diff --git a/lib/commands/doctor.sh b/lib/commands/doctor.sh index 6edf88c..df749bc 100644 --- a/lib/commands/doctor.sh +++ b/lib/commands/doctor.sh @@ -114,11 +114,32 @@ cmd_doctor() { # Check fzf (optional, for interactive picker) if command -v fzf >/dev/null 2>&1; then - echo "[OK] fzf: $(fzf --version 2>/dev/null | awk '{print $1}') (interactive picker available)" + echo "[OK] fzf: $(fzf --version 2>/dev/null | awk '{print $1}') (interactive picker: gtr cd)" else echo "[i] fzf: not found (install for interactive picker: gtr cd)" fi + # Check shell integration (required for gtr cd) + local _shell_name _rc_file + _shell_name="$(basename "${SHELL:-bash}")" + case "$_shell_name" in + zsh) _rc_file="$HOME/.zshrc" ;; + bash) _rc_file="$HOME/.bashrc" ;; + fish) _rc_file="$HOME/.config/fish/config.fish" ;; + *) _rc_file="" ;; + esac + if [ -n "$_rc_file" ] && [ -f "$_rc_file" ] && grep -q 'git gtr init' "$_rc_file" 2>/dev/null; then + echo "[OK] Shell integration: loaded (gtr cd available)" + elif [ -n "$_rc_file" ]; then + local _init_hint + if [ "$_shell_name" = "fish" ]; then + _init_hint="git gtr init fish | source" + else + _init_hint="eval \"\$(git gtr init $_shell_name)\"" + fi + echo "[i] Shell integration: $_init_hint in ${_rc_file##*/} for gtr cd" + fi + echo "" if [ "$issues" -eq 0 ]; then echo "Everything looks good!" diff --git a/lib/commands/init.sh b/lib/commands/init.sh index d29f02f..daf30c0 100644 --- a/lib/commands/init.sh +++ b/lib/commands/init.sh @@ -83,8 +83,14 @@ __FUNC__() { shift local dir if [ "$#" -eq 0 ] && command -v fzf >/dev/null 2>&1; then + local _gtr_porcelain + _gtr_porcelain="$(command git gtr list --porcelain)" + if [ "$(printf '%s\n' "$_gtr_porcelain" | wc -l)" -le 1 ]; then + echo "No worktrees to pick from. Create one with: git gtr new " >&2 + return 0 + fi local _gtr_selection - _gtr_selection="$(command git gtr list --porcelain | fzf \ + _gtr_selection="$(printf '%s\n' "$_gtr_porcelain" | fzf \ --delimiter=$'\t' \ --with-nth=2 \ --ansi \ @@ -183,8 +189,14 @@ __FUNC__() { shift local dir if [ "$#" -eq 0 ] && command -v fzf >/dev/null 2>&1; then + local _gtr_porcelain + _gtr_porcelain="$(command git gtr list --porcelain)" + if [ "$(printf '%s\n' "$_gtr_porcelain" | wc -l)" -le 1 ]; then + echo "No worktrees to pick from. Create one with: git gtr new " >&2 + return 0 + fi local _gtr_selection - _gtr_selection="$(command git gtr list --porcelain | fzf \ + _gtr_selection="$(printf '%s\n' "$_gtr_porcelain" | fzf \ --delimiter=$'\t' \ --with-nth=2 \ --ansi \ @@ -287,7 +299,12 @@ function __FUNC__ if test (count $argv) -gt 0; and test "$argv[1]" = "cd" set -l dir if test (count $argv) -eq 1; and type -q fzf - set -l _gtr_selection (command git gtr list --porcelain | fzf \ + set -l _gtr_porcelain (command git gtr list --porcelain) + if test (count $_gtr_porcelain) -le 1 + echo "No worktrees to pick from. Create one with: git gtr new " >&2 + return 0 + end + set -l _gtr_selection (printf '%s\n' $_gtr_porcelain | fzf \ --delimiter=\t \ --with-nth=2 \ --ansi \