Skip to content

Instantly share code, notes, and snippets.

@omaryoussef
Last active August 17, 2019 17:33
Show Gist options
  • Save omaryoussef/dadae995be000c38cd88067b144e8685 to your computer and use it in GitHub Desktop.
Save omaryoussef/dadae995be000c38cd88067b144e8685 to your computer and use it in GitHub Desktop.
Add Ctrl+P functionality to the ZSH command line
# Adds Ctrl+P funcionality similar to Ctrl+T in fzf to open a file directly in vim from the command line
command -v fzf >/dev/null 2>&1 || { exit 0; }
# Optional to use Ripgrep, comment this out if otherwise
export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --glob "!{.git,node_modules}/*"'
fzf-ctrlp-widget() {
local file="$(__fsel)"
local ret=$?
file="$(echo -e "${file}" | sed -e 's/[[:space:]]*$//')"
# Open the file if it exists
if [ -n "$file" ]; then
</dev/tty vim "$file"
fi
zle redisplay
typeset -f zle-line-init >/dev/null && zle zle-line-init
return $ret
}
zle -N fzf-ctrlp-widget
bindkey "^p" fzf-ctrlp-widget
command -v rg >/dev/null 2>&1 || { return 0; }
_fzf_compgen_path() {
rg --files --no-ignore --hidden --follow -g "!{.git,node_modules}/*" 2> /dev/null
#rg --files --hidden --no-ignore --no-messages
}
# Add to the bottom of your .zshrc file to source the file.
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh && source ~/.shell_utils.zsh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment