From f520f9ff22d514a6f2034cd440b7dc593d43116d Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 27 May 2026 10:28:38 +0200 Subject: [PATCH] Simplify --- bin/omarchy-config-shell | 22 ++++++++-------------- bin/omarchy-install-tailscale | 2 +- test/shell.d/config-test.sh | 15 ++++----------- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/bin/omarchy-config-shell b/bin/omarchy-config-shell index 8de50270..b3297209 100755 --- a/bin/omarchy-config-shell +++ b/bin/omarchy-config-shell @@ -1,8 +1,8 @@ #!/bin/bash # omarchy:summary=Mutate the user shell.json bar layout -# omarchy:args= -# omarchy:examples=omarchy config shell append right omarchy.tailscale +# omarchy:args= +# omarchy:examples=omarchy config shell right omarchy.tailscale set -euo pipefail @@ -11,7 +11,7 @@ OMARCHY_ROOT="${OMARCHY_PATH:-}" DEFAULTS_FILE="$OMARCHY_ROOT/config/omarchy/shell.json" usage() { - echo "Usage: omarchy-config-shell " >&2 + echo "Usage: omarchy-config-shell " >&2 } fail() { @@ -19,16 +19,14 @@ fail() { exit 1 } -operation="${1:-}" -section="${2:-}" -plugin="${3:-}" +section="${1:-}" +plugin="${2:-}" -if (( $# != 3 )); then +if (( $# != 2 )); then usage exit 1 fi -[[ $operation == "append" || $operation == "prepend" ]] || fail "operation must be append or prepend" [[ $section =~ ^(left|center|right)$ ]] || fail "section must be left, center, or right" [[ -n $plugin ]] || fail "plugin is required" [[ -n $OMARCHY_ROOT ]] || fail "OMARCHY_PATH is not set" @@ -44,7 +42,7 @@ fi tmp=$(mktemp) trap 'rm -f "$tmp"' EXIT -jq --arg operation "$operation" --arg section "$section" --arg plugin "$plugin" ' +jq --arg section "$section" --arg plugin "$plugin" ' def object_or_empty: if type == "object" then . else {} end; def array_or_empty: if type == "array" then . else [] end; def entry_id: if type == "object" then (.id // "" | tostring) else tostring end; @@ -70,11 +68,7 @@ jq --arg operation "$operation" --arg section "$section" --arg plugin "$plugin" | .bar.layout.center = (.bar.layout.center | array_or_empty | map(select(entry_id != $plugin))) | .bar.layout.right = (.bar.layout.right | array_or_empty | map(select(entry_id != $plugin))) | .plugins = (.plugins | array_or_empty) - | if $operation == "prepend" then - .bar.layout[$section] = ([{ id: $plugin }] + .bar.layout[$section]) - else - .bar.layout[$section] = insert_after_anchor(.bar.layout[$section]; { id: $plugin }; append_anchor($section)) - end + | .bar.layout[$section] = insert_after_anchor(.bar.layout[$section]; { id: $plugin }; append_anchor($section)) ' "$source_file" >"$tmp" mv "$tmp" "$CONFIG_FILE" diff --git a/bin/omarchy-install-tailscale b/bin/omarchy-install-tailscale index 0f194026..f4595af6 100755 --- a/bin/omarchy-install-tailscale +++ b/bin/omarchy-install-tailscale @@ -14,6 +14,6 @@ echo -e "\nAllowing $USER to manage Tailscale..." sudo tailscale set --operator="$USER" echo -e "\nAdding Tailscale to the bar..." -omarchy-config-shell append right omarchy.tailscale +omarchy-config-shell right omarchy.tailscale omarchy-webapp-install "Tailscale" "https://login.tailscale.com/admin/machines" https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/tailscale-light.png diff --git a/test/shell.d/config-test.sh b/test/shell.d/config-test.sh index 7a8059fb..352f3ff9 100755 --- a/test/shell.d/config-test.sh +++ b/test/shell.d/config-test.sh @@ -109,35 +109,28 @@ cat >"$TMPDIR/home/.config/omarchy/shell.json" <<'JSON' } JSON -HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-config-shell append right omarchy.tailscale +HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-config-shell right omarchy.tailscale jq -e ' def ids: map(.id // .); .bar.layout.right | ids == ["omarchy.tray", "omarchy.tailscale", "omarchy.bluetooth"] ' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null pass "shell config appends right widgets after tray" -HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-config-shell append left local.left +HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-config-shell left local.left jq -e ' def ids: map(.id // .); .bar.layout.left | ids == ["omarchy.menu", "omarchy.workspaces", "local.left"] ' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null pass "shell config appends left widgets after workspaces" -HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-config-shell append center local.center +HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-config-shell center local.center jq -e ' def ids: map(.id // .); .bar.layout.center | ids == ["omarchy.clock", "omarchy.weather", "local.center"] ' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null pass "shell config appends center widgets after weather" -HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-config-shell prepend right local.first -jq -e ' - def ids: map(.id // .); - .bar.layout.right | ids == ["local.first", "omarchy.tray", "omarchy.tailscale", "omarchy.bluetooth"] -' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null -pass "shell config prepends widgets to section start" - -HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-config-shell append right local.first +HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-config-shell right local.first jq -e ' def ids: map(.id // .); .bar.layout.right | ids == ["omarchy.tray", "local.first", "omarchy.tailscale", "omarchy.bluetooth"]