Simplify
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# omarchy:summary=Mutate the user shell.json bar layout
|
||||
# omarchy:args=<append|prepend> <left|center|right> <plugin>
|
||||
# omarchy:examples=omarchy config shell append right omarchy.tailscale
|
||||
# omarchy:args=<left|center|right> <plugin>
|
||||
# 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 <append|prepend> <left|center|right> <plugin>" >&2
|
||||
echo "Usage: omarchy-config-shell <left|center|right> <plugin>" >&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"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user