Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iammerrick/afd08241030b6fdc9cdb998b52fb62b8 to your computer and use it in GitHub Desktop.
Save iammerrick/afd08241030b6fdc9cdb998b52fb62b8 to your computer and use it in GitHub Desktop.
# CTRL-P - cd into the selected directory
#
__fzfcmd() {
[ ${FZF_TMUX:-1} -eq 1 ] && echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
}
fzf-cd-widget() {
local cmd="${FZF_CTRL_P_COMMAND:-"command find -L ~ \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
-o -type d -print 2> /dev/null | sed 1d"}"
setopt localoptions pipefail 2> /dev/null
cd "${$(eval "$cmd | $(__fzfcmd) +m $FZF_CTRL_P_OPTS"):-.}"
local ret=$?
zle reset-prompt
typeset -f zle-line-init >/dev/null && zle zle-line-init
return $ret
}
zle -N fzf-cd-widget
bindkey "^P" fzf-cd-widget
@iammerrick
Copy link
Author

Adapted from bindings provided by fzf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment