30 lines
815 B
Bash
Executable File
30 lines
815 B
Bash
Executable File
#!/usr/bin/env zsh
|
|
|
|
local idx="${@[(ei)--help]}"
|
|
local flags_end="${@[(ei)--]}"
|
|
if (( idx < flags_end )); then
|
|
printf "Usage: $0 [--all] [REMOTE]..."
|
|
return 0
|
|
fi
|
|
|
|
idx="${@[(ei)--all]}"
|
|
if (( idx < flags_end )); then
|
|
# Replace --all flag with empty string. Will be replaced with
|
|
# refs/remotes/ later so that all remotes are listed
|
|
set -- "${@[1,$((idx-1))]}" "" "${@[$((idx+1)),-1]}"
|
|
fi
|
|
|
|
git for-each-ref --format='%(upstream),%(refname)' refs/heads "${@/#/refs/remotes/}" \
|
|
| sort -d \
|
|
| sed -Ez '
|
|
s:(^|\n|,)refs/(heads|remotes/):\1:g
|
|
s:(^|\n),([^/][^\n]*):\1\2,:g
|
|
s:,/:,:g
|
|
s:(^|\n)([^,]+),\n\2:\1\2:g
|
|
s:(^|\n)([^/,]*)([^\n]*\n\2(,|/))*:\n,\n&:g
|
|
s:\n,\n+$:\n:' \
|
|
| { echo remote,local; cat; } \
|
|
| sed -E 's:(.*),(.*):\2,\1:g; s:^,: ,:; s:,$:, :' \
|
|
| column -ts, \
|
|
| sed '2d; 1{p;s/./―/g}'
|