Files
omarchycn/migrations/1785344985.sh
T
David Heinemeier HanssonandClaude Opus 5 39936d2982 Ship the model usage widget in the default bar
The widget hid itself well enough that nobody found it: it only ever
appeared if you knew the id and ran `omarchy bar plugin add`, since it was
in neither the shipped layout nor any migration.

Defaulting it on costs nothing on machines that don't use it. Panel.qml is
`visible: providers.length > 0`, and Main.qml only counts a provider that
is enabled and has actually recorded prompts, sessions, active days, or a
rate limit. A box that has never run Claude Code or Codex draws an empty
bar item, and the icon arrives on its own at the first scan that finds
usage — which is the behavior the widget already advertised.

The migration skips any config that already lists the widget in any
section, so a curated bar keeps its own placement rather than gaining a
second copy.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-29 14:49:55 -04:00

50 lines
1.5 KiB
Bash

echo "Add the model usage widget to the bar"
# The widget is now in the default layout. It draws nothing until a provider
# reports usage — Panel.qml is `visible: providers.length > 0`, and Main.qml
# only counts a provider that is enabled *and* has recorded prompts, sessions,
# active days, or a rate limit. So adding it to every existing bar is free:
# machines without Claude Code or Codex never see it.
config_file="$HOME/.config/omarchy/shell.json"
if [[ -s $config_file ]] && omarchy-cmd-present jq; then
tmp=$(mktemp)
jq '
def entry_id:
if type == "string" then
.
elif type == "object" then
(.id // "")
else
""
end;
def has_widget($id):
[(.bar.layout // {}) | to_entries[] | .value | select(type == "array") | .[] | entry_id]
| any(. == $id);
def insert_after($anchor; $entry):
if type != "array" then
[$entry]
else
([range(0; length) as $i | select((.[$i] | entry_id) == $anchor) | $i][0]) as $anchor_index |
if $anchor_index == null then
[$entry] + .
else
.[0:$anchor_index + 1] + [$entry] + .[$anchor_index + 1:]
end
end;
# Respect a bar the user already curated: only place the widget when it is
# absent from every section, never a second copy.
if has_widget("omarchy.model-usage") then
.
else
.bar.layout.right |= insert_after("omarchy.tray"; { id: "omarchy.model-usage" })
end
' "$config_file" >"$tmp" && mv "$tmp" "$config_file" || rm -f "$tmp"
fi
omarchy-restart-shell