|
| 1 | +echo "Remove the tmux alert hooks and its bar indicator" |
| 2 | + |
| 3 | +tmux_config="$HOME/.config/tmux/tmux.conf" |
| 4 | + |
| 5 | +# Drop only the hooks Omarchy installed, wherever the migrations that wrote |
| 6 | +# them left them, and only the blank run around what goes: every other line |
| 7 | +# comes through untouched. |
| 8 | +if [[ -f $tmux_config ]]; then |
| 9 | + tmp=$(mktemp) |
| 10 | + |
| 11 | + if awk ' |
| 12 | + function flush(count, i) { for (i = 0; i < count; i++) print "" } |
| 13 | +
|
| 14 | + function keep(line) { |
| 15 | + if (dropped) { if (printed && blanks) print "" } |
| 16 | + else flush(blanks) |
| 17 | +
|
| 18 | + blanks = 0 |
| 19 | + dropped = 0 |
| 20 | + printed = 1 |
| 21 | + print line |
| 22 | + } |
| 23 | +
|
| 24 | + # The heading only belongs to the block when a removed hook follows it. |
| 25 | + /^[[:space:]]*# Alerts$/ && header == "" { header = $0; next } |
| 26 | +
|
| 27 | + /^[[:space:]]*set-hook -g alert-(bell|activity|silence) .*omarchy\.indicators refresh/ || |
| 28 | + /^[[:space:]]*set-hook -g (after-select-window|client-session-changed|client-focus-(in|out))(\[[0-9]+\])? .*(omarchy-tmux-alert track|omarchy\.indicators refresh)/ { |
| 29 | + header = "" |
| 30 | + dropped = 1 |
| 31 | + next |
| 32 | + } |
| 33 | +
|
| 34 | + /^[[:space:]]*$/ { |
| 35 | + if (header != "") { keep(header); header = "" } |
| 36 | + blanks++ |
| 37 | + next |
| 38 | + } |
| 39 | +
|
| 40 | + { |
| 41 | + if (header != "") { keep(header); header = "" } |
| 42 | + keep($0) |
| 43 | + } |
| 44 | +
|
| 45 | + END { |
| 46 | + if (header != "") keep(header) |
| 47 | + if (!dropped) flush(blanks) |
| 48 | + } |
| 49 | + ' "$tmux_config" >"$tmp"; then |
| 50 | + if ! cmp -s "$tmp" "$tmux_config"; then |
| 51 | + # Write through the path instead of replacing it, so a tmux.conf |
| 52 | + # symlinked out of a dotfiles repo keeps pointing where it pointed. |
| 53 | + cat "$tmp" >"$tmux_config" |
| 54 | + omarchy-restart-tmux |
| 55 | + fi |
| 56 | + else |
| 57 | + echo "Could not rewrite $tmux_config; remove the tmux alert hooks by hand." |
| 58 | + fi |
| 59 | + |
| 60 | + rm -f "$tmp" |
| 61 | +fi |
| 62 | + |
| 63 | +# A running server keeps its hooks as options, so sourcing a config that no |
| 64 | +# longer sets them leaves every one of them firing at the deleted command. |
| 65 | +# Unset by the exact name and index tmux reports, which leaves hooks the user |
| 66 | +# added at other indexes alone. |
| 67 | +if tmux has-session 2>/dev/null; then |
| 68 | + while read -r hook; do |
| 69 | + [[ -n $hook ]] || continue |
| 70 | + tmux set-hook -gu "$hook" 2>/dev/null || true |
| 71 | + done < <(tmux show-hooks -g 2>/dev/null | |
| 72 | + awk '$0 ~ /omarchy-tmux-alert|omarchy\.indicators refresh/ { print $1 }') |
| 73 | + |
| 74 | + # The removed track subcommand stamped this on every window it saw. |
| 75 | + while read -r window; do |
| 76 | + [[ -n $window ]] || continue |
| 77 | + tmux set-option -wqu -t "$window" @omarchy_unfocused_activity 2>/dev/null || true |
| 78 | + done < <(tmux list-windows -a -F '#{window_id}' 2>/dev/null) |
| 79 | +fi |
| 80 | + |
| 81 | +# Only a hand-picked indicator list names TmuxAlert; the default list lives in |
| 82 | +# the widget. An emptied list would read as "show them all", so a widget that |
| 83 | +# has nothing left to show goes with it. |
| 84 | +config_file="$HOME/.config/omarchy/shell.json" |
| 85 | + |
| 86 | +if [[ -s $config_file ]] && grep -q 'TmuxAlert' "$config_file"; then |
| 87 | + tmp=$(mktemp) |
| 88 | + |
| 89 | + if jq ' |
| 90 | + def entry_id: |
| 91 | + if type == "string" then . elif type == "object" then (.id // "") else "" end; |
| 92 | +
|
| 93 | + def without_tmux_alert: map(select(entry_id != "TmuxAlert")); |
| 94 | +
|
| 95 | + def stripped($key): |
| 96 | + if (.[$key] | type) == "array" then .[$key] |= without_tmux_alert else . end; |
| 97 | +
|
| 98 | + # The list the widget actually reads: "indicators" is the older spelling of |
| 99 | + # "items", and either one empty means "show the default set". |
| 100 | + def picked: |
| 101 | + if (.items | type) == "array" and (.items | length) > 0 then .items |
| 102 | + elif (.indicators | type) == "array" and (.indicators | length) > 0 then .indicators |
| 103 | + else null end; |
| 104 | +
|
| 105 | + def cleaned: |
| 106 | + if type == "object" and .id == "omarchy.indicators" then stripped("items") | stripped("indicators") else . end; |
| 107 | +
|
| 108 | + def emptied: |
| 109 | + type == "object" and .id == "omarchy.indicators" and |
| 110 | + picked != null and (cleaned | picked) == null; |
| 111 | +
|
| 112 | + walk(if type == "array" then map(select(emptied | not)) | map(cleaned) else . end) |
| 113 | + ' "$config_file" >"$tmp"; then |
| 114 | + cat "$tmp" >"$config_file" |
| 115 | + else |
| 116 | + echo "Could not rewrite $config_file; remove the TmuxAlert indicator by hand." |
| 117 | + fi |
| 118 | + |
| 119 | + rm -f "$tmp" |
| 120 | +fi |
| 121 | + |
| 122 | +# Nothing to restart from a TTY or over ssh, and that is no reason to stop the |
| 123 | +# rest of the queue: hand it to the post-update restart instead. |
| 124 | +omarchy-restart-shell >/dev/null 2>&1 || omarchy-state set restart-shell-required |
0 commit comments