all repos — nixfiles @ e9d22a78a393d2c2e8d4c92c6d39dad8352f49fa

System and user configuration, managed by nix and home-manager

zsh: Create function & widget to cd into ghq projects

Alan Pearce
commit

e9d22a78a393d2c2e8d4c92c6d39dad8352f49fa

parent

7aa006027e6a4d267bdfde0d5a3cf9a3a0377221

1 file changed, 20 insertions(+), 0 deletions(-)

jump to
M zsh/.config/zsh/.zshrczsh/.config/zsh/.zshrc
@@ -234,6 +234,26 @@ command find -L "$1" \
-name .git -prune -o -name .svn -prune -o -type d \ -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@' } + + fp () { + ghq look $(ghq list | fzf +m) + } + cd-project-widget () { + local cmd="ghq list" + setopt localoptions pipefail 2> /dev/null + local dir="$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS" fzf +m)" + if [[ -z "$dir" ]]; then + zle redisplay + return 0 + fi + cd $(ghq list --full-path | grep "$dir") + local ret=$? + zle reset-prompt + typeset -f zle-line-init >/dev/null && zle zle-line-init + return $ret + } + zle -N cd-project-widget + bindkey '\es' cd-project-widget fi unsetopt flow_control # Let me use ^S and ^Q