Simplify
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# omarchy:summary=Mutate the user shell.json bar layout
|
# omarchy:summary=Mutate the user shell.json bar layout
|
||||||
# omarchy:args=<append|prepend> <left|center|right> <plugin>
|
# omarchy:args=<left|center|right> <plugin>
|
||||||
# omarchy:examples=omarchy config shell append right omarchy.tailscale
|
# omarchy:examples=omarchy config shell right omarchy.tailscale
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ OMARCHY_ROOT="${OMARCHY_PATH:-}"
|
|||||||
DEFAULTS_FILE="$OMARCHY_ROOT/config/omarchy/shell.json"
|
DEFAULTS_FILE="$OMARCHY_ROOT/config/omarchy/shell.json"
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: omarchy-config-shell <append|prepend> <left|center|right> <plugin>" >&2
|
echo "Usage: omarchy-config-shell <left|center|right> <plugin>" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
fail() {
|
fail() {
|
||||||
@@ -19,16 +19,14 @@ fail() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
operation="${1:-}"
|
section="${1:-}"
|
||||||
section="${2:-}"
|
plugin="${2:-}"
|
||||||
plugin="${3:-}"
|
|
||||||
|
|
||||||
if (( $# != 3 )); then
|
if (( $# != 2 )); then
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ $operation == "append" || $operation == "prepend" ]] || fail "operation must be append or prepend"
|
|
||||||
[[ $section =~ ^(left|center|right)$ ]] || fail "section must be left, center, or right"
|
[[ $section =~ ^(left|center|right)$ ]] || fail "section must be left, center, or right"
|
||||||
[[ -n $plugin ]] || fail "plugin is required"
|
[[ -n $plugin ]] || fail "plugin is required"
|
||||||
[[ -n $OMARCHY_ROOT ]] || fail "OMARCHY_PATH is not set"
|
[[ -n $OMARCHY_ROOT ]] || fail "OMARCHY_PATH is not set"
|
||||||
@@ -44,7 +42,7 @@ fi
|
|||||||
tmp=$(mktemp)
|
tmp=$(mktemp)
|
||||||
trap 'rm -f "$tmp"' EXIT
|
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 object_or_empty: if type == "object" then . else {} end;
|
||||||
def array_or_empty: if type == "array" 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;
|
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.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)))
|
| .bar.layout.right = (.bar.layout.right | array_or_empty | map(select(entry_id != $plugin)))
|
||||||
| .plugins = (.plugins | array_or_empty)
|
| .plugins = (.plugins | array_or_empty)
|
||||||
| if $operation == "prepend" then
|
| .bar.layout[$section] = insert_after_anchor(.bar.layout[$section]; { id: $plugin }; append_anchor($section))
|
||||||
.bar.layout[$section] = ([{ id: $plugin }] + .bar.layout[$section])
|
|
||||||
else
|
|
||||||
.bar.layout[$section] = insert_after_anchor(.bar.layout[$section]; { id: $plugin }; append_anchor($section))
|
|
||||||
end
|
|
||||||
' "$source_file" >"$tmp"
|
' "$source_file" >"$tmp"
|
||||||
|
|
||||||
mv "$tmp" "$CONFIG_FILE"
|
mv "$tmp" "$CONFIG_FILE"
|
||||||
|
|||||||
@@ -14,6 +14,6 @@ echo -e "\nAllowing $USER to manage Tailscale..."
|
|||||||
sudo tailscale set --operator="$USER"
|
sudo tailscale set --operator="$USER"
|
||||||
|
|
||||||
echo -e "\nAdding Tailscale to the bar..."
|
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
|
omarchy-webapp-install "Tailscale" "https://login.tailscale.com/admin/machines" https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/tailscale-light.png
|
||||||
|
|||||||
@@ -109,35 +109,28 @@ cat >"$TMPDIR/home/.config/omarchy/shell.json" <<'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 '
|
jq -e '
|
||||||
def ids: map(.id // .);
|
def ids: map(.id // .);
|
||||||
.bar.layout.right | ids == ["omarchy.tray", "omarchy.tailscale", "omarchy.bluetooth"]
|
.bar.layout.right | ids == ["omarchy.tray", "omarchy.tailscale", "omarchy.bluetooth"]
|
||||||
' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null
|
' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null
|
||||||
pass "shell config appends right widgets after tray"
|
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 '
|
jq -e '
|
||||||
def ids: map(.id // .);
|
def ids: map(.id // .);
|
||||||
.bar.layout.left | ids == ["omarchy.menu", "omarchy.workspaces", "local.left"]
|
.bar.layout.left | ids == ["omarchy.menu", "omarchy.workspaces", "local.left"]
|
||||||
' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null
|
' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null
|
||||||
pass "shell config appends left widgets after workspaces"
|
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 '
|
jq -e '
|
||||||
def ids: map(.id // .);
|
def ids: map(.id // .);
|
||||||
.bar.layout.center | ids == ["omarchy.clock", "omarchy.weather", "local.center"]
|
.bar.layout.center | ids == ["omarchy.clock", "omarchy.weather", "local.center"]
|
||||||
' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null
|
' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null
|
||||||
pass "shell config appends center widgets after weather"
|
pass "shell config appends center widgets after weather"
|
||||||
|
|
||||||
HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-config-shell prepend 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 == ["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
|
|
||||||
jq -e '
|
jq -e '
|
||||||
def ids: map(.id // .);
|
def ids: map(.id // .);
|
||||||
.bar.layout.right | ids == ["omarchy.tray", "local.first", "omarchy.tailscale", "omarchy.bluetooth"]
|
.bar.layout.right | ids == ["omarchy.tray", "local.first", "omarchy.tailscale", "omarchy.bluetooth"]
|
||||||
|
|||||||
Reference in New Issue
Block a user