Skip to content

Commit 584c17a

Browse files
authored
fix(ux): improve fzf picker discoverability and empty state (#139)
1 parent 929026d commit 584c17a

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

lib/commands/doctor.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,32 @@ cmd_doctor() {
114114

115115
# Check fzf (optional, for interactive picker)
116116
if command -v fzf >/dev/null 2>&1; then
117-
echo "[OK] fzf: $(fzf --version 2>/dev/null | awk '{print $1}') (interactive picker available)"
117+
echo "[OK] fzf: $(fzf --version 2>/dev/null | awk '{print $1}') (interactive picker: gtr cd)"
118118
else
119119
echo "[i] fzf: not found (install for interactive picker: gtr cd)"
120120
fi
121121

122+
# Check shell integration (required for gtr cd)
123+
local _shell_name _rc_file
124+
_shell_name="$(basename "${SHELL:-bash}")"
125+
case "$_shell_name" in
126+
zsh) _rc_file="$HOME/.zshrc" ;;
127+
bash) _rc_file="$HOME/.bashrc" ;;
128+
fish) _rc_file="$HOME/.config/fish/config.fish" ;;
129+
*) _rc_file="" ;;
130+
esac
131+
if [ -n "$_rc_file" ] && [ -f "$_rc_file" ] && grep -q 'git gtr init' "$_rc_file" 2>/dev/null; then
132+
echo "[OK] Shell integration: loaded (gtr cd available)"
133+
elif [ -n "$_rc_file" ]; then
134+
local _init_hint
135+
if [ "$_shell_name" = "fish" ]; then
136+
_init_hint="git gtr init fish | source"
137+
else
138+
_init_hint="eval \"\$(git gtr init $_shell_name)\""
139+
fi
140+
echo "[i] Shell integration: $_init_hint in ${_rc_file##*/} for gtr cd"
141+
fi
142+
122143
echo ""
123144
if [ "$issues" -eq 0 ]; then
124145
echo "Everything looks good!"

lib/commands/init.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,14 @@ __FUNC__() {
8383
shift
8484
local dir
8585
if [ "$#" -eq 0 ] && command -v fzf >/dev/null 2>&1; then
86+
local _gtr_porcelain
87+
_gtr_porcelain="$(command git gtr list --porcelain)"
88+
if [ "$(printf '%s\n' "$_gtr_porcelain" | wc -l)" -le 1 ]; then
89+
echo "No worktrees to pick from. Create one with: git gtr new <branch>" >&2
90+
return 0
91+
fi
8692
local _gtr_selection
87-
_gtr_selection="$(command git gtr list --porcelain | fzf \
93+
_gtr_selection="$(printf '%s\n' "$_gtr_porcelain" | fzf \
8894
--delimiter=$'\t' \
8995
--with-nth=2 \
9096
--ansi \
@@ -183,8 +189,14 @@ __FUNC__() {
183189
shift
184190
local dir
185191
if [ "$#" -eq 0 ] && command -v fzf >/dev/null 2>&1; then
192+
local _gtr_porcelain
193+
_gtr_porcelain="$(command git gtr list --porcelain)"
194+
if [ "$(printf '%s\n' "$_gtr_porcelain" | wc -l)" -le 1 ]; then
195+
echo "No worktrees to pick from. Create one with: git gtr new <branch>" >&2
196+
return 0
197+
fi
186198
local _gtr_selection
187-
_gtr_selection="$(command git gtr list --porcelain | fzf \
199+
_gtr_selection="$(printf '%s\n' "$_gtr_porcelain" | fzf \
188200
--delimiter=$'\t' \
189201
--with-nth=2 \
190202
--ansi \
@@ -287,7 +299,12 @@ function __FUNC__
287299
if test (count $argv) -gt 0; and test "$argv[1]" = "cd"
288300
set -l dir
289301
if test (count $argv) -eq 1; and type -q fzf
290-
set -l _gtr_selection (command git gtr list --porcelain | fzf \
302+
set -l _gtr_porcelain (command git gtr list --porcelain)
303+
if test (count $_gtr_porcelain) -le 1
304+
echo "No worktrees to pick from. Create one with: git gtr new <branch>" >&2
305+
return 0
306+
end
307+
set -l _gtr_selection (printf '%s\n' $_gtr_porcelain | fzf \
291308
--delimiter=\t \
292309
--with-nth=2 \
293310
--ansi \

0 commit comments

Comments
 (0)