@@ -81,25 +81,30 @@ _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
10184 local dir
102- 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+ else
105+ dir="$(command git gtr go "$@")" || return $?
106+ fi
107+ cd "$dir" && {
103108 local _gtr_hooks _gtr_hook _gtr_seen _gtr_config_file
104109 _gtr_hooks=""
105110 _gtr_seen=""
@@ -171,25 +176,30 @@ _init_zsh() {
171176__FUNC__() {
172177 if [ "$#" -gt 0 ] && [ "$1" = "cd" ]; then
173178 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
191179 local dir
192- dir="$(command git gtr go "$@")" && cd "$dir" && {
180+ if [ "$#" -eq 0 ] && command -v fzf >/dev/null 2>&1; then
181+ local _gtr_selection
182+ _gtr_selection="$(command git gtr list --porcelain | fzf \
183+ --delimiter=$'\t' \
184+ --with-nth=2 \
185+ --ansi \
186+ --layout=reverse \
187+ --border \
188+ --prompt='Worktree> ' \
189+ --header='enter:cd │ ctrl-e:editor │ ctrl-a:ai │ ctrl-d:delete │ ctrl-y:copy │ ctrl-r:refresh' \
190+ --preview='git -C {1} log --oneline --graph --color=always -15 2>/dev/null; echo "---"; git -C {1} status --short 2>/dev/null' \
191+ --preview-window=right:50% \
192+ --bind='ctrl-e:execute(git gtr editor {2})' \
193+ --bind='ctrl-a:execute(git gtr ai {2})' \
194+ --bind='ctrl-d:execute(git gtr rm {2})+reload(git gtr list --porcelain)' \
195+ --bind='ctrl-y:execute(git gtr copy {2})' \
196+ --bind='ctrl-r:reload(git gtr list --porcelain)')" || return 0
197+ [ -z "$_gtr_selection" ] && return 0
198+ dir="$(printf '%s' "$_gtr_selection" | cut -f1)"
199+ else
200+ dir="$(command git gtr go "$@")" || return $?
201+ fi
202+ cd "$dir" && {
193203 local _gtr_hooks _gtr_hook _gtr_seen _gtr_config_file
194204 _gtr_hooks=""
195205 _gtr_seen=""
@@ -266,26 +276,31 @@ _init_fish() {
266276
267277function __FUNC__
268278 if test (count $argv) -gt 0; and test "$argv[1]" = "cd"
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
279+ set -l dir
280+ if test (count $argv) -eq 1; and type -q fzf
281+ set -l _gtr_selection (command git gtr list --porcelain | fzf \
282+ --delimiter=\t \
283+ --with-nth=2 \
284+ --ansi \
285+ --layout=reverse \
286+ --border \
287+ --prompt='Worktree> ' \
288+ --header='enter:cd │ ctrl-e:editor │ ctrl-a:ai │ ctrl-d:delete │ ctrl-y:copy │ ctrl-r:refresh' \
289+ --preview='git -C {1} log --oneline --graph --color=always -15 2>/dev/null; echo "---"; git -C {1} status --short 2>/dev/null' \
290+ --preview-window=right:50% \
291+ --bind='ctrl-e:execute(git gtr editor {2})' \
292+ --bind='ctrl-a:execute(git gtr ai {2})' \
293+ --bind='ctrl-d:execute(git gtr rm {2})+reload(git gtr list --porcelain)' \
294+ --bind='ctrl-y:execute(git gtr copy {2})' \
295+ --bind='ctrl-r:reload(git gtr list --porcelain)')
296+ or return 0
297+ test -z "$_gtr_selection"; and return 0
298+ set dir (string split \t -- "$_gtr_selection")[1]
299+ else
300+ set dir (command git gtr go $argv[2..])
301+ or return $status
286302 end
287- set -l dir (command git gtr go $_gtr_cd_args)
288- and cd $dir
303+ cd $dir
289304 and begin
290305 set -l _gtr_hooks
291306 set -l _gtr_seen
0 commit comments