Skip to content

Instantly share code, notes, and snippets.

@yhirose
Created September 5, 2019 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yhirose/49b521ac887c7a0bd63f61130d93316e to your computer and use it in GitHub Desktop.
Save yhirose/49b521ac887c7a0bd63f61130d93316e to your computer and use it in GitHub Desktop.
fzf
function fzf-default() {
fzf --multi --ansi --select-1 --exit-0 --reverse --height '40%'
}
function fzf-cd() {
local DIR=$(fd --type d | fzf +m --ansi --select-1 --reverse)
if [ -n "$DIR" ]; then
cd $DIR
fi
}
function fzf-ag() {
if [ -z "$1" ]; then
echo 'Usage: agg PATTERN'
return 0
fi
local result=`ag $1 | fzf`
local line=`echo "$result" | awk -F ':' '{print $2}'`
local file=`echo "$result" | awk -F ':' '{print $1}'`
if [ -n "$file" ]; then
vi $file +$line
fi
}
function fzf-vi() {
fd ${1:-.} | fzf-default | xargs -o vi
}
alias d='fzf-cd'
alias g="fzf-ag"
alias v='fzf-vi'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment