summaryrefslogtreecommitdiffstats
path: root/pkgs/claude-inbox.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/claude-inbox.nix')
-rw-r--r--pkgs/claude-inbox.nix57
1 files changed, 50 insertions, 7 deletions
diff --git a/pkgs/claude-inbox.nix b/pkgs/claude-inbox.nix
index 4361383..05d864a 100644
--- a/pkgs/claude-inbox.nix
+++ b/pkgs/claude-inbox.nix
@@ -27,12 +27,14 @@ let
their branches with something master doesn't have (by content),
those it has all of (to delete), and whether master needs
pushing. --by-remote: grouped by OWNER.
- --show [REPO|BRANCH] [--diff[=WHAT]]
+ --show [REPO|BRANCH] [--diff[=WHAT]] [--git=ARGS]...
The default with BRANCH. Fetch REPO (or else all) first, show
master..BRANCH, with patches, and mark BRANCH seen. Without
BRANCH: REPO's branches, as a graph.
--diff: the diff to BRANCH from WHAT, a branch or commit
(default: HEAD).
+ --git: more arguments for git log (or git diff), split at
+ spaces, e.g. --git=-p --git='-n 1', or --git='-p -n 1'.
--take BRANCH [-f|--force|--pick]
Fast-forward master to BRANCH, as last fetched (i.e. as shown),
and push it to claude. master: checked out, or nowhere (not in
@@ -113,7 +115,7 @@ let
sed -E \
-e "s/^([A-Z][A-Za-z ]*:)$/$C_HEAD\1$C_OFF/" \
-e ":a; s/(^|$x)(--(list|show|take|push)|COMMAND)($x|$)/\1$C_CMD\2$C_OFF\4/; ta" \
- -e ":b; s/(^|$x)(-d|--vm|--no-fetch|--by-remote|-f|--force|--pick|--diff|-h|--help|OPTION)($x|$)/\1$C_OPT\2$C_OFF\3/; tb" \
+ -e ":b; s/(^|$x)(-d|--vm|--no-fetch|--by-remote|-f|--force|--pick|--diff|--git|-h|--help|OPTION)($x|$)/\1$C_OPT\2$C_OFF\3/; tb" \
-e ":c; s/(^|$x)(REPO)($x|$)/\1$C_REPO\2$C_OFF\3/; tc" \
-e ":d; s/(^|$x)(BRANCH)($x|$)/\1$C_BRANCH\2$C_OFF\3/; td"
}
@@ -142,6 +144,7 @@ let
pick=
diff=
what=
+ gitargs=()
words=()
# options, commands and words, in any order: the options and commands
# are one set, without overlaps, and the words are REPO and BRANCH
@@ -161,6 +164,8 @@ let
--pick) pick=1 ;;
--diff) diff=1 what= ;;
--diff=*) diff=1 what=''${1#--diff=} ;;
+ --git=*) read -ra a <<< "''${1#--git=}"; gitargs+=("''${a[@]}") ;;
+ --git) die "--git=ARGS: more arguments for git" ;;
-h | --help) colors 1; usage | paint; exit ;;
-*) die "$1: no such option (claude-inbox -h)" ;;
*) words+=("$1")
@@ -277,6 +282,7 @@ let
test -z "$force" || case $cmd in take | push) ;; *) die "-f is for --take and --push" ;; esac
test -z "$pick" || test "$cmd" = take || die "--pick is for --take"
test -z "$diff" || test "$cmd" = show || die "--diff is for --show"
+ test ''${#gitargs[@]} = 0 || test "$cmd" = show || die "--git is for --show"
test "$by" = repo || test "$cmd" = list || die "--by-remote is for --list"
case $cmd in
list) test -z "$b" || die "--list takes no BRANCH" ;;
@@ -399,16 +405,16 @@ let
;;
show)
if test -z "$b"; then
- git -C "$r" log --oneline --all --graph
+ git -C "$r" log --oneline --all --graph "''${gitargs[@]}"
elif test -n "$diff"; then
# from WHAT, any branch or commit, or by default, HEAD
what=''${what:-HEAD}
git -C "$r" rev-parse -q --verify "$what^{commit}" >/dev/null ||
die "$name: no branch or commit $what"
- git -C "$r" diff "$what..claude/$b"
+ git -C "$r" diff "''${gitargs[@]}" "$what..claude/$b"
seen "$b"
else
- git -C "$r" log -p --stat "master..claude/$b"
+ git -C "$r" log -p --stat "''${gitargs[@]}" "master..claude/$b"
seen "$b"
fi
;;
@@ -493,13 +499,14 @@ let
w=''${COMP_WORDS[i]}
case $w in
-f | --force | --pick) used="$used-f --force --pick " ;;
+ --git) ;; # again and again
-*) used="$used$w " ;;
esac
case $w in
-d) src=''${COMP_WORDS[i+1]}; i=$((i + 1)) ;;
--vm) i=$((i + 1)) ;;
--list | --show | --take | --push) cmd=''${w#--} ;;
- --diff) [ "''${COMP_WORDS[i+1]}" != = ] || i=$((i + 2)) ;;
+ --diff | --git) [ "''${COMP_WORDS[i+1]}" != = ] || i=$((i + 2)) ;;
-*) ;;
*) words+=("$w") ;;
esac
@@ -568,6 +575,35 @@ let
COMPREPLY=($(compgen -W "$(git -C "$src/''${repo:-.}" for-each-ref --format='%(refname:short)' refs/heads 2>/dev/null)" -- "$cur"))
return
fi
+ # --git=ARGS: git log's options, or with --diff, git diff's
+ if { [ "$cur" = = ] && [ "$prev" = --git ]; } ||
+ { [ "$prev" = = ] && [ "''${COMP_WORDS[COMP_CWORD-2]}" = --git ]; }; then
+ [ "$cur" = = ] && cur=
+ local gitopts
+ case " ''${COMP_WORDS[*]} " in
+ *" --diff "*)
+ gitopts="--stat --shortstat --numstat --name-only --name-status
+ --summary -p -U --unified= --word-diff --color-words -w
+ --ignore-all-space -b --ignore-space-change --ignore-blank-lines
+ -M --find-renames --diff-filter= -R --minimal --patience
+ --histogram" ;;
+ *)
+ gitopts="-p --patch -s --no-patch --stat --shortstat --name-only
+ --name-status --oneline --graph --decorate --format= --pretty=
+ --abbrev-commit --date= -n --max-count= --skip= --since=
+ --until= --author= --grep= --no-merges --merges
+ --first-parent --reverse -S -G --follow -U --unified=
+ --word-diff --color-words -w --ignore-all-space" ;;
+ esac
+ # inside quotes (--git='-p -n 1'): the last word, after the others
+ local w=$cur pre=
+ case $w in \'* | \"*) w=''${w:1} ;; esac
+ case $w in *" "*) pre="''${w% *} " w=''${w##* } ;; esac
+ COMPREPLY=()
+ for c in $(compgen -W "$gitopts" -- "$w"); do COMPREPLY+=("$pre$c"); done
+ _claude_inbox_nospace
+ return
+ fi
# what's left, in groups: the commands (until there's one), the
# options (a command's, once it's there), REPO, BRANCH; but nothing
# that's there already (nor what that excludes)
@@ -575,7 +611,7 @@ let
case $cmd in
"") cmds="--list --show --take --push" ;;
list) opts="$opts --by-remote" ;;
- show) opts="$opts --diff" ;;
+ show) opts="$opts --diff --git=" ;;
take) opts="$opts -f --force --pick" ;;
push) opts="$opts -f --force" ;;
esac
@@ -600,6 +636,7 @@ let
done
k=$((k + 1))
done
+ _claude_inbox_nospace
# Listing only (a second TAB), in color, by kind: readline would
# print escapes as ^[, so the list is printed here, and readline gets
# one blank candidate, to list instead, and redraw the prompt after.
@@ -658,6 +695,12 @@ let
done
}
# in that order (bash 4.4 and later)
+ # an option that takes a value (--git=), the only one: no space after
+ _claude_inbox_nospace() {
+ if [ ''${#COMPREPLY[@]} = 1 ] && [ "''${COMPREPLY[0]%=}" != "''${COMPREPLY[0]}" ]; then
+ compopt -o nospace
+ fi
+ }
complete -o nosort -F _claude_inbox claude-inbox 2>/dev/null ||
complete -F _claude_inbox claude-inbox
'';