diff options
| author | Tommaso Negri <me@tommasongr.com> | 2026-08-28 11:28:44 +0200 |
|---|---|---|
| committer | Tommaso Negri <me@tommasongr.com> | 2026-08-28 11:28:44 +0200 |
| commit | c1404367ae8d1dadb680c65ac84de9994cfdd469 (patch) | |
| tree | dd1d97d57bd01f8984b8d5fbc6e78312ca0212be | |
| parent | fe5014853363620acdf41f79e6d0eda7544a0fa7 (diff) | |
| download | bar-c1404367ae8d1dadb680c65ac84de9994cfdd469.tar.gz bar-c1404367ae8d1dadb680c65ac84de9994cfdd469.zip | |
add examples for both yabai and aerospace
| -rw-r--r-- | Sources/bar/bar.docc/examples.md | 2 | ||||
| -rw-r--r-- | Sources/bar/bar.docc/examples/example-aerospace.md | 42 | ||||
| -rw-r--r-- | Sources/bar/bar.docc/examples/example-focused-app.md | 72 | ||||
| -rw-r--r-- | Sources/bar/bar.docc/examples/example-kitty.md | 65 | ||||
| -rw-r--r-- | Sources/bar/bar.docc/examples/example-workspaces.md | 83 |
5 files changed, 214 insertions, 50 deletions
diff --git a/Sources/bar/bar.docc/examples.md b/Sources/bar/bar.docc/examples.md index e4e4b2e..7c55ea4 100644 --- a/Sources/bar/bar.docc/examples.md +++ b/Sources/bar/bar.docc/examples.md @@ -4,7 +4,6 @@ A few examples you can use as starting point for your commands. ## Topics -- <doc:example-aerospace> - <doc:example-clock> - <doc:example-cpu> - <doc:example-focused-app> @@ -13,3 +12,4 @@ A few examples you can use as starting point for your commands. - <doc:example-memory> - <doc:example-mpd> - <doc:example-volume> +- <doc:example-workspaces> diff --git a/Sources/bar/bar.docc/examples/example-aerospace.md b/Sources/bar/bar.docc/examples/example-aerospace.md deleted file mode 100644 index 18726eb..0000000 --- a/Sources/bar/bar.docc/examples/example-aerospace.md +++ /dev/null @@ -1,42 +0,0 @@ -# Aerospace - -A script that prints the active Aerospace workspaces. - -```shell -#!/bin/zsh - -# Get all available workspaces -workspaces=() -while IFS= read -r line; do - workspaces+=("$line") -done < <(aerospace list-workspaces --monitor 1) - -# Get all active workspaces (with at least one window). -typeset -A used_workspaces -while IFS= read -r line; do - used_workspaces[$line]=1 -done < <(aerospace list-windows --monitor 1 --format "%{workspace}") - -# Get the current workspace -focused_workspace=$(aerospace list-workspaces --focused) - -for workspace in "${workspaces[@]}"; do - if [[ $workspace == $focused_workspace ]]; then - echo "&!2 $workspace " - elif [[ -n ${used_workspaces[$workspace]} ]]; then - echo "&!1 $workspace " - fi -done -``` - -## Usage - -Instead of relaying on ``Block/interval``, you might want to setup a Aerospace [callback](https://nikitabobko.github.io/AeroSpace/guide#on-focus-changed-callbacks) to update the block in real-time: - -```toml -# ~/.config/aerospace/aerospace.toml - -on-focus-changed = [ - "exec-and-forget notifyutil -p bar.touch.spaces" -] -``` diff --git a/Sources/bar/bar.docc/examples/example-focused-app.md b/Sources/bar/bar.docc/examples/example-focused-app.md index 29a6f18..2090c96 100644 --- a/Sources/bar/bar.docc/examples/example-focused-app.md +++ b/Sources/bar/bar.docc/examples/example-focused-app.md @@ -2,8 +2,72 @@ A script that prints the currently focused app with a custom icon. -> Important: This script uses Aerospace CLI to get the currently focused window. -If you don't use Aerospace, please adapt the script accordingly. +## Using yabai + +```shell +#!/bin/zsh + +# Default to a UTF-8 locale when launched with a minimal environment +# (aerospace/launchd set neither LANG nor LC_*), otherwise zsh rejects +# multibyte chars like the U+200E prefix in WhatsApp's app-name. +: ${LANG:=en_US.UTF-8}; export LANG + +# Icon used when the focused app isn't recognised below +fallback_icon='' + +# Get currently focused app +app=$(yabai -m query --windows | jq -r '.[] | select(."has-focus" == true) | .app') + +# Hide app on an empty workspace +if [[ -z $app ]]; then + echo '' + exit 0 +fi + +# Map each favourite app to its SF Symbol icon, grouped by icon. +typeset -A icons +map() { + local icon=$1; shift + for name in "$@"; do icons[$name]=$icon + done +} + +map Finder Transmit +map kitty Xcode 'SF Symbols' Terminal TablePro RapidAPI +map qutebrowser 'Brave Browser' Safari +map 'Brewer X' 'App Store' +map Messages WhatsApp $'\u200eWhatsApp' # WhatsApp ships a leading U+200E (invisible LRM) +map Whereby FaceTime 'Final Cut Pro' HandBrake Compressor Infuse TV mpv +map BusyCal Calendar +map BusyContacts +map Sketch +map 'Pixelmator Pro' Affinity Aseprite +map Calculator +map Numbers +map Keynote 'iA Presenter' +map Pages 'iA Writer' +map Blender +map Music 'Mp3tag' +map Podcasts +map 'Logic Pro' +map Mail +map Preview + +# Set icon (fallback to $fallback_icon for unknown apps) + label in one call, then show +echo " ${icons[$app]:-$fallback_icon} $app" +``` + +### Usage + +Instead of relaying on ``Block/interval``, you might want to setup a yabai [signal](https://github.com/asmvik/yabai/wiki/Commands#automation-with-rules-and-signals) to update the block in real-time: + +```toml +# ~/.config/yabai/yabairc + +yabai -m signal --add event=window_focused action='notifyutil -p bar.touch.app' +``` + +## Using AeroSpace ```shell #!/bin/zsh @@ -58,9 +122,9 @@ map Preview echo " ${icons[$app]:-$fallback_icon} $app " ``` -## Usage +### Usage -Instead of relaying on ``Block/interval``, you might want to setup a Aerospace [callback](https://nikitabobko.github.io/AeroSpace/guide#on-focus-changed-callbacks) to update the block in real-time: +Instead of relaying on ``Block/interval``, you might want to setup an Aerospace [callback](https://nikitabobko.github.io/AeroSpace/guide#on-focus-changed-callbacks) to update the block in real-time: ```toml # ~/.config/aerospace/aerospace.toml diff --git a/Sources/bar/bar.docc/examples/example-kitty.md b/Sources/bar/bar.docc/examples/example-kitty.md index 2193f25..063068f 100644 --- a/Sources/bar/bar.docc/examples/example-kitty.md +++ b/Sources/bar/bar.docc/examples/example-kitty.md @@ -2,8 +2,67 @@ A script that prints the current Kitty session. -> Important: This script uses Aerospace CLI to get the currently focused window. -If you don't use Aerospace, please adapt the script accordingly. +## Using yabai + +```shell +#!/bin/zsh + +# Get currently focused app +app=$(yabai -m query --windows | jq -r '.[] | select(."has-focus" == true) | .app') + +if [[ $app == kitty ]]; then + # Get current kitty session + socket=$(ls -t /tmp/kitty-* 2>/dev/null | head -1) + [[ -z $socket ]] && exit 0 + session=$(kitty @ --to "unix:$socket" ls | jq -r '.[0].tabs[] | select(.is_active).windows[] | select(.is_active).session_name') + + if [[ -n $session ]]; then + echo " ($session)" + else + exit 0 + fi +else + exit 0 +fi +``` + +### Usage + +Instead of relaying on ``Block/interval``, you might want to setup a Kitty [watcher](https://sw.kovidgoyal.net/kitty/launch/#watchers) to update the block in real-time: + +```python +# ~/.config/kitty/watchers/session_watcher.py + +import subprocess +from typing import Any + +from kitty.boss import Boss +from kitty.window import Window + +def _touch_bar() -> None: + subprocess.Popen( + ["notifyutil", "-p", "bar.touch.session"], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) + +def on_focus_change(boss: Boss, window: Window, data: dict[str, Any]) -> None: + _touch_bar() + +def on_tab_bar_dirty(boss: Boss, window: Window, data: dict[str, Any]) -> None: + _touch_bar() +``` + +Also, you might want to refresh the block on workspace/app change. +You can do that by setting a yabai [signal](https://github.com/asmvik/yabai/wiki/Commands#automation-with-rules-and-signals): + +```toml +# ~/.config/yabai/yabairc + +yabai -m signal --add event=window_focused action='notifyutil -p bar.touch.session' +``` + +## Using AeroSpace ```shell #!/bin/zsh @@ -27,7 +86,7 @@ else fi ``` -## Usage +### Usage Instead of relaying on ``Block/interval``, you might want to setup a Kitty [watcher](https://sw.kovidgoyal.net/kitty/launch/#watchers) to update the block in real-time: diff --git a/Sources/bar/bar.docc/examples/example-workspaces.md b/Sources/bar/bar.docc/examples/example-workspaces.md new file mode 100644 index 0000000..4f9a444 --- /dev/null +++ b/Sources/bar/bar.docc/examples/example-workspaces.md @@ -0,0 +1,83 @@ +# Workspaces + +A script that prints the active workspaces. + +## Using yabai + +```shell +#!/bin/zsh + +# Get all available workspaces +workspaces=() +while IFS= read -r line; do + workspaces+=("$line") +done < <(yabai -m query --spaces | jq '.[] | .index') + +# Get all active workspaces (with at least one window). +typeset -A used_workspaces +while IFS= read -r line; do + used_workspaces[$line]=1 +done < <(yabai -m query --spaces | jq '.[] | select(.windows != []) | .index') + +# Get the current workspace +focused_workspace=$(yabai -m query --spaces | jq '.[] | select(."has-focus" == true) | .index') + +for workspace in "${workspaces[@]}"; do + if [[ $workspace == $focused_workspace ]]; then + echo "&!2 $workspace " + elif [[ -n ${used_workspaces[$workspace]} ]]; then + echo "&!1 $workspace " + fi +done +``` + +### Usage + +Instead of relaying on ``Block/interval``, you might want to setup a yabai [signal](https://github.com/asmvik/yabai/wiki/Commands#automation-with-rules-and-signals) to update the block in real-time: + +```toml +# ~/.config/yabai/yabairc + +yabai -m signal --add event=space_changed action='notifyutil -p bar.touch.spaces' +``` + +## Using AeroSpace + +```shell +#!/bin/zsh + +# Get all available workspaces +workspaces=() +while IFS= read -r line; do + workspaces+=("$line") +done < <(aerospace list-workspaces --monitor 1) + +# Get all active workspaces (with at least one window). +typeset -A used_workspaces +while IFS= read -r line; do + used_workspaces[$line]=1 +done < <(aerospace list-windows --monitor 1 --format "%{workspace}") + +# Get the current workspace +focused_workspace=$(aerospace list-workspaces --focused) + +for workspace in "${workspaces[@]}"; do + if [[ $workspace == $focused_workspace ]]; then + echo "&!2 $workspace " + elif [[ -n ${used_workspaces[$workspace]} ]]; then + echo "&!1 $workspace " + fi +done +``` + +### Usage + +Instead of relaying on ``Block/interval``, you might want to setup an Aerospace [callback](https://nikitabobko.github.io/AeroSpace/guide#on-focus-changed-callbacks) to update the block in real-time: + +```toml +# ~/.config/aerospace/aerospace.toml + +on-focus-changed = [ + "exec-and-forget notifyutil -p bar.touch.spaces" +] +``` |
