@@ -81,6 +81,23 @@ _init_bash() {
8181__FUNC__() {
8282 if [ "$#" -gt 0 ] && [ "$1" = "cd" ]; then
8383 shift
84+ if [ "$#" -eq 0 ]; then
85+ if command -v fzf >/dev/null 2>&1; then
86+ local _gtr_sel
87+ _gtr_sel="$(command git gtr list --porcelain | fzf \
88+ --delimiter=$'\t' \
89+ --with-nth=2 \
90+ --header='Select worktree (Ctrl-C to cancel)' \
91+ --preview='git -C {1} log --oneline --graph -15 2>/dev/null; echo "---"; git -C {1} status --short 2>/dev/null' \
92+ --preview-window=right:50%)" || return 0
93+ set -- "$(printf '%s' "$_gtr_sel" | cut -f2)"
94+ else
95+ echo "Tip: Install fzf for an interactive worktree picker (https://github.com/junegunn/fzf)" >&2
96+ echo "" >&2
97+ command git gtr list
98+ return 0
99+ fi
100+ fi
84101 local dir
85102 dir="$(command git gtr go "$@")" && cd "$dir" && {
86103 local _gtr_hooks _gtr_hook _gtr_seen _gtr_config_file
@@ -154,6 +171,23 @@ _init_zsh() {
154171__FUNC__() {
155172 if [ "$#" -gt 0 ] && [ "$1" = "cd" ]; then
156173 shift
174+ if [ "$#" -eq 0 ]; then
175+ if command -v fzf >/dev/null 2>&1; then
176+ local _gtr_sel
177+ _gtr_sel="$(command git gtr list --porcelain | fzf \
178+ --delimiter=$'\t' \
179+ --with-nth=2 \
180+ --header='Select worktree (Ctrl-C to cancel)' \
181+ --preview='git -C {1} log --oneline --graph -15 2>/dev/null; echo "---"; git -C {1} status --short 2>/dev/null' \
182+ --preview-window=right:50%)" || return 0
183+ set -- "$(printf '%s' "$_gtr_sel" | cut -f2)"
184+ else
185+ echo "Tip: Install fzf for an interactive worktree picker (https://github.com/junegunn/fzf)" >&2
186+ echo "" >&2
187+ command git gtr list
188+ return 0
189+ fi
190+ fi
157191 local dir
158192 dir="$(command git gtr go "$@")" && cd "$dir" && {
159193 local _gtr_hooks _gtr_hook _gtr_seen _gtr_config_file
@@ -232,7 +266,25 @@ _init_fish() {
232266
233267function __FUNC__
234268 if test (count $argv) -gt 0; and test "$argv[1]" = "cd"
235- set -l dir (command git gtr go $argv[2..])
269+ set -l _gtr_cd_args $argv[2..]
270+ if test (count $_gtr_cd_args) -eq 0
271+ if command -q fzf
272+ set -l _gtr_sel (command git gtr list --porcelain | fzf \
273+ --delimiter=\t \
274+ --with-nth=2 \
275+ --header='Select worktree (Ctrl-C to cancel)' \
276+ --preview='git -C {1} log --oneline --graph -15 2>/dev/null; echo "---"; git -C {1} status --short 2>/dev/null' \
277+ --preview-window=right:50%)
278+ or return 0
279+ set _gtr_cd_args (printf '%s' "$_gtr_sel" | cut -f2)
280+ else
281+ echo "Tip: Install fzf for an interactive worktree picker (https://github.com/junegunn/fzf)" >&2
282+ echo "" >&2
283+ command git gtr list
284+ return 0
285+ end
286+ end
287+ set -l dir (command git gtr go $_gtr_cd_args)
236288 and cd $dir
237289 and begin
238290 set -l _gtr_hooks
0 commit comments