跳至主要内容

television

Overview

television 是一款以 Rust 開發的通用模糊搜尋工具。 與傳統的 fzf 不同,television 內建了多種「頻道 (channels)」作為資料來源, 不需要透過 pipe 餵入資料就能直接進行搜尋。

主要特色:

  • 🦀 Rust 開發,效能優異
  • 📺 內建多種 channels(檔案、Git repos、環境變數等)
  • 🎯 開箱即用,不需額外組合指令
  • 🖥️ 內建預覽功能,支援語法高亮
  • ⚡ 即時模糊搜尋,支援多種匹配演算法

Install

# macOS (Homebrew)
brew install television

# Cargo
cargo install television

# Arch Linux
pacman -S television

Basic Usage

# 啟動預設頻道 (files)
tv

# 指定頻道啟動
tv files
tv git-repos
tv git-branches
tv env
tv aliases
tv text

# 搜尋後輸出選取結果至 stdout
tv files | xargs code

基本操作:

  • 輸入文字即開始模糊搜尋
  • Enter 確認選取
  • Esc / Ctrl+C 取消
  • Ctrl+N / Ctrl+P 上下移動
  • Tab 切換頻道

Channels (資料來源)

television 的核心概念是 channels,每個 channel 是一個獨立的資料來源:

Channel說明指令
Files當前目錄下的檔案tv files
Git Repos系統中的 Git 倉庫tv git-repos
Git Branches當前 repo 的分支tv git-branches
Env環境變數tv env
AliasesShell aliasestv aliases
Recent Dirs最近存取的目錄tv recent-dirs
Text (grep)檔案內容全文搜尋tv text

也可以自訂 channel,從任意指令輸出建立資料來源。

Configuration

設定檔位置:~/.config/television/config.toml

# 預設頻道
default_channel = "files"

# 快捷鍵設定
[keybindings]
quit = ["esc", "ctrl-c"]
select = ["enter"]
channel_next = ["tab"]
channel_prev = ["shift-tab"]

# UI 設定
[ui]
preview = true
preview_width = 50

與 fzf 的比較

特性fzftelevision
定位通用 filter (stdin → stdout)整合型模糊搜尋器
資料來源需透過 pipe 提供內建 channels
Shell 整合Ctrl+R, Ctrl+T, Alt+C有限
自訂性極高(任意組合)中等(channel 為主)
啟動速度極快
適用場景Pipeline、Shell 整合快速獨立搜尋

建議使用方式: 兩者可以共存。fzf 作為核心模糊引擎處理 pipe 和 shell 整合場景, television 則用於需要快速獨立搜尋特定資料來源(如 git repos、環境變數)的情境。

# fzf: pipe 導向,靈活組合
cat ~/.zsh_history | fzf
find . -name "*.ts" | fzf --preview 'bat {}'

# television: 內建來源,開箱即用
tv git-repos # 直接搜尋所有 git 倉庫
tv env # 快速查找環境變數

See Also