Jacky's blog
首页
  • Android
  • Web
  • Server
  • Python
  • iOS
  • Java
  • Vue
  • 计算机基础
  • AI
  • 全部工具
  • CLI 工具
  • 编辑器
  • 开发工具
  • 构建工具
  • 版本控制
  • 调试工具
  • 网络工具
  • 个人成长
  • 博客
  • 分类
  • 标签
  • 归档
收藏
GitHub (opens new window)

Jack Yang

编程; 随笔
首页
  • Android
  • Web
  • Server
  • Python
  • iOS
  • Java
  • Vue
  • 计算机基础
  • AI
  • 全部工具
  • CLI 工具
  • 编辑器
  • 开发工具
  • 构建工具
  • 版本控制
  • 调试工具
  • 网络工具
  • 个人成长
  • 博客
  • 分类
  • 标签
  • 归档
收藏
GitHub (opens new window)
  • 开发工具

  • 构建工具

  • 版本控制

  • 容器

  • 调试工具

  • 测试工具

  • CLI 工具

    • tmux
    • oh-my-zsh
    • ripgrep 高性能文本搜索工具使用指南
    • awk
    • sed
    • xargs
    • fzf
      • Shell Integration
      • support
        • fzf-git
      • tricks
        • 1. 在shell中浏览任何目录下的文件内容
        • 2. git 高效切换分支
        • 3. 选择Android手机的当天媒文件并保存到本地
        • 4. 解压并打开技巧
      • link
    • fd
    • raycast
    • VisiData 终极生存指南(vd)
    • yq
    • direnv
    • ln 软链接/硬链接使用指南
    • watch 周期监控使用指南
    • osascript
  • 网络工具

  • 编辑器

  • 设计工具

  • 多媒体

  • 包管理

  • 平台工具

  • tools
  • cli_tools
Jacky
2026-04-11
目录

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 fzf
  • CTRL + 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 功能

  1. 在 raycast 中创建 snippet cat $(find {clipboard} -type f 2>/dev/null | fzf --preview="cat {} | head -50"), 取名 <snippet_name>
  2. 复制需要浏览的目录,然后打开 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

注: 另一个更加高效的可以使用 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

# 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

注:

  • 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
#Shell#Linux#tool#cli
上次更新: 2026/10/18, 22:14:48
xargs
fd

← xargs fd→

最近更新
01
Codex 使用与会话管理指南
10-17
02
Tailscale 入门:让自己的设备跨网络互联
10-15
03
GitHub CLI(gh)工作流与 CI 排查
10-08
更多文章>
Theme by Vdoing | Copyright © 2019-2026 Jacky | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式