Skip to content

Commit 40005e9

Browse files
committed
add opton to open in editor plus more
1 parent 5529729 commit 40005e9

File tree

3 files changed

+84
-57
lines changed

3 files changed

+84
-57
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,11 @@ eval "$(git gtr init bash)"
221221
gtr cd # Interactive worktree picker (requires fzf)
222222
gtr cd my-feature
223223
gtr cd 1
224+
gtr cd # interactive picker (requires fzf)
224225
```
225226

227+
With [fzf](https://github.com/junegunn/fzf) installed, `gtr cd` (no arguments) opens a command palette with git log preview and keybindings: `ctrl-e` editor, `ctrl-a` AI, `ctrl-d` delete, `ctrl-y` copy, `ctrl-r` refresh.
228+
226229
> **Note:** If `gtr` conflicts with another command (e.g., GNU `tr` from coreutils), use `--as` to pick a different name:
227230
>
228231
> ```bash

lib/commands/help.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,19 @@ Setup:
365365
eval "$(git gtr init zsh --as gwtr)"
366366
367367
After setup:
368-
gtr cd # interactive worktree picker (requires fzf)
369368
gtr cd my-feature # cd to worktree
370369
gtr cd 1 # cd to main repo
370+
gtr cd # interactive picker (requires fzf)
371371
gtr <command> # same as git gtr <command>
372+
373+
Command palette (gtr cd with no arguments, requires fzf):
374+
enter cd into selected worktree
375+
ctrl-e open in editor
376+
ctrl-a start AI tool
377+
ctrl-d delete worktree (with confirmation)
378+
ctrl-y copy files to worktree
379+
ctrl-r refresh list
380+
esc cancel
372381
EOF
373382
}
374383

@@ -550,7 +559,7 @@ SETUP & MAINTENANCE:
550559
Generate shell integration for cd support (bash, zsh, fish)
551560
--as <name>: custom function name (default: gtr)
552561
Usage: eval "$(git gtr init bash)"
553-
With fzf installed, 'gtr cd' (no args) opens an interactive picker
562+
With fzf: 'gtr cd' opens a command palette (preview, editor, AI, delete)
554563
555564
version
556565
Show version

lib/commands/init.sh

Lines changed: 70 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -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
267277
function __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

Comments
 (0)