Files
dotfiles/.config/zsh/autoload/git/git-track
Julian Prein 5794af1c52 zsh:autoload:git-track: Make more portable
Some distributions ship older versions of `column` that do not have the
flags `-dNLO`. This is a workaround around this limitation that creates
the same output using other tools.
2022-02-17 15:40:51 +01:00

17 lines
433 B
Bash
Executable File

#!/usr/bin/env zsh
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}'