百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
Z

zsh-apple-touchbar

> 编程语言
开源

让您的触控条更强大。

352 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

让您的触控条更强大。

zsh-apple-touchbar

Make your touchbar more powerful.

Requirements

  • iTerm2 3.1 or later
  • zsh
  • ruby 2.3.4 or later (only if you want automatic generation)

In iterm2: Go to View -> Customize Tool Bar... and drag & drop the Fn module

Installation

Manual

  1. Clone this repository somewhere on your machine. This guide will assume ~/.zsh/zsh-apple-touchbar.
bash
git clone https://github.com/zsh-users/zsh-apple-touchbar ~/.zsh/zsh-apple-touchbar
  1. Add the following to your .zshrc:
bash
source ~/.zsh/zsh-apple-touchbar/zsh-apple-touchbar.zsh
  1. Start a new terminal session.

Oh My Zsh

  1. Clone this repository into $ZSH_CUSTOM/plugins (by default ~/.oh-my-zsh/custom/plugins)
bash
git clone https://github.com/zsh-users/zsh-apple-touchbar $ZSH_CUSTOM/plugins/zsh-apple-touchbar
  1. Add the plugin to the list of plugins for Oh My Zsh to load:
bash
plugins=(zsh-apple-touchbar)
  1. Start a new terminal session.

Customization

Automatic

You can define simple commands for FN keys in config.yml file.

Structure

File should have two base keys:

  1. default_view - default view to show.
  2. views - list of defined views.

views section contains views you want to show. Key is a view name.

Under view name key you should define next keys:

  1. text - text that will show on touchbar key.
  2. command or view - command means executing some command that under is this key and view means show view that is under this key
  3. back - under this key should be a view name that will be shown after executing some command.

Example

yaml
default_view: first
views:
  first:
    1:
      text:  pwd
      command: pwd |tr -d "\\n" |pbcopy
    2:
      text: second view
      view: second
    3:
      text: third view
      view: third
  second:
    1:
      text:  back
      view: first
    2:
      text: current path
      command: pwd
    back: first
  third:
    1:
      text:  back
      view: first
    2:
      text: ls
      command: ls -la

For generating view from config.yml file go to its folder:

bash
cd $ZSH_CUSTOM/plugins/zsh-apple-touchbar

and run generate.rb file:

bash
ruby generate.rb

Custom

If you need more complicated logic you can rewrite zsh-apple-touchbar.zsh file on your own.

View functions

For each view you need to define separate function that will contain keys creation. E.G.

bash
function first_view() {
  remove_and_unbind_keys

  set_state 'first'

  create_key 1 ' pwd' 'pwd |tr -d "\\n" |pbcopy' '-s'
  create_key 2 'second view' 'second_view'
}

function second_view() {
  remove_and_unbind_keys

  set_state 'second'

  create_key 1 ' back' 'first_view'
  create_key 2 'current path' 'pwd' '-s'

  set_state 'first'
}

In every function first, you need to remove and unbind old keys with remove_and_unbind_keys function.

Then you need to set a state (state variable define which view to show after reinitialization) with set_state function.

After that, you can create keys for this view with create_key function.

And after keys part you can set new state (if you want to show some view after executing key command).

Keys creation

Keys creates with create_key function

This function accept 4 arguments:

  1. number of key (from 1 to 12)
  2. key text
  3. command or view
  4. bind option (-s if third argument isn't a view, nothing if it is)

Init widgets

For calling views in main function you need to init widgets for every view function.

bash
zle -N first
zle -N second

Main function

Here you need to define which view to show for every state.

bash
precmd_apple_touchbar() {
  case $state in
    first) first_view ;;
    second) second_view ;;
  esac
}

Full example

…

Contributing

If you have some proposals how to improve this boilerplate feel free to open issues and send pull requests!

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

Available as open source under the terms of the MIT License.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubyappleiterm2macbook-proon-my-zsh

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言