ag比grep快速的速度, 同时打印出搜索词的行数.
Fasd 时空机, 瞬间跳到去过的目录, 或定位打开过的文件.
Fzf 模糊搜索工具.
1. 安装ag fasd fzf
1.1 Mac安装ag fasd fzf.
brew install the_silver_searcher fzf fasd
# 以下内容添加到~/.zshrc或~/.bashrc中
eval "$(fasd --init auto)"
# 重新生效
source ~/.zshrc 或 source ~/.bashrc
1.2 Linux安装ag fasd fzf.
yum install the_silver_searcher fasd
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install

2. 别名
alias jan='fasd -a' # any
alias js='fasd -si' # show / search / select
alias jd='fasd -d' # directory
alias jf='fasd -f' # file
alias jsd='fasd -sid' # interactive directory selection
alias jsf='fasd -sif' # interactive file selection
alias j='fasd_cd -d' # cd, same functionality as j in autojump
alias jz='fasd_cd -d -i' # cd with interactive selection
alias jdd='fasd -D' # 删除一个路径
alias v='jf -e vim'
alias nv='jf -e nvim'
alias catf='jf -e cat'
alias py3f="jf -e python3"
alias lsf="jd -e ls"
alias shf='jf -e sh'
alias commandf='jf -e command'
# preview file
alias ffp='fzf --preview '"'"'[[ $(file --mime {}) =~ binary ]] && echo {} is a binary file || (rougify {} || highlight -O ansi -l {} || coderay {} || cat {}) 2> /dev/null | head -500'"'"
# 跳到最近匹配的目录中
jj() {
[ $# -gt 0 ] && fasd_cd -d "$*" && return
local dir
dir="$(fasd -Rdl "$1" | fzf -1 -0 --no-sort +m)" && cd "${dir}" || return 1
}
jje() {
[ $# -gt 0 ] && fasd_cd -d "$*" && return
local dir
dir="$(fasd -Rdl "$1" | fzf -e -1 -0 --no-sort +m)" && cd "${dir}" || return 1
}
# 从当前路径搜索并跳转
jcd() {
local dir
dir=$(find ${1:-.} -path '*/\.*' -prune \
-o -type d -print 2> /dev/null | fzf +m) &&
cd "$dir"
}
jcde() {
local dir
dir=$(find ${1:-.} -path '*/\.*' -prune \
-o -type d -print 2> /dev/null | fzf -e +m) &&
cd "$dir"
}
alias ffall="find / -type f | fzf | pbcopy"
alias ffm="find ~/ -type f | fzf | pbcopy"
alias ffd="find . -type f | fzf | pbcopy"
alias ffec="find ~/ -type f | fzf -e | pbcopy"
3. 使用效果
3.1 ag, ag与fasd联用.
3.2 fasd使用
单个文件夹
多个目录关键词也能识别出来
3.3 fzf 搜索命令行历史记录 模糊搜索并跳转, 预览文件内容

Control + R 搜索命令行历史记录

模糊搜索并跳转

快速预览文件内容