Created
February 19, 2017 16:25
-
-
Save chew-z/078d8a68945bb26ca83e5b829c505bf0 to your computer and use it in GitHub Desktop.
My CtrlP - using fzf - open, edit or reveal in finder
This file contains hidden or 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
#!/usr/bin/env zsh | |
# | |
# https://adamheins.com/blog/ctrl-p-in-the-terminal-with-fzf | |
# This is the same functionality as fzf's ctrl-t, except that the file or | |
# directory selected is now automatically cd'ed or opened, respectively. | |
fzf-edit-file-or-open-dir() { | |
local out key file helpline | |
helpline="Ctrl-f to open in Finder | uses ag -g\"\" respecting .ignore" | |
IFS=$'\n' out=($(ag -g "" | fzf --header="$helpline" --exit-0 --expect=ctrl-f)) | |
key=$(head -1 <<< "$out") | |
file=$(head -2 <<< "$out" | tail -1) | |
if [ "$key" = ctrl-f ]; then | |
open -R "$file" # reveal in Finder | |
else | |
if [ -f "$file" ]; then | |
open -a MacVim "$file" | |
elif [ -d "$file" ]; then | |
cd "$file" | |
fi | |
zle reset-prompt | |
fi | |
zle accept-line | |
} | |
zle -N fzf-edit-file-or-open-dir | |
bindkey '^P' fzf-edit-file-or-open-dir | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment