From 186dc3ca525d640fc380c6d9839dcae301d0f3d6 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 8 Feb 2024 19:47:16 +0100 Subject: [PATCH] feat: removed public, ls marks hidden repos --- ls | 18 ++++++++++++++---- public | 14 -------------- 2 files changed, 14 insertions(+), 18 deletions(-) delete mode 100755 public diff --git a/ls b/ls index ef382c6..a81b0b1 100755 --- a/ls +++ b/ls @@ -1,6 +1,7 @@ #!/usr/bin/env python import os +import subprocess from pathlib import Path GIT_ROOT = Path(os.environ.get("GIT_ROOT_DIR") or "/srv/git/") @@ -8,20 +9,29 @@ GIT_ROOT = Path(os.environ.get("GIT_ROOT_DIR") or "/srv/git/") def pre(depth: int, last: bool = False) -> str: return (': ' * (depth)) + ("'-" if last else '|-') +def is_public(repo: Path) -> bool: + cmd = ["git", "config", "-f", f"{repo}/config", "cgit.ignore"] + proc = subprocess.run(cmd, stdout=subprocess.PIPE) + if proc.stdout.decode().strip() == "1": + return False + return True + def print_dir(dir: str, depth: int): print(f"{pre(depth)}+ {dir}/") -def print_repo(repo: str, depth: int, last: bool = False): - print(f"{pre(depth, last=last)} {repo.replace('.git','')}") +def print_repo(repo: str, depth: int, last: bool = False, public: bool = False): + print(f"{pre(depth, last=last)} {repo.replace('.git','')} {'' if public else '[h]'}") def run_on_all_repos(root: Path, depth: int = 0): - contents = os.listdir(root) + contents = sorted(os.listdir(root)) for element in contents: full_path = root / element if element.startswith("."): pass # ignore hidden files elif element.endswith(".git"): - print_repo(element, depth, last=element==contents[-1]) + public = is_public(full_path) + last = element == contents[-1] + print_repo(element, depth, last=last, public=public) elif os.path.isdir(root / element): print_dir(element, depth) run_on_all_repos(root / element, depth=depth+1) diff --git a/public b/public deleted file mode 100755 index 3476e10..0000000 --- a/public +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -# ls /srv/git -I 'git-shell-commands' - -# one above misses repos like '.dotfiles', let's do it by hand -for f in $(ls /srv/git/.public -a); do - if [[ $f == '.' ]]; then - continue - elif [[ $f == '..' ]]; then - continue - fi - - echo "$f" -done