@@ -104,24 +104,41 @@ __FUNC__() {
104104 echo "No worktrees to pick from. Create one with: git gtr new <branch>" >&2
105105 return 0
106106 fi
107- local _gtr_selection
107+ local _gtr_selection _gtr_key _gtr_line _gtr_branch
108108 _gtr_selection="$(printf '%s\n' "$_gtr_porcelain" | fzf \
109109 --delimiter=$'\t' \
110110 --with-nth=2 \
111111 --ansi \
112112 --layout=reverse \
113113 --border \
114114 --prompt='Worktree> ' \
115- --header='enter:cd │ ctrl-e:editor │ ctrl-a:ai │ ctrl-d:delete │ ctrl-y:copy │ ctrl-r:refresh' \
115+ --header='enter:cd │ ctrl-n:new │ ctrl-e:editor │ ctrl-a:ai │ ctrl-d:delete │ ctrl-y:copy │ ctrl-r:refresh' \
116+ --expect=ctrl-n,ctrl-a,ctrl-e \
116117 --preview='git -C {1} log --oneline --graph --color=always -15 2>/dev/null; echo "---"; git -C {1} status --short 2>/dev/null' \
117118 --preview-window=right:50% \
118- --bind='ctrl-e:execute(git gtr editor {2})' \
119- --bind='ctrl-a:execute(git gtr ai {2})' \
120- --bind='ctrl-d:execute(git gtr rm {2})+reload(git gtr list --porcelain)' \
121- --bind='ctrl-y:execute(git gtr copy {2})' \
119+ --bind='ctrl-d:execute(git gtr rm {2} > /dev/tty 2>&1 < /dev/tty)+reload(git gtr list --porcelain)' \
120+ --bind='ctrl-y:execute(git gtr copy {2} > /dev/tty 2>&1 < /dev/tty)' \
122121 --bind='ctrl-r:reload(git gtr list --porcelain)')" || return 0
123122 [ -z "$_gtr_selection" ] && return 0
124- dir="$(printf '%s' "$_gtr_selection" | cut -f1)"
123+ _gtr_key="$(head -1 <<< "$_gtr_selection")"
124+ _gtr_line="$(sed -n '2p' <<< "$_gtr_selection")"
125+ if [ "$_gtr_key" = "ctrl-n" ]; then
126+ printf "Branch name: " >&2
127+ read -r _gtr_branch
128+ [ -z "$_gtr_branch" ] && return 0
129+ command git gtr new "$_gtr_branch"
130+ return $?
131+ fi
132+ [ -z "$_gtr_line" ] && return 0
133+ # ctrl-a/ctrl-e: run after fzf exits (needs full terminal for TUI apps)
134+ if [ "$_gtr_key" = "ctrl-a" ]; then
135+ command git gtr ai "$(printf '%s' "$_gtr_line" | cut -f2)"
136+ return $?
137+ elif [ "$_gtr_key" = "ctrl-e" ]; then
138+ command git gtr editor "$(printf '%s' "$_gtr_line" | cut -f2)"
139+ return $?
140+ fi
141+ dir="$(printf '%s' "$_gtr_line" | cut -f1)"
125142 elif [ "$#" -eq 0 ]; then
126143 echo "Usage: __FUNC__ cd <branch>" >&2
127144 echo "Tip: Install fzf for an interactive picker (https://github.com/junegunn/fzf)" >&2
@@ -209,24 +226,41 @@ __FUNC__() {
209226 echo "No worktrees to pick from. Create one with: git gtr new <branch>" >&2
210227 return 0
211228 fi
212- local _gtr_selection
229+ local _gtr_selection _gtr_key _gtr_line _gtr_branch
213230 _gtr_selection="$(printf '%s\n' "$_gtr_porcelain" | fzf \
214231 --delimiter=$'\t' \
215232 --with-nth=2 \
216233 --ansi \
217234 --layout=reverse \
218235 --border \
219236 --prompt='Worktree> ' \
220- --header='enter:cd │ ctrl-e:editor │ ctrl-a:ai │ ctrl-d:delete │ ctrl-y:copy │ ctrl-r:refresh' \
237+ --header='enter:cd │ ctrl-n:new │ ctrl-e:editor │ ctrl-a:ai │ ctrl-d:delete │ ctrl-y:copy │ ctrl-r:refresh' \
238+ --expect=ctrl-n,ctrl-a,ctrl-e \
221239 --preview='git -C {1} log --oneline --graph --color=always -15 2>/dev/null; echo "---"; git -C {1} status --short 2>/dev/null' \
222240 --preview-window=right:50% \
223- --bind='ctrl-e:execute(git gtr editor {2})' \
224- --bind='ctrl-a:execute(git gtr ai {2})' \
225- --bind='ctrl-d:execute(git gtr rm {2})+reload(git gtr list --porcelain)' \
226- --bind='ctrl-y:execute(git gtr copy {2})' \
241+ --bind='ctrl-d:execute(git gtr rm {2} > /dev/tty 2>&1 < /dev/tty)+reload(git gtr list --porcelain)' \
242+ --bind='ctrl-y:execute(git gtr copy {2} > /dev/tty 2>&1 < /dev/tty)' \
227243 --bind='ctrl-r:reload(git gtr list --porcelain)')" || return 0
228244 [ -z "$_gtr_selection" ] && return 0
229- dir="$(printf '%s' "$_gtr_selection" | cut -f1)"
245+ _gtr_key="$(head -1 <<< "$_gtr_selection")"
246+ _gtr_line="$(sed -n '2p' <<< "$_gtr_selection")"
247+ if [ "$_gtr_key" = "ctrl-n" ]; then
248+ printf "Branch name: " >&2
249+ read -r _gtr_branch
250+ [ -z "$_gtr_branch" ] && return 0
251+ command git gtr new "$_gtr_branch"
252+ return $?
253+ fi
254+ [ -z "$_gtr_line" ] && return 0
255+ # ctrl-a/ctrl-e: run after fzf exits (needs full terminal for TUI apps)
256+ if [ "$_gtr_key" = "ctrl-a" ]; then
257+ command git gtr ai "$(printf '%s' "$_gtr_line" | cut -f2)"
258+ return $?
259+ elif [ "$_gtr_key" = "ctrl-e" ]; then
260+ command git gtr editor "$(printf '%s' "$_gtr_line" | cut -f2)"
261+ return $?
262+ fi
263+ dir="$(printf '%s' "$_gtr_line" | cut -f1)"
230264 elif [ "$#" -eq 0 ]; then
231265 echo "Usage: __FUNC__ cd <branch>" >&2
232266 echo "Tip: Install fzf for an interactive picker (https://github.com/junegunn/fzf)" >&2
@@ -325,17 +359,41 @@ function __FUNC__
325359 --layout=reverse \
326360 --border \
327361 --prompt='Worktree> ' \
328- --header='enter:cd │ ctrl-e:editor │ ctrl-a:ai │ ctrl-d:delete │ ctrl-y:copy │ ctrl-r:refresh' \
362+ --header='enter:cd │ ctrl-n:new │ ctrl-e:editor │ ctrl-a:ai │ ctrl-d:delete │ ctrl-y:copy │ ctrl-r:refresh' \
363+ --expect=ctrl-n,ctrl-a,ctrl-e \
329364 --preview='git -C {1} log --oneline --graph --color=always -15 2>/dev/null; echo "---"; git -C {1} status --short 2>/dev/null' \
330365 --preview-window=right:50% \
331- --bind='ctrl-e:execute(git gtr editor {2})' \
332- --bind='ctrl-a:execute(git gtr ai {2})' \
333- --bind='ctrl-d:execute(git gtr rm {2})+reload(git gtr list --porcelain)' \
334- --bind='ctrl-y:execute(git gtr copy {2})' \
366+ --bind='ctrl-d:execute(git gtr rm {2} > /dev/tty 2>&1 < /dev/tty)+reload(git gtr list --porcelain)' \
367+ --bind='ctrl-y:execute(git gtr copy {2} > /dev/tty 2>&1 < /dev/tty)' \
335368 --bind='ctrl-r:reload(git gtr list --porcelain)')
336369 or return 0
337370 test -z "$_gtr_selection"; and return 0
338- set dir (string split \t -- "$_gtr_selection")[1]
371+ # --expect gives two lines: key (index 1) and selection (index 2)
372+ # Fish collapses empty lines in command substitution, so when Enter
373+ # is pressed the empty key line disappears and count drops to 1.
374+ if test (count $_gtr_selection) -eq 1
375+ set -l _gtr_key ""
376+ set -l _gtr_line "$_gtr_selection[1]"
377+ else
378+ set -l _gtr_key "$_gtr_selection[1]"
379+ set -l _gtr_line "$_gtr_selection[2]"
380+ end
381+ if test "$_gtr_key" = "ctrl-n"
382+ read -P "Branch name: " _gtr_branch
383+ test -z "$_gtr_branch"; and return 0
384+ command git gtr new "$_gtr_branch"
385+ return $status
386+ end
387+ test -z "$_gtr_line"; and return 0
388+ # ctrl-a/ctrl-e: run after fzf exits (needs full terminal for TUI apps)
389+ if test "$_gtr_key" = "ctrl-a"
390+ command git gtr ai (string split \t -- "$_gtr_line")[2]
391+ return $status
392+ else if test "$_gtr_key" = "ctrl-e"
393+ command git gtr editor (string split \t -- "$_gtr_line")[2]
394+ return $status
395+ end
396+ set dir (string split \t -- "$_gtr_line")[1]
339397 else if test (count $argv) -eq 1
340398 echo "Usage: __FUNC__ cd <branch>" >&2
341399 echo "Tip: Install fzf for an interactive picker (https://github.com/junegunn/fzf)" >&2
0 commit comments