Support positional section when moving bar widgets
This commit is contained in:
+22
-2
@@ -3,7 +3,7 @@
|
||||
# omarchy:summary=Add, move, remove, and configure bar plugin widgets in the layout
|
||||
# omarchy:group=bar
|
||||
# omarchy:args=add <id> [placement] | move <id> [placement] | remove <id> [placement] | set <id> <key> <value> [--json] [placement] | replace <old-id> <new-id>
|
||||
# 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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user