Skip to content

Instantly share code, notes, and snippets.

@jrnewell
Created November 2, 2017 15:35
Show Gist options
  • Save jrnewell/fc302a1eb659010379970686b68d0530 to your computer and use it in GitHub Desktop.
Save jrnewell/fc302a1eb659010379970686b68d0530 to your computer and use it in GitHub Desktop.
# Auto-completion
# ---------------
[[ $- =~ i ]] && source "/usr/local/opt/fzf/shell/completion.bash"
# Key bindings
# ------------
source "/usr/local/opt/fzf/shell/key-bindings.bash"
# fd - cd to selected directory
fd() {
local dir
dir=$(find ${1:-*} -path '*/\.*' -prune \
-o -type d -print 2> /dev/null | fzf +m) &&
cd "$dir"
}
# fda - including hidden directories
fda() {
local dir
dir=$(find ${1:-.} -type d 2> /dev/null | fzf +m) && cd "$dir"
}
# cdf - cd into the directory of the selected file
cdf() {
local file
local dir
file=$(fzf +m -q "$1") && dir=$(dirname "$file") && cd "$dir"
}
# fe [FUZZY PATTERN] - Open the selected file with the default editor
# - Bypass fuzzy finder if there's only one match (--select-1)
# - Exit if there's no match (--exit-0)
fe() {
local file
file=$(fzf --query="$1" --select-1 --exit-0)
[ -n "$file" ] && ${EDITOR:-vim} "$file"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment