#!/bin/bash # omarchy:summary=Mutate the user shell.json bar layout # omarchy:args= # omarchy:examples=omarchy config shell append 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 " >&2 } fail() { echo "omarchy-config-shell: $*" >&2 exit 1 } operation="${1:-}" section="${2:-}" plugin="${3:-}" if (( $# != 3 )); 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" 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 operation "$operation" --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) | 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 ' "$source_file" >"$tmp" mv "$tmp" "$CONFIG_FILE" trap - EXIT omarchy-shell -q shell rescanPlugins >/dev/null 2>&1 || true