From 57923f03783a8477a8fc4861a660d2f2678e25ea Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 25 Jul 2026 11:13:35 -0700 Subject: [PATCH] Support positional section when moving bar widgets --- bin/omarchy-bar-plugin | 24 ++++++++++++++++++++++-- test/shell.d/config-test.sh | 21 +++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/bin/omarchy-bar-plugin b/bin/omarchy-bar-plugin index 9e0d829c..c7442f10 100755 --- a/bin/omarchy-bar-plugin +++ b/bin/omarchy-bar-plugin @@ -3,7 +3,7 @@ # omarchy:summary=Add, move, remove, and configure bar plugin widgets in the layout # omarchy:group=bar # omarchy:args=add [placement] | move [placement] | remove [placement] | set [--json] [placement] | replace -# omarchy:examples=omarchy bar plugin add omarchy.tailscale | omarchy bar plugin add omarchy.clock --section center --before omarchy.weather | omarchy bar plugin move omarchy.clock --section center --index 0 | omarchy bar plugin remove omarchy.tailscale | omarchy bar plugin set omarchy.clock format HH:mm +# omarchy:examples=omarchy bar plugin add omarchy.tailscale | omarchy bar plugin add omarchy.clock center | omarchy bar plugin move omarchy.media left | omarchy bar plugin move omarchy.clock --section center --index 0 | omarchy bar plugin remove omarchy.tailscale | omarchy bar plugin set omarchy.clock format HH:mm set -euo pipefail @@ -41,7 +41,8 @@ Widget ids are listed by 'omarchy plugin list'. Examples: omarchy bar plugin add omarchy.tailscale - omarchy bar plugin add omarchy.clock --section center --before omarchy.weather + omarchy bar plugin add omarchy.clock center + omarchy bar plugin move omarchy.media left omarchy bar plugin move omarchy.clock --section center --index 0 omarchy bar plugin remove omarchy.tailscale omarchy bar plugin remove omarchy.tailscale --all @@ -265,7 +266,26 @@ cmd_move() { local id="${1:-}" [[ -n $id ]] || fail "move requires a widget id" shift + + local positional_section="" + while (( $# > 0 )); do + if [[ $1 == --* ]]; then + break + fi + [[ -z $positional_section ]] || fail "unexpected argument: $1" + positional_section="$1" + shift + done + parse_placement "$@" + [[ -z $positional_section || -z $PLACEMENT_SECTION ]] || fail "specify a section positionally or with --section, not both" + [[ -z $positional_section || -z $PLACEMENT_INDEX ]] || fail "specify a section positionally or use --index, not both" + [[ -z $positional_section || -z $PLACEMENT_BEFORE ]] || fail "specify a section positionally or use --before, not both" + [[ -z $positional_section || -z $PLACEMENT_AFTER ]] || fail "specify a section positionally or use --after, not both" + if [[ -n $positional_section ]]; then + validate_section "$positional_section" + PLACEMENT_SECTION="$positional_section" + fi local default_section="${PLACEMENT_SECTION:-}" local prog diff --git a/test/shell.d/config-test.sh b/test/shell.d/config-test.sh index 773d5d2d..8a9f0471 100755 --- a/test/shell.d/config-test.sh +++ b/test/shell.d/config-test.sh @@ -249,6 +249,27 @@ jq -e ' ' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null pass "shell config moves existing widgets without duplicates" +HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-bar-plugin move omarchy.active-window right +jq -e ' + def ids: map(.id // .); + (.bar.layout.left | ids == ["omarchy.menu", "omarchy.workspaces"]) and + (.bar.layout.right | ids == ["omarchy.tray", "omarchy.active-window", "omarchy.microphone", "omarchy.tailscale", "omarchy.bluetooth"]) +' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null +pass "bar plugin move accepts a positional target section" + +HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-bar-plugin move omarchy.active-window left +jq -e ' + def ids: map(.id // .); + (.bar.layout.left | ids == ["omarchy.menu", "omarchy.workspaces", "omarchy.active-window"]) and + (.bar.layout.right | ids == ["omarchy.tray", "omarchy.microphone", "omarchy.tailscale", "omarchy.bluetooth"]) +' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null +pass "bar plugin move can restore a widget with positional syntax" + +if HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-bar-plugin move omarchy.active-window left --section right 2>/dev/null; then + fail "bar plugin move accepted positional and flagged target sections" +fi +pass "bar plugin move rejects conflicting target section syntax" + if HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-bar-plugin add local.nonexistent-widget 2>/dev/null; then fail "bar plugin add accepted an unknown widget" fi