@@ -82,7 +82,33 @@ __FUNC__() {
8282 if [ "$#" -gt 0 ] && [ "$1" = "cd" ]; then
8383 shift
8484 local dir
85- dir="$(command git gtr go "$@")" && cd "$dir" && {
85+ if [ "$#" -eq 0 ] && command -v fzf >/dev/null 2>&1; then
86+ local _gtr_selection
87+ _gtr_selection="$(command git gtr list --porcelain | fzf \
88+ --delimiter=$'\t' \
89+ --with-nth=2 \
90+ --ansi \
91+ --layout=reverse \
92+ --border \
93+ --prompt='Worktree> ' \
94+ --header='enter:cd │ ctrl-e:editor │ ctrl-a:ai │ ctrl-d:delete │ ctrl-y:copy │ ctrl-r:refresh' \
95+ --preview='git -C {1} log --oneline --graph --color=always -15 2>/dev/null; echo "---"; git -C {1} status --short 2>/dev/null' \
96+ --preview-window=right:50% \
97+ --bind='ctrl-e:execute(git gtr editor {2})' \
98+ --bind='ctrl-a:execute(git gtr ai {2})' \
99+ --bind='ctrl-d:execute(git gtr rm {2})+reload(git gtr list --porcelain)' \
100+ --bind='ctrl-y:execute(git gtr copy {2})' \
101+ --bind='ctrl-r:reload(git gtr list --porcelain)')" || return 0
102+ [ -z "$_gtr_selection" ] && return 0
103+ dir="$(printf '%s' "$_gtr_selection" | cut -f1)"
104+ elif [ "$#" -eq 0 ]; then
105+ echo "Usage: __FUNC__ cd <branch>" >&2
106+ echo "Tip: Install fzf for an interactive picker (https://github.com/junegunn/fzf)" >&2
107+ return 1
108+ else
109+ dir="$(command git gtr go "$@")" || return $?
110+ fi
111+ cd "$dir" && {
86112 local _gtr_hooks _gtr_hook _gtr_seen _gtr_config_file
87113 _gtr_hooks=""
88114 _gtr_seen=""
@@ -152,10 +178,37 @@ _init_zsh() {
152178# eval "$(git gtr init zsh)"
153179
154180__FUNC__() {
181+ emulate -L zsh
155182 if [ "$#" -gt 0 ] && [ "$1" = "cd" ]; then
156183 shift
157184 local dir
158- dir="$(command git gtr go "$@")" && cd "$dir" && {
185+ if [ "$#" -eq 0 ] && command -v fzf >/dev/null 2>&1; then
186+ local _gtr_selection
187+ _gtr_selection="$(command git gtr list --porcelain | fzf \
188+ --delimiter=$'\t' \
189+ --with-nth=2 \
190+ --ansi \
191+ --layout=reverse \
192+ --border \
193+ --prompt='Worktree> ' \
194+ --header='enter:cd │ ctrl-e:editor │ ctrl-a:ai │ ctrl-d:delete │ ctrl-y:copy │ ctrl-r:refresh' \
195+ --preview='git -C {1} log --oneline --graph --color=always -15 2>/dev/null; echo "---"; git -C {1} status --short 2>/dev/null' \
196+ --preview-window=right:50% \
197+ --bind='ctrl-e:execute(git gtr editor {2})' \
198+ --bind='ctrl-a:execute(git gtr ai {2})' \
199+ --bind='ctrl-d:execute(git gtr rm {2})+reload(git gtr list --porcelain)' \
200+ --bind='ctrl-y:execute(git gtr copy {2})' \
201+ --bind='ctrl-r:reload(git gtr list --porcelain)')" || return 0
202+ [ -z "$_gtr_selection" ] && return 0
203+ dir="$(printf '%s' "$_gtr_selection" | cut -f1)"
204+ elif [ "$#" -eq 0 ]; then
205+ echo "Usage: __FUNC__ cd <branch>" >&2
206+ echo "Tip: Install fzf for an interactive picker (https://github.com/junegunn/fzf)" >&2
207+ return 1
208+ else
209+ dir="$(command git gtr go "$@")" || return $?
210+ fi
211+ cd "$dir" && {
159212 local _gtr_hooks _gtr_hook _gtr_seen _gtr_config_file
160213 _gtr_hooks=""
161214 _gtr_seen=""
@@ -232,8 +285,35 @@ _init_fish() {
232285
233286function __FUNC__
234287 if test (count $argv) -gt 0; and test "$argv[1]" = "cd"
235- set -l dir (command git gtr go $argv[2..])
236- and cd $dir
288+ set -l dir
289+ if test (count $argv) -eq 1; and type -q fzf
290+ set -l _gtr_selection (command git gtr list --porcelain | fzf \
291+ --delimiter=\t \
292+ --with-nth=2 \
293+ --ansi \
294+ --layout=reverse \
295+ --border \
296+ --prompt='Worktree> ' \
297+ --header='enter:cd │ ctrl-e:editor │ ctrl-a:ai │ ctrl-d:delete │ ctrl-y:copy │ ctrl-r:refresh' \
298+ --preview='git -C {1} log --oneline --graph --color=always -15 2>/dev/null; echo "---"; git -C {1} status --short 2>/dev/null' \
299+ --preview-window=right:50% \
300+ --bind='ctrl-e:execute(git gtr editor {2})' \
301+ --bind='ctrl-a:execute(git gtr ai {2})' \
302+ --bind='ctrl-d:execute(git gtr rm {2})+reload(git gtr list --porcelain)' \
303+ --bind='ctrl-y:execute(git gtr copy {2})' \
304+ --bind='ctrl-r:reload(git gtr list --porcelain)')
305+ or return 0
306+ test -z "$_gtr_selection"; and return 0
307+ set dir (string split \t -- "$_gtr_selection")[1]
308+ else if test (count $argv) -eq 1
309+ echo "Usage: __FUNC__ cd <branch>" >&2
310+ echo "Tip: Install fzf for an interactive picker (https://github.com/junegunn/fzf)" >&2
311+ return 1
312+ else
313+ set dir (command git gtr go $argv[2..])
314+ or return $status
315+ end
316+ cd $dir
237317 and begin
238318 set -l _gtr_hooks
239319 set -l _gtr_seen
0 commit comments