Skip to content

Instantly share code, notes, and snippets.

@okdtsk
Created June 17, 2025 00:56
Show Gist options
  • Select an option

  • Save okdtsk/d97d313284d889091da094a651a6aa56 to your computer and use it in GitHub Desktop.

Select an option

Save okdtsk/d97d313284d889091da094a651a6aa56 to your computer and use it in GitHub Desktop.
gcd: Fish Function to change working directory to github repositories managed by ghq
function gcd
# Check if ghq and fzf are installed
if not command -v ghq >/dev/null
echo "Error: ghq is not installed" >&2
return 1
end
if not command -v fzf >/dev/null
echo "Error: fzf is not installed" >&2
return 1
end
# Define preview command
set preview_cmd "echo 'Repository: {}'; echo; eza -lah --git --git-ignore --group-directories-first --total-size --time-style='iso' --color=always (ghq root)/{}"
# Set initial query if argument is provided
set fzf_options --prompt="Select repository: " \
--select-1 \
--border \
--preview="$preview_cmd" \
--preview-window=right:50%:wrap
if test -n "$argv[1]"
set fzf_options $fzf_options --query="$argv[1]"
end
# Get repository list with ghq and select with fzf (with preview)
set selected_repo (ghq list | fzf $fzf_options)
# Return if cancelled in fzf
if test -z "$selected_repo"
return
end
# Get full path of selected repository and cd to it
set repo_path (ghq root)/$selected_repo
cd $repo_path
# Display current directory and branch information
echo "📁 $repo_path"
if test -d .git
set current_branch (git branch --show-current 2>/dev/null)
if test -n "$current_branch"
echo "🌿 Current branch: $current_branch"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment