From 5767210dcea21e601fdc45320616a9735e8a3390 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Mon, 25 Aug 2025 13:50:13 +0200 Subject: [PATCH] git:track: List remote refs only on request List only the local heads by default and require the remote refs to be passed as arguments. For example: git track origin To make this easier, add support of an `--all` flag to list all remote refs. --- .config/zsh/autoload/git/git-track | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.config/zsh/autoload/git/git-track b/.config/zsh/autoload/git/git-track index 79080c9..10e9dea 100755 --- a/.config/zsh/autoload/git/git-track +++ b/.config/zsh/autoload/git/git-track @@ -1,6 +1,20 @@ #!/usr/bin/env zsh -git for-each-ref --format='%(upstream),%(refname)' refs/heads refs/remotes \ +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