-
-
Save macoshita/d71b9ef0f272c57fb57a0e1d56118653 to your computer and use it in GitHub Desktop.
ghq で管理しているリポジトリに Ctrl-g で cd する on zsh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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