fzf
fzf is a general-purpose command-line fuzzy finder.
# Shell Integration
http://junegunn.github.io/fzf/shell-integration/ (opens new window)
CTRL + T: complete the command using fzfCTRL + R: 搜索历史命令CTRL-/: see the whole command
Option + C: 搜索目录(直接 cd 进去)。
# support
https://junegunn.github.io/fzf/examples/directory-navigation/ (opens new window)
# fzf-git
fzf-github (opens new window) project provides a bunch of key bindings for completing Git objects. You should definitely check it out. example (opens new window)
# tricks
# 1. 在shell中浏览任何目录下的文件内容
本方案借助 raycast 的 snippets 功能
- 在 raycast 中创建 snippet
cat $(find {clipboard} -type f 2>/dev/null | fzf --preview="cat {} | head -50"), 取名 <snippet_name> - 复制需要浏览的目录,然后打开 raycast。 搜素上述 <snippet_name>。 按Enter触发文件浏览
# 2. git 高效切换分支
# 1
git branch | fzf | cut -c 3- | xargs git checkout
# 2. 输出纯净的分支名,省去 cut 这一步
git branch --format='%(refname:short)' | fzf | xargs git checkout
1
2
3
4
5
2
3
4
5
注: 另一个更加高效的可以使用 fzf-git 支持。 具体可以参照fzf-git
# 3. 选择Android手机的当天媒文件并保存到本地
# 1. 一行方案
file=$(adb shell ls /sdcard/Pictures/Screenshots | grep $(date +%Y%m%d) | tr -d '\r' | fzf --prompt="选择需要pull的媒体文件") && [ -n "$file" ] && adb pull "/sdcard/Pictures/Screenshots/$file"
# 2. 脚本function方案
a_pull() {
local date="${1:-$(date +%Y%m%d)}"
local file=$(adb shell ls /sdcard/Pictures/Screenshots | grep "$date" | tr -d '\r' | fzf --prompt="选择需要pull的媒体文件")
[ -z "$file" ] && return 1
adb pull "/sdcard/Pictures/Screenshots/$file"
}
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 4. 解压并打开技巧
选择zip文件,解压。并使用 klog工具打开
# 1. 一行方案
selectZip=$(find . -name '*.zip' -exec ls -t {} + | sed 's|^\./||' | fzf --prompt="自动解压并使用klog打开工具:请选择你要操作的zip包") && [ -n "$selectZip" ] && logfile=$(tar xvf "$selectZip" 2>&1 | head -1 | sed 's/^x //') && open -a "$APP_KLOGG" "$logfile"
# 2. 脚本function方案。 支持zip和log文件选择
klog() {
local file="${1:-$(find . \( -name '*.zip' -o -name '*.log' \) -exec ls -t {} + | sed 's|^\./||' | fzf --prompt='选择文件: ')}"
[ -z "$file" ] && return 1
if [[ "$file" == *.zip ]]; then
local logfile=$(tar xvf "$file" 2>&1 | head -1 | sed 's/^x //')
[ -n "$logfile" ] && open -a "$APP_KLOGG" "$logfile"
else
open -a "$APP_KLOGG" "$file"
fi
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
注:
tar xvf "$selectZip" 2>&1: tar xvf 的 verbose 输出(文件名列表)走的是 stderr. 加2>&1将 stderr 重定向到 stdout
# link
- fzf-github (opens new window) github 官网
- fzf-io (opens new window) useful
上次更新: 2026/10/18, 22:14:48