mirror of
https://github.com/arthur-pbty/arthur-os.git
synced 2026-08-06 04:29:34 +02:00
77 lines
2.3 KiB
Bash
Executable File
77 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# omarchy:summary=Mutate the user shell.json bar layout
|
|
# omarchy:args=<left|center|right> <plugin>
|
|
# omarchy:examples=omarchy config shell right omarchy.tailscale
|
|
|
|
set -euo pipefail
|
|
|
|
CONFIG_FILE="$HOME/.config/omarchy/shell.json"
|
|
OMARCHY_ROOT="${OMARCHY_PATH:-}"
|
|
DEFAULTS_FILE="$OMARCHY_ROOT/config/omarchy/shell.json"
|
|
|
|
usage() {
|
|
echo "Usage: omarchy-config-shell <left|center|right> <plugin>" >&2
|
|
}
|
|
|
|
fail() {
|
|
echo "omarchy-config-shell: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
section="${1:-}"
|
|
plugin="${2:-}"
|
|
|
|
if (( $# != 2 )); then
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
[[ $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"
|
|
|
|
mkdir -p "$(dirname "$CONFIG_FILE")"
|
|
|
|
source_file="$CONFIG_FILE"
|
|
if [[ ! -s $source_file ]]; then
|
|
source_file="$DEFAULTS_FILE"
|
|
fi
|
|
[[ -s $source_file ]] || fail "could not find shell config or defaults"
|
|
|
|
tmp=$(mktemp)
|
|
trap 'rm -f "$tmp"' EXIT
|
|
|
|
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;
|
|
def append_anchor($section):
|
|
{
|
|
left: "omarchy.workspaces",
|
|
center: "omarchy.weather",
|
|
right: "omarchy.tray"
|
|
}[$section];
|
|
def insert_after_anchor($entries; $entry; $anchor):
|
|
($entries | map(entry_id) | index($anchor)) as $index
|
|
| if $index == null then
|
|
$entries + [$entry]
|
|
else
|
|
$entries[0:$index + 1] + [$entry] + $entries[$index + 1:]
|
|
end;
|
|
|
|
object_or_empty
|
|
| .version = 1
|
|
| .bar = (.bar | object_or_empty)
|
|
| .bar.layout = (.bar.layout | object_or_empty)
|
|
| .bar.layout.left = (.bar.layout.left | 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)))
|
|
| .plugins = (.plugins | array_or_empty)
|
|
| .bar.layout[$section] = insert_after_anchor(.bar.layout[$section]; { id: $plugin }; append_anchor($section))
|
|
' "$source_file" >"$tmp"
|
|
|
|
mv "$tmp" "$CONFIG_FILE"
|
|
trap - EXIT
|
|
omarchy-shell -q shell rescanPlugins >/dev/null 2>&1 || true
|