mirror of
https://git.alemi.dev/gitshell.git
synced 2024-11-24 16:34:50 +01:00
feat: reimplement ls in python
so we can get exactly the functionality we need
This commit is contained in:
parent
70e3d77b19
commit
5e32a80357
1 changed files with 27 additions and 9 deletions
36
ls
36
ls
|
@ -1,12 +1,30 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env python
|
||||||
|
|
||||||
tree /srv/git -I "hooks|objects|info|branches|refs|HEAD|description|config|cgitrc|FETCH_HEAD|packed-refs"
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
# ls /srv/git -I 'git-shell-commands'
|
GIT_ROOT = Path(os.environ.get("GIT_ROOT_DIR") or "/srv/git/")
|
||||||
|
|
||||||
# one above misses repos like '.dotfiles', let's do it by hand
|
def pre(depth: int, last: bool = False) -> str:
|
||||||
# for f in $(ls /srv/git -a); do
|
return (': ' * (depth)) + ("'-" if last else '|-')
|
||||||
# if [[ $f == *.git ]]; then
|
|
||||||
# echo $f
|
def print_dir(dir: str, depth: int):
|
||||||
# fi
|
print(f"{pre(depth)}+ {dir}/")
|
||||||
# done
|
|
||||||
|
def print_repo(repo: str, depth: int, last: bool = False):
|
||||||
|
print(f"{pre(depth, last=last)} {repo.replace('.git','')}")
|
||||||
|
|
||||||
|
def run_on_all_repos(root: Path, depth: int = 0):
|
||||||
|
contents = 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])
|
||||||
|
elif os.path.isdir(root / element):
|
||||||
|
print_dir(element, depth)
|
||||||
|
run_on_all_repos(root / element, depth=depth+1)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run_on_all_repos(GIT_ROOT)
|
||||||
|
|
Loading…
Reference in a new issue