Television

Television

Intro

Television 是一个跨平台、快速且可扩展的通用模糊查找器📺

Fuzzy Finder

快速查找文件、目录、命令历史等工作都是常见的需求,用cd ls cd ls...多少有点复古了。

维新派的解决方案是使用模糊查找器,多数fuzzy finder提供了TUI(Terminal User Interface)界面,相比对着CLI(Command Line Interface)手敲cd ls cd ls...,显然TUI更User-Friendly。

例如我们通过fd递归的查找所有子目录,再将其传递给fzf进行模糊匹配:

1
fd --type directory | fzf --preview 'eza --all --git --long --no-time --color=always --icons {}'
television_fzf_example.webp

更进一步的集成,一般是要将模糊查找器的结果插入到命令行中,例如输入cd后按下Ctrl-T,然后在fzf中选择目录,最后将选中的目录插入到命令行中。例如Nushell使用command edit来将输出结果 Insert/Replace 到命令行中。

1
2
3
4
5
6
7
8
9
10
{
    name: fuzzy_file
    modifier: control
    keycode: char_t
    mode: [emacs, vi_normal, vi_insert]
    event: {
        send: executehostcommand
        cmd: "commandline edit --insert (fd --type file | fzf --preview 'eza --all --git --long --no-time --color=always --icons {}')"
  }
}

Why Television

可以看到充分使用fuzzy_finder提高效率,不可避免的用到了管道以及编辑命令行的API;这些功能在不同的shell中实现方式不尽相同。

个人为了跨平台的需求一直使用NuShell。在使用fzf时,在github搜到bash/zsh的fzf的集成脚本时,往往需要自己改写成nushell,多少有点麻烦。

tv 内置bash, zsh, fish, nushell等多种 shell的集成;

  • Channel使用toml配置,便于跨shell使用,也方便社区共享
  • UI界面更美观,这个看个人喜好

SetUp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 1. Install
# windows
scoop install television
# macOS
brew install television

# 2. 引入社区的 channels,作用后面会解释
tv update-channels

# 3. 设置 shell 集成
# zsh
echo 'eval "$(tv init zsh)"' >> ~/.zshrc
source ~/.zshrc
# bash
echo 'eval "$(tv init bash)"' >> ~/.bashrc
source ~/.bashrc
Tip

在执行tv init shell命令后,tv会自动检测当前的shell并生成对应的脚本,脚本可以读取toml编写的Channel配置文件,然后执行相应的操作。

应该是通过这种方式屏蔽了不同shell的差异,不过这是我猜的

Channel

Channels are short configuration recipes that typically dictate what tv should search through and what’s displayed on the screen along with various other options.

Channels | Television

tv 引入 Channel 的概念,Channel 可以理解成定义 tv 的搜索范围和显示内容的配置文件,存放在~/.config/television/cable/目录下

前面运行的tv update-channels命令会从社区下载一些常用的 Channel。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/home/user/.config/television
├── config.toml
├── cable
│   ├── alias.toml
│   ├── aws-buckets.toml
│   ├── aws-instances.toml
│   ├── bash-history.toml
│   ├── dirs.toml
│   ├── docker-images.toml
│   ├── dotfiles.toml
│   ├── env.toml
│   ├── files.toml
│   ├── fish-history.toml
│   ├── git-branch.toml
│   ├── git-diff.toml
│   ├── git-log.toml
│   ├── git-reflog.toml
│   ├── git-repos.toml
│   ├── nu-history.toml
│   ├── text.toml
│   └── zsh-history.toml
Warning

部分 Channel 需要安装对应的cli工具才能使用,例如bat, fd

可以在config.toml中添加 Channel 触发器。例如我们希望在输入cd时触发dirs Channel,输入catvim时触发files Channel,可以在config.toml中添加如下内容:

1
2
3
[shell_integration.channel_triggers]
"dirs" = ["cd"]
"files" = ["cat", "vim"]

效果参考下图,输入vim后按Ctrl-T即可触发files Channel,输入cd后按Ctrl-T即可触发dirs Channel。

Outro

更多features可以参考Television,文档的前端界面很有新意,内容也十分详细

作者

GnixAij

发布于

2025-07-24

更新于

2025-07-25

许可协议

评论