diff options
| -rw-r--r-- | pkgs/claude-inbox.nix | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/pkgs/claude-inbox.nix b/pkgs/claude-inbox.nix index 64633cf..721d771 100644 --- a/pkgs/claude-inbox.nix +++ b/pkgs/claude-inbox.nix @@ -361,18 +361,54 @@ let -d) COMPREPLY=($(compgen -d -- "$cur")); return ;; --vm) COMPREPLY=($(compgen -A hostname -- "$cur")); return ;; esac - local repos="$(cd "$src" 2>/dev/null && for d in */; do git -C "$d" remote get-url claude >/dev/null 2>&1 && echo "''${d%/}"; done)" + # The repositories with a remote claude, and claude's branches, read + # from .git, as running git twice per repository on every TAB adds + # up; but by git, where .git isn't a plain directory (a worktree's), + # or the refs aren't files (reftable). + local repos=" " d l + for d in "$src"/*/; do + d=''${d%/} + if [ -d "$d/.git" ]; then + while IFS= read -r l; do + case $l in *'[remote "claude"]'*) repos="$repos''${d##*/} "; break ;; esac + done < "$d/.git/config" + elif [ -e "$d/.git" ] && git -C "$d" remote get-url claude >/dev/null 2>&1; then + repos="$repos''${d##*/} " + fi + done 2>/dev/null _claude_inbox_branches() { - local n + local n g x r for n; do - git -C "$src/$n" for-each-ref --format='%(refname:lstrip=3)' refs/remotes/claude 2>/dev/null + g=$src/$n/.git + if [ -d "$g" ] && ! [ -e "$g/reftable" ]; then + if [ -f "$g/packed-refs" ]; then + while read -r x r; do + case $r in refs/remotes/claude/*) printf '%s\n' "''${r#refs/remotes/claude/}" ;; esac + done < "$g/packed-refs" + fi + _claude_inbox_loose "$g/refs/remotes/claude" "" + else + git -C "$src/$n" for-each-ref --format='%(refname:lstrip=3)' refs/remotes/claude 2>/dev/null + fi done | grep -vx -e master -e HEAD | sort -u } + # DIR PREFIX: the loose refs below DIR, by name + _claude_inbox_loose() { + local f + for f in "$1"/*; do + case $f in *.lock) continue ;; esac + if [ -d "$f" ]; then + _claude_inbox_loose "$f" "$2''${f##*/}/" + elif [ -f "$f" ]; then + printf '%s\n' "$2''${f##*/}" + fi + done + } # the words so far: a repository's name is the REPO, anything else # the BRANCH (good enough to complete the rest) local repo= branch= for w in "''${words[@]}"; do - if [ -z "$repo" ] && printf '%s\n' "$repos" | grep -qxF -- "$w"; then + if [ -z "$repo" ] && case $repos in *" $w "*) true ;; *) false ;; esac; then repo=$w else branch=$w |
