git: add git-st script

This commit is contained in:
Daniel Lundin 2023-12-27 00:43:23 +01:00
parent c2023b81ac
commit 3c12e2f746
2 changed files with 37 additions and 1 deletions

View file

@ -39,7 +39,12 @@ sw = branchless switch
s = branchless switch -i
new = !git fetch -u origin main:main && git branchless switch -d origin/main
gerrit-clone = "!f() { git clone ssh://gerrit-ssh.shelman.io:2222/$1 && (cd $1 && mkdir -p `git rev-parse --git-dir`/hooks/ && scp -O -P 2222 gerrit-ssh.shelman.io:hooks/commit-msg `git rev-parse --git-dir`/hooks/commit-msg && chmod +x `git rev-parse --git-dir`/hooks/commit-msg && git branchless init); }; f"
gerrit-clone = "!f() { \
git clone ssh://gerrit-ssh.shelman.io:2222/$1 \
&& (cd $1 && mkdir -p `git rev-parse --git-dir`/hooks/ \
&& scp -O -P 2222 gerrit-ssh.shelman.io:hooks/commit-msg `git rev-parse --git-dir`/hooks/commit-msg \
&& chmod +x `git rev-parse --git-dir`/hooks/commit-msg \
&& git branchless init); }; f"
gerrit-switch = !(ssh `git remote get-url origin | cut -d / -f -3` gerrit query --format=JSON --current-patch-set status:open project:`git remote get-url origin | cut -d / -f 4-` \
| jq -sr 'map(select(.number) | \"\\(.number) @ \\(.currentPatchSet.ref) - \\(.subject)\")|join(\"\\n\")' \

31
bin/git-st Executable file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env bash
git branchless smartlog || true
printf '\n'
awk -vOFS='' '
NR==FNR {
all[i++] = $0;
difffiles[$1] = $0;
next;
}
! ($2 in difffiles) {
print; next;
}
{
gsub($2, difffiles[$2]);
print;
}
END {
if (NR != FNR) {
# Had diff output
exit;
}
# Had no diff output, just print lines from git status -sb
for (i in all) {
print all[i];
}
}
' \
<(git diff --color --stat=$(($(tput cols) - 3)) HEAD | sed '$d; s/^ //')\
<(git -c color.status=always status -sb)