上图左侧是文件列表,右侧是rougify生成的预览窗口,可以用鼠标上下滚动,遗憾的是用键盘没法移动光标到右侧窗口进行上下滚动。
fzf示例
interactive cd
安装
wget https://github.com/changyuheng/zsh-interactive-cd/blob/master/zsh-interactive-cd.plugin.zsh
cp zsh-interactive-cd.plugin.zsh ~/.fzf/shell
echo \'source ~/.fzf/shell/zsh-interactive-cd.plugin.zsh\' >> ~/.zshrc
cd后按ctrl-i就会打开fzf finder窗口
z
# fasd & fzf change directory - jump using `fasd` if given argument, filter output of `fasd` using `fzf` else
z() {
[ $# -gt 0 ] && fasd_cd -d "$*" && return
local dir
dir="$(fasd -Rdl "$1" | fzf -1 -0 --no-sort +m)" && cd "${dir}" || return 1
}
changing directory
# 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"
}
# fdr - cd to selected parent directory
fdr() {
local declare dirs=()
get_parent_dirs() {
if [[ -d "${1}" ]]; then dirs+=("$1"); else return; fi
if [[ "${1}" == \'/\' ]]; then
for _dir in "${dirs[@]}"; do echo $_dir; done
else
get_parent_dirs $(dirname "$1")
fi
}
local DIR=$(get_parent_dirs $(realpath "${1:-$PWD}") | fzf-tmux --tac)
cd "$DIR"
}
# cf - fuzzy cd from anywhere
# ex: cf word1 word2 ... (even part of a file name)
# zsh autoload function
cf() {
local file
file="$(locate -Ai -0 $@ | grep -z -vE \'~$\' | fzf --read0 -0 -1)"
if [[ -n $file ]]
then
if [[ -d $file ]]
then
cd -- $file
else
cd -- ${file:h}
fi
fi
}
v
# fasd & fzf change directory - open best matched file using `fasd` if given argument, filter output of `fasd` using `fzf` else
v() {
[ $# -gt 0 ] && fasd -f -e ${EDITOR} "$*" && return
local file
file="$(fasd -Rfl "$1" | fzf -1 -0 --no-sort +m)" && vi "${file}" || return 1
}
fzf的vim插件
在.vimrc里用vunble安装
set rtp+=http://www.likecs.com/home/harriszh/.fzf/
...
Plugin \'junegunn/fzf.vim\'
...
然后FZF等命令就可以使用了
建议要安装ag,并把FZF_DEFAULT_COMMAND改成ag
后言
fzf是非常强大的胶水工具,利用它和ag, fasd及shell command可以实现非常绚烂的功能。更多例子见wiki
如果上文有错误的地方,欢迎联系作者