fix(examples): treat the state file as data in the bundled scripts and document $TERMINAL
- commit
- a3516e3fd166e8ad4d3babd007f25f477ca38839
- author
- brice · · 2026-10-05 16:00 UTC
- parent
- 6a789b4
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
5 files · +23 -7
M README.md +10 -1
| @@ -66,7 +66,16 @@ theme = "auto" # the terminal you use | |||
| 66 | 66 | theme = "~/.config/kitty/themes/mytheme.conf" # or one file | |
| 67 | 67 | ``` | |
| 68 | 68 | ||
| 69 | - | `auto` picks the terminal named by `$TERMINAL` (or the first entry of `xdg-terminals.list`), and otherwise the first of kitty, ghostty, foot and alacritty that has a config with colors. A file can be any of those formats, and the bar recognizes it by its content. Includes and `theme =` names are followed. Colors the file does not set come from a built-in dark theme. | |
| 69 | + | `auto` reads the theme of the terminal named by the **`$TERMINAL`** environment variable, and nothing else. It knows kitty, ghostty, foot and alacritty (`TERMINAL=kitty`, or a path such as `/usr/bin/foot`). A theme file can be any of those formats, and the bar recognizes it by its content. Includes and ghostty `theme =` names are followed. Colors the file does not set come from a built-in dark theme. | |
| 70 | + | ||
| 71 | + | **Set `$TERMINAL` for your whole session**, not only in a shell. A variable you `set -x` in an open terminal is not seen by programs your compositor starts. The simplest place is a systemd user environment file, read when a session starts, whatever your shell is: | |
| 72 | + | ||
| 73 | + | ``` | |
| 74 | + | # ~/.config/environment.d/10-terminal.conf | |
| 75 | + | TERMINAL=kitty | |
| 76 | + | ``` | |
| 77 | + | ||
| 78 | + | Then start a new session. If `$TERMINAL` is missing, the bar says so in its log and uses the built-in colors. | |
| 70 | 79 | ||
| 71 | 80 | The bar watches every file it read: change your terminal's theme and the bar changes with it. If the theme cannot be read, the bar uses the built-in colors and says why in its log. | |
| 72 | 81 | ||
| @@ -66,7 +66,16 @@ theme = "auto" # the terminal you use | |||||
| 66 | theme = "~/.config/kitty/themes/mytheme.conf" # or one file | 66 | theme = "~/.config/kitty/themes/mytheme.conf" # or one file | ||
| 67 | ``` | 67 | ``` | ||
| 68 | 68 | ||||
| 69 | - | `auto` picks the terminal named by `$TERMINAL` (or the first entry of `xdg-terminals.list`), and otherwise the first of kitty, ghostty, foot and alacritty that has a config with colors. A file can be any of those formats, and the bar recognizes it by its content. Includes and `theme =` names are followed. Colors the file does not set come from a built-in dark theme. | 69 | + | `auto` reads the theme of the terminal named by the **`$TERMINAL`** environment variable, and nothing else. It knows kitty, ghostty, foot and alacritty (`TERMINAL=kitty`, or a path such as `/usr/bin/foot`). A theme file can be any of those formats, and the bar recognizes it by its content. Includes and ghostty `theme =` names are followed. Colors the file does not set come from a built-in dark theme. |
| 70 | + | ||||
| 71 | + | **Set `$TERMINAL` for your whole session**, not only in a shell. A variable you `set -x` in an open terminal is not seen by programs your compositor starts. The simplest place is a systemd user environment file, read when a session starts, whatever your shell is: | |||
| 72 | + | ||||
| 73 | + | ``` | |||
| 74 | + | # ~/.config/environment.d/10-terminal.conf | |||
| 75 | + | TERMINAL=kitty | |||
| 76 | + | ``` | |||
| 77 | + | ||||
| 78 | + | Then start a new session. If `$TERMINAL` is missing, the bar says so in its log and uses the built-in colors. | |||
| 70 | 79 | ||||
| 71 | The bar watches every file it read: change your terminal's theme and the bar changes with it. If the theme cannot be read, the bar uses the built-in colors and says why in its log. | 80 | The bar watches every file it read: change your terminal's theme and the bar changes with it. If the theme cannot be read, the bar uses the built-in colors and says why in its log. | ||
| 72 | 81 | ||||
M examples/bundle/center.sh +3 -1
| @@ -10,7 +10,9 @@ | |||
| 10 | 10 | ||
| 11 | 11 | draw() { | |
| 12 | 12 | local app | |
| 13 | - | app=$(jq -r '.window.app_id // empty' "$NEFERWL_STATE" 2>/dev/null) || return | |
| 13 | + | # An app id is chosen by the application: drop control characters, which | |
| 14 | + | # would otherwise reach the bar as escape sequences. | |
| 15 | + | app=$(jq -r '(.window.app_id // empty) | explode | map(select(. >= 32 and . != 127)) | implode' "$NEFERWL_STATE" 2>/dev/null) || return | |
| 14 | 16 | if [ -n "$app" ]; then | |
| 15 | 17 | printf '%s%s%s %s%s%s\f' "$(bg "$BAR")" "$(fg "$NEFERBAR_COLOR3")" "$ICON_APP" "$(fg "$NEFERBAR_FOREGROUND")" "$app" "$RESET" | |
| 16 | 18 | else | |
| @@ -10,7 +10,9 @@ | |||||
| 10 | 10 | ||||
| 11 | draw() { | 11 | draw() { | ||
| 12 | local app | 12 | local app | ||
| 13 | - | app=$(jq -r '.window.app_id // empty' "$NEFERWL_STATE" 2>/dev/null) || return | 13 | + | # An app id is chosen by the application: drop control characters, which |
| 14 | + | # would otherwise reach the bar as escape sequences. | |||
| 15 | + | app=$(jq -r '(.window.app_id // empty) | explode | map(select(. >= 32 and . != 127)) | implode' "$NEFERWL_STATE" 2>/dev/null) || return | |||
| 14 | if [ -n "$app" ]; then | 16 | if [ -n "$app" ]; then | ||
| 15 | printf '%s%s%s %s%s%s\f' "$(bg "$BAR")" "$(fg "$NEFERBAR_COLOR3")" "$ICON_APP" "$(fg "$NEFERBAR_FOREGROUND")" "$app" "$RESET" | 17 | printf '%s%s%s %s%s%s\f' "$(bg "$BAR")" "$(fg "$NEFERBAR_COLOR3")" "$ICON_APP" "$(fg "$NEFERBAR_FOREGROUND")" "$app" "$RESET" | ||
| 16 | else | 18 | else | ||
M examples/bundle/config.toml +1 -1
| @@ -9,7 +9,7 @@ | |||
| 9 | 9 | [bar] | |
| 10 | 10 | font = "JetBrainsMono Nerd Font Mono" # any "Mono" Nerd Font | |
| 11 | 11 | size = 14 | |
| 12 | - | theme = "auto" # the colors of your terminal, or the path of a theme file | |
| 12 | + | theme = "auto" # the colors of the terminal in $TERMINAL, or the path of a theme file | |
| 13 | 13 | ||
| 14 | 14 | [[module]] | |
| 15 | 15 | name = "workspaces" | |
| @@ -9,7 +9,7 @@ | |||||
| 9 | [bar] | 9 | [bar] | ||
| 10 | font = "JetBrainsMono Nerd Font Mono" # any "Mono" Nerd Font | 10 | font = "JetBrainsMono Nerd Font Mono" # any "Mono" Nerd Font | ||
| 11 | size = 14 | 11 | size = 14 | ||
| 12 | - | theme = "auto" # the colors of your terminal, or the path of a theme file | 12 | + | theme = "auto" # the colors of the terminal in $TERMINAL, or the path of a theme file |
| 13 | 13 | ||||
| 14 | [[module]] | 14 | [[module]] | ||
| 15 | name = "workspaces" | 15 | name = "workspaces" | ||
M examples/bundle/left.sh +4 -1
| @@ -24,10 +24,13 @@ draw() { | |||
| 24 | 24 | | "\($n) \($here | length) \([$here[] | select(.stash_count > 0)] | length)")' \ | |
| 25 | 25 | "$NEFERWL_STATE" 2>/dev/null) || return | |
| 26 | 26 | read -r active count <<<"$(head -1 <<<"$data")" | |
| 27 | - | [ -n "$active" ] || return | |
| 27 | + | # The state file is data, not code: bash arithmetic runs command | |
| 28 | + | # substitutions, so only digits may reach it. | |
| 29 | + | [[ $active =~ ^[0-9]+$ && $count =~ ^[0-9]+$ ]] || return | |
| 28 | 30 | ||
| 29 | 31 | line="$(bg "$ACCENT")$(fg "$(ink "$ACCENT")")$BOLD $active $RESET$(fade "$ACCENT" "$BAR")$(bg "$BAR")" | |
| 30 | 32 | while read -r n w s; do | |
| 33 | + | [[ $n =~ ^[0-9]+$ && $w =~ ^[0-9]+$ && $s =~ ^[0-9]+$ ]] || continue | |
| 31 | 34 | pips="" | |
| 32 | 35 | ((w > 0)) && printf -v pips "$DOT%.0s" $(seq 1 $((w > 4 ? 4 : w))) | |
| 33 | 36 | if ((n == active)); then | |
| @@ -24,10 +24,13 @@ draw() { | |||||
| 24 | | "\($n) \($here | length) \([$here[] | select(.stash_count > 0)] | length)")' \ | 24 | | "\($n) \($here | length) \([$here[] | select(.stash_count > 0)] | length)")' \ | ||
| 25 | "$NEFERWL_STATE" 2>/dev/null) || return | 25 | "$NEFERWL_STATE" 2>/dev/null) || return | ||
| 26 | read -r active count <<<"$(head -1 <<<"$data")" | 26 | read -r active count <<<"$(head -1 <<<"$data")" | ||
| 27 | - | [ -n "$active" ] || return | 27 | + | # The state file is data, not code: bash arithmetic runs command |
| 28 | + | # substitutions, so only digits may reach it. | |||
| 29 | + | [[ $active =~ ^[0-9]+$ && $count =~ ^[0-9]+$ ]] || return | |||
| 28 | 30 | ||||
| 29 | line="$(bg "$ACCENT")$(fg "$(ink "$ACCENT")")$BOLD $active $RESET$(fade "$ACCENT" "$BAR")$(bg "$BAR")" | 31 | line="$(bg "$ACCENT")$(fg "$(ink "$ACCENT")")$BOLD $active $RESET$(fade "$ACCENT" "$BAR")$(bg "$BAR")" | ||
| 30 | while read -r n w s; do | 32 | while read -r n w s; do | ||
| 33 | + | [[ $n =~ ^[0-9]+$ && $w =~ ^[0-9]+$ && $s =~ ^[0-9]+$ ]] || continue | |||
| 31 | pips="" | 34 | pips="" | ||
| 32 | ((w > 0)) && printf -v pips "$DOT%.0s" $(seq 1 $((w > 4 ? 4 : w))) | 35 | ((w > 0)) && printf -v pips "$DOT%.0s" $(seq 1 $((w > 4 ? 4 : w))) | ||
| 33 | if ((n == active)); then | 36 | if ((n == active)); then | ||
M examples/bundle/right.sh +5 -3
| @@ -3,8 +3,10 @@ | |||
| 3 | 3 | . "$(dirname "$0")/lib.sh" | |
| 4 | 4 | ||
| 5 | 5 | while true; do | |
| 6 | + | # One reading of the clock, for the text and for the sleep, so they cannot | |
| 7 | + | # straddle a minute boundary. | |
| 8 | + | printf -v now '%(%s)T' -1 | |
| 6 | 9 | printf '%s%s%s%s%s %(%H:%M)T %s\f' \ | |
| 7 | - | "$(fade "$BAR" "$ACCENT")" "$(bg "$ACCENT")" "$(fg "$(ink "$ACCENT")")" "$BOLD" "$ICON_CLOCK" -1 "$RESET" | |
| 8 | - | # Sleep until the next minute starts. | |
| 9 | - | sleep $((60 - 10#$(date +%S))) | |
| 10 | + | "$(fade "$BAR" "$ACCENT")" "$(bg "$ACCENT")" "$(fg "$(ink "$ACCENT")")" "$BOLD" "$ICON_CLOCK" "$now" "$RESET" | |
| 11 | + | sleep $((60 - now % 60)) | |
| 10 | 12 | done | |
| @@ -3,8 +3,10 @@ | |||||
| 3 | . "$(dirname "$0")/lib.sh" | 3 | . "$(dirname "$0")/lib.sh" | ||
| 4 | 4 | ||||
| 5 | while true; do | 5 | while true; do | ||
| 6 | + | # One reading of the clock, for the text and for the sleep, so they cannot | |||
| 7 | + | # straddle a minute boundary. | |||
| 8 | + | printf -v now '%(%s)T' -1 | |||
| 6 | printf '%s%s%s%s%s %(%H:%M)T %s\f' \ | 9 | printf '%s%s%s%s%s %(%H:%M)T %s\f' \ | ||
| 7 | - | "$(fade "$BAR" "$ACCENT")" "$(bg "$ACCENT")" "$(fg "$(ink "$ACCENT")")" "$BOLD" "$ICON_CLOCK" -1 "$RESET" | 10 | + | "$(fade "$BAR" "$ACCENT")" "$(bg "$ACCENT")" "$(fg "$(ink "$ACCENT")")" "$BOLD" "$ICON_CLOCK" "$now" "$RESET" |
| 8 | - | # Sleep until the next minute starts. | 11 | + | sleep $((60 - now % 60)) |
| 9 | - | sleep $((60 - 10#$(date +%S))) | |||
| 10 | done | 12 | done | ||