13

MAC工具记录 - zsh&三剑客

 3 years ago
source link: https://studygolang.com/articles/30665
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

在 oh-my-zsh 中使用 fasd、ripgrep、fzf。

快速跳转工具 - fasd

fasd 是一个命令行加速工具,提供了对文件和文件夹的快速访问。

使用brew安装

# brew 查询 fasd 安装包
brew search fasd
# brew 安装
brew install fasd
# 更新
brew update fasd
# 卸载
brew uninstall fasd

设置oh-my-zsh

在 oh-my-zsh 文件中开启 fasd 插件

# 编辑 oh-my-zsh 配置文件
vim ~/.zshrc
# 一般在文件的第 71 行,插件列表中添加 fasd
plugins=(fasd)

自带别名列表

alias a='fasd -a'        # any
alias s='fasd -si'       # show / search / select
alias d='fasd -d'        # directory
alias f='fasd -f'        # file
alias sd='fasd -sid'     # interactive directory selection
alias sf='fasd -sif'     # interactive file selection
alias z='fasd_cd -d'     # cd, same functionality as j in autojump
alias zz='fasd_cd -d -i' # cd with interactive selection

别名使用

a foo 列出最近操作的路径匹配 'foo' 的文件与目录
f foo 列出最近操作的路径匹配 'foo' 的文件
d foo 列出最近操作的路径匹配 'foo' 的目录
s foo 列出最近操作的路径匹配 'foo' 的文件与目录,并可以通过序号选择
sf foo 列出最近操作的路径匹配'foo'的文件,并可以通过序号选择
sd foo 列出最近操作的路径匹配'foo'的目录,并可以通过序号选择
z foo cd到最近操作的匹配'foo'并且得分最高的目录
zz foo 列出最近操作的路径匹配'foo'的目录,通过序号选择,然后cd进目录

使用如下

a zshrc # 列出最近操作的路径匹配 'zshrc' 的文件与目录

除了z和zz带有cd的效果,其他的命令都是列出对应的目录,如果需要编辑器打开选定的路径,可参考以下两种方式。

# 1. 直接打开
vim `sf zshrc` # 相当于 vim ~/.zshrc
# 2. 通过配置别名
alias v='f -e vim'
v zshrc

文本搜索神器 - ripgrep

ripgrep 是一个以行为单位的搜索工具,可替代 grep 使用。

使用brew安装

# brew 查询 ripgrep 安装包
brew search ripgrep
# brew 安装
brew install ripgrep
# 更新
brew update ripgrep
# 卸载
brew uninstall ripgrep

设置oh-my-zsh

在 oh-my-zsh 文件中开启 ripgrep 插件

# 编辑 oh-my-zsh 配置文件
vim ~/.zshrc
# 一般在文件的第 71 行,插件列表中添加 ripgrep
plugins=(ripgrep)

使用如下

rg foo ./    # 查询当前文件夹中存在 foo 关键字的文件、行数和行内容
rg -e "plugins.+" .zshrc    # 使用正则匹配查找文件中的行内容
YJBnEn2.png!mobile

1.png

rg -e "plugins.+" .zshrc -o    # 只显示匹配部分的内容
qYbMNrJ.png!mobile

2.png

模糊文件搜索 - fzf

fasd 是一个由 golang 编写的模糊文件搜索工具。

使用brew安装

# brew 查询 fzf 安装包
brew search fzf
# brew 安装
brew install fzf
# 更新
brew update fzf
# 卸载
brew uninstall fzf

设置oh-my-zsh

在 oh-my-zsh 文件中开启 fzf 插件

# 编辑 oh-my-zsh 配置文件
vim ~/.zshrc
# 一般在文件的第 71 行,插件列表中添加 fzf
plugins=(fzf)

fzf 快捷键

在 finder(输出交换窗口)里,

  • Ctrl - J / Ctrl - K 上下移动光标
  • Enter 选中条目,Ctrl -C / Ctrl - G / Esc 退出
  • 在多选模式下 (-m) ,TAB 和 Shift - TAB 多选
  • Mouse: 上下滚动选中;双击选中

窗口大小设置

fzf 默认为全屏模式,可通过定制高度

vim $(fzf --height 40%)

或修改环境变量来调整。

vim ~/.bash_profile
# 添加环境变量
export FZF_DEFAULT_OPTS=--height 40% --reverse --border
# 使环境变量生效
source ~/.bash_profile

搜索语法

fzf 默认会以 'extend-search' 模式启动,这种模式下可以输入多个以空格分隔的关键字来搜索,如 ^music .mp3$ sbtrkt !fire

Token Match type Descriptio sbtrkt fuzzy-match Items that match sbtrkt 'wild exact-match (quoted) Items that include wild ^music prefix-exact-match Items that start with music .mp3$ suffix-exact-match Items that end with .mp3 !fire inverse-exact-match Items that do not include fire !^music inverse-prefix-exact-match Items that do not start with music !.mp3$ inverse-suffix-exact-match Items that do not end with .mp3

有疑问加站长微信联系

iiUfA3j.png!mobile

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK