Created
September 5, 2019 22:08
-
-
Save yhirose/49b521ac887c7a0bd63f61130d93316e to your computer and use it in GitHub Desktop.
fzf
This file contains 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
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