{"id":13563370,"url":"https://github.com/zsh-users/zsh-apple-touchbar","last_synced_at":"2025-04-06T21:15:15.806Z","repository":{"id":41142757,"uuid":"129488601","full_name":"zsh-users/zsh-apple-touchbar","owner":"zsh-users","description":"Make your touchbar more powerful.","archived":false,"fork":false,"pushed_at":"2023-03-27T19:16:39.000Z","size":1301,"stargazers_count":351,"open_issues_count":3,"forks_count":21,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-30T19:08:40.043Z","etag":null,"topics":["apple","iterm2","macbook-pro","on-my-zsh","touchbar","touchbar-support","zsh","zsh-apple-touchbar","zsh-custom","zsh-plugin"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zsh-users.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-04-14T06:28:46.000Z","updated_at":"2025-03-11T11:38:11.000Z","dependencies_parsed_at":"2024-04-12T23:00:36.299Z","dependency_job_id":null,"html_url":"https://github.com/zsh-users/zsh-apple-touchbar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zsh-users%2Fzsh-apple-touchbar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zsh-users%2Fzsh-apple-touchbar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zsh-users%2Fzsh-apple-touchbar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zsh-users%2Fzsh-apple-touchbar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zsh-users","download_url":"https://codeload.github.com/zsh-users/zsh-apple-touchbar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247550690,"owners_count":20956987,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apple","iterm2","macbook-pro","on-my-zsh","touchbar","touchbar-support","zsh","zsh-apple-touchbar","zsh-custom","zsh-plugin"],"created_at":"2024-08-01T13:01:18.534Z","updated_at":"2025-04-06T21:15:15.786Z","avatar_url":"https://github.com/zsh-users.png","language":"Ruby","funding_links":[],"categories":["Plugins","Ruby"],"sub_categories":["ZSH on Windows","Zinit (née zplugin)"],"readme":"# zsh-apple-touchbar\n\nMake your touchbar more powerful.\n\n![preview](./preview.gif)\n\n## Requirements\n\n* iTerm2 3.1 or later\n* zsh\n* ruby 2.3.4 or later (only if you want automatic generation)\n\n**In iterm2:** Go to `View -\u003e Customize Tool Bar...` and drag \u0026 drop the `Fn` module\n\n## Installation\n\n### Manual\n\n1. Clone this repository somewhere on your machine. This guide will assume `~/.zsh/zsh-apple-touchbar`.\n\n```sh\ngit clone https://github.com/zsh-users/zsh-apple-touchbar ~/.zsh/zsh-apple-touchbar\n```\n\n2. Add the following to your `.zshrc`:\n\n```sh\nsource ~/.zsh/zsh-apple-touchbar/zsh-apple-touchbar.zsh\n```\n\n3. Start a new terminal session.\n\n\n### Oh My Zsh\n\n1. Clone this repository into `$ZSH_CUSTOM/plugins` (by default `~/.oh-my-zsh/custom/plugins`)\n\n```sh\ngit clone https://github.com/zsh-users/zsh-apple-touchbar $ZSH_CUSTOM/plugins/zsh-apple-touchbar\n```\n\n2. Add the plugin to the list of plugins for Oh My Zsh to load:\n\n```sh\nplugins=(zsh-apple-touchbar)\n```\n\n3. Start a new terminal session.\n\n## Customization\n\n### Automatic\n\nYou can define simple commands for FN keys in `config.yml` file. \n\n#### Structure\n\nFile should have two base keys:\n1. `default_view` - default view to show.\n2. `views` - list of defined views.\n\n`views` section contains views you want to show. **Key is a view name.**\n\nUnder view name key you should define next keys:\n1. `text` -  text that will show on touchbar key.\n2. `command` or `view` - `command` means executing some command that under is this key and `view` means show view that is under this key\n3. `back` - under this key should be a view name that will be shown after executing some command.\n\n#### Example\n\n```yml\ndefault_view: first\nviews:\n  first:\n    1:\n      text: 👉 pwd\n      command: pwd |tr -d \"\\\\n\" |pbcopy\n    2:\n      text: second view\n      view: second\n    3:\n      text: third view\n      view: third\n  second:\n    1:\n      text: 👈 back\n      view: first\n    2:\n      text: current path\n      command: pwd\n    back: first\n  third:\n    1:\n      text: 👈 back\n      view: first\n    2:\n      text: ls\n      command: ls -la\n```\n\nFor generating view from `config.yml` file go to its folder:\n\n```sh\ncd $ZSH_CUSTOM/plugins/zsh-apple-touchbar\n```\n\nand run `generate.rb` file:\n\n```sh\nruby generate.rb\n```\n\n### Custom\nIf you need more complicated logic you can rewrite `zsh-apple-touchbar.zsh` file on your own.\n\n#### View functions\nFor each `view` you need to define separate function that will contain keys creation. E.G.\n\n```bash\nfunction first_view() {\n  remove_and_unbind_keys\n\n  set_state 'first'\n\n  create_key 1 '👉 pwd' 'pwd |tr -d \"\\\\n\" |pbcopy' '-s'\n  create_key 2 'second view' 'second_view'\n}\n\nfunction second_view() {\n  remove_and_unbind_keys\n\n  set_state 'second'\n\n  create_key 1 '👈 back' 'first_view'\n  create_key 2 'current path' 'pwd' '-s'\n\n  set_state 'first'\n}\n```\n\nIn every function first, you need to remove and unbind old keys with `remove_and_unbind_keys` function.\n\nThen you need to set a state (`state` variable define which view to show after reinitialization) with `set_state` function.\n\nAfter that, you can create keys for this view with `create_key` function.\n\nAnd after keys part you can set new state (if you want to show some view after executing key command).\n\n#### Keys creation\nKeys creates with `create_key` function\n\nThis function accept 4 arguments:\n1. number of key (from 1 to 12)\n2. key text\n3. `command` or `view`\n4. bind option (`-s` if third argument isn't a view, nothing if it is)\n\n#### Init widgets\nFor calling views in main function you need to init widgets for every view function.\n\n```bash\nzle -N first\nzle -N second\n```\n\n#### Main function\nHere you need to define which view to show for every state.\n\n```bash\nprecmd_apple_touchbar() {\n  case $state in\n    first) first_view ;;\n    second) second_view ;;\n  esac\n}\n```\n\n#### Full example\n```bash\nsource ${0:A:h}/functions.zsh\n\nset_state 'first'\n\nfunction first_view() {\n  remove_and_unbind_keys\n\n  set_state 'first'\n\n  create_key 1 '👉 pwd' 'pwd |tr -d \"\\\\n\" |pbcopy' '-s'\n  create_key 2 'second view' 'second_view'\n}\n\nfunction second_view() {\n  remove_and_unbind_keys\n\n  set_state 'second'\n\n  create_key 1 '👈 back' 'first_view'\n  create_key 2 'current path' 'pwd' '-s'\n\n  set_state 'first'\n}\n\nzle -N first_view\nzle -N second_view\n\nprecmd_apple_touchbar() {\n  case $state in\n    first) first_view ;;\n    second) second_view ;;\n  esac\n}\n\nautoload -Uz add-zsh-hook\n\nadd-zsh-hook precmd precmd_apple_touchbar\n```\n\n## Contributing\n\nIf you have some proposals how to improve this boilerplate feel free to open issues and send pull requests!\n\n1. Fork it\n2. Create your feature branch (git checkout -b my-new-feature)\n3. Commit your changes (git commit -am 'Add some feature')\n4. Push to the branch (git push origin my-new-feature)\n5. Create new Pull Request\n\n## License\n\nAvailable as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzsh-users%2Fzsh-apple-touchbar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzsh-users%2Fzsh-apple-touchbar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzsh-users%2Fzsh-apple-touchbar/lists"}