Skip to content

Instantly share code, notes, and snippets.

@sheepla
Last active February 17, 2024 14:05
Show Gist options
  • Save sheepla/d680f1480d8c36c4290d6aabebf1abc6 to your computer and use it in GitHub Desktop.
Save sheepla/d680f1480d8c36c4290d6aabebf1abc6 to your computer and use it in GitHub Desktop.
ghq で管理しているリポジトリに Ctrl-g で cd する on zsh
#
# ghq-fzf.zsh
#
# ABOUT:
# `cd` to `ghq` repositories directory on `zsh`
# You can launch this function with `Ctrl-g`
#
# INSTALLATION:
# Requires `zsh` and `fzf`
# Download this file then, append `source path/to/fzf-ghq.zsh` to your `~/.zshrc`
# or copy & paste to your `~/.zshrc`
#
function _fzf_cd_ghq() {
FZF_DEFAULT_OPTS="${FZF_DEFAULT_OPTS} --reverse --height=50%"
local root="$(ghq root)"
local repo="$(ghq list | fzf --preview="ls -AF --color=always ${root}/{1}")"
local dir="${root}/${repo}"
[ -n "${dir}" ] && cd "${dir}"
zle accept-line
zle reset-prompt
}
zle -N _fzf_cd_ghq
bindkey "^g" _fzf_cd_ghq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment