38 lines
1.1 KiB
Bash
Executable File
38 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# omarchy:summary=Set bar position
|
|
# omarchy:args=<top|bottom|left|right>
|
|
# omarchy:examples=omarchy-style-bar-position top | omarchy style bar position bottom
|
|
|
|
set -e
|
|
|
|
CONFIG_FILE="$HOME/.config/omarchy/shell.json"
|
|
DEFAULTS_FILE="$OMARCHY_PATH/shell/shell-defaults.json"
|
|
position=$1
|
|
|
|
if [[ ! $position =~ ^(top|bottom|left|right)$ ]]; then
|
|
echo "Usage: omarchy-style-bar-position top|bottom|left|right" >&2
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p "$(dirname "$CONFIG_FILE")"
|
|
tmp=$(mktemp)
|
|
|
|
# Seed from shell-defaults.json when the user has no shell.json yet (or it's
|
|
# malformed). Writing just `{ bar: { position } }` would leave the bar with
|
|
# no layout, since the shell treats any valid user config as authoritative
|
|
# and does not deep-merge defaults.
|
|
if [[ -s $CONFIG_FILE ]] && jq -e 'type == "object"' "$CONFIG_FILE" >/dev/null 2>&1; then
|
|
source="$CONFIG_FILE"
|
|
else
|
|
source="$DEFAULTS_FILE"
|
|
fi
|
|
|
|
jq --arg position "$position" '
|
|
.version = 1 |
|
|
.bar = ((.bar // {}) | if type == "object" then . else {} end) |
|
|
.bar.position = $position
|
|
' "$source" >"$tmp"
|
|
|
|
mv "$tmp" "$CONFIG_FILE"
|