Skip to content

Instantly share code, notes, and snippets.

@macoshita
Forked from sheepla/ghq-fzf.zsh
Last active December 16, 2021 15:01
Show Gist options
  • Save macoshita/d71b9ef0f272c57fb57a0e1d56118653 to your computer and use it in GitHub Desktop.
Save macoshita/d71b9ef0f272c57fb57a0e1d56118653 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}")"
if [ -n "$repo" ]; then
BUFFER="cd $root/$repo"
zle accept-line
fi
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