Extend shell bar config command
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=add <plugin> [left|center|right] | drop <plugin> | show
|
# omarchy:args=add <plugin> [left|center|right] | drop <plugin> | position <top|bottom|left|right> | transparent <true|false> | show
|
||||||
# omarchy:examples=omarchy config shell bar add omarchy.tailscale | omarchy config shell bar drop omarchy.tailscale | omarchy config shell bar show
|
# omarchy:examples=omarchy config shell bar add omarchy.tailscale | omarchy config shell bar position top | omarchy config shell bar transparent true | omarchy config shell bar show
|
||||||
|
|
||||||
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-bar add <plugin> [left|center|right] | drop <plugin> | show" >&2
|
echo "Usage: omarchy-config-shell-bar add <plugin> [left|center|right] | drop <plugin> | position <top|bottom|left|right> | transparent <true|false> | show" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
fail() {
|
fail() {
|
||||||
@@ -40,7 +40,7 @@ case "$command" in
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
jq . "$(source_file)"
|
jq '.bar // {}' "$(source_file)"
|
||||||
;;
|
;;
|
||||||
add)
|
add)
|
||||||
if (( $# < 2 || $# > 3 )); then
|
if (( $# < 2 || $# > 3 )); then
|
||||||
@@ -93,6 +93,62 @@ case "$command" in
|
|||||||
trap - EXIT
|
trap - EXIT
|
||||||
omarchy-shell -q shell rescanPlugins >/dev/null 2>&1 || true
|
omarchy-shell -q shell rescanPlugins >/dev/null 2>&1 || true
|
||||||
;;
|
;;
|
||||||
|
position)
|
||||||
|
if (( $# != 2 )); then
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
position="${2:-}"
|
||||||
|
|
||||||
|
[[ $position =~ ^(top|bottom|left|right)$ ]] || fail "position must be top, bottom, left, or right"
|
||||||
|
|
||||||
|
mkdir -p "$(dirname "$CONFIG_FILE")"
|
||||||
|
|
||||||
|
source="$(source_file)"
|
||||||
|
tmp=$(mktemp)
|
||||||
|
trap 'rm -f "$tmp"' EXIT
|
||||||
|
|
||||||
|
jq --arg position "$position" '
|
||||||
|
def object_or_empty: if type == "object" then . else {} end;
|
||||||
|
|
||||||
|
object_or_empty
|
||||||
|
| .version = 1
|
||||||
|
| .bar = (.bar | object_or_empty)
|
||||||
|
| .bar.position = $position
|
||||||
|
' "$source" >"$tmp"
|
||||||
|
|
||||||
|
mv "$tmp" "$CONFIG_FILE"
|
||||||
|
trap - EXIT
|
||||||
|
;;
|
||||||
|
transparent)
|
||||||
|
if (( $# != 2 )); then
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
transparent="${2:-}"
|
||||||
|
|
||||||
|
[[ $transparent =~ ^(true|false)$ ]] || fail "transparent must be true or false"
|
||||||
|
|
||||||
|
mkdir -p "$(dirname "$CONFIG_FILE")"
|
||||||
|
|
||||||
|
source="$(source_file)"
|
||||||
|
tmp=$(mktemp)
|
||||||
|
trap 'rm -f "$tmp"' EXIT
|
||||||
|
|
||||||
|
jq --argjson transparent "$transparent" '
|
||||||
|
def object_or_empty: if type == "object" then . else {} end;
|
||||||
|
|
||||||
|
object_or_empty
|
||||||
|
| .version = 1
|
||||||
|
| .bar = (.bar | object_or_empty)
|
||||||
|
| .bar.transparent = $transparent
|
||||||
|
' "$source" >"$tmp"
|
||||||
|
|
||||||
|
mv "$tmp" "$CONFIG_FILE"
|
||||||
|
trap - EXIT
|
||||||
|
;;
|
||||||
drop)
|
drop)
|
||||||
if (( $# != 2 )); then
|
if (( $# != 2 )); then
|
||||||
usage
|
usage
|
||||||
|
|||||||
@@ -40,14 +40,79 @@ _omarchy_complete() {
|
|||||||
candidates+=("--all" "--json" "--markdown" "--check")
|
candidates+=("--all" "--json" "--markdown" "--check")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if (( ${#candidates[@]} == 0 )) && [[ -x $bin_dir/$prefix ]]; then
|
if (( ${#candidates[@]} == 0 )); then
|
||||||
local args enum
|
local command_prefix command_path first_arg_index n j
|
||||||
args=$(grep -m 1 '^# omarchy:args=<' "$bin_dir/$prefix" 2>/dev/null)
|
for ((n = COMP_CWORD - 1; n >= 0; n--)); do
|
||||||
enum="${args#*<}"
|
command_prefix="omarchy"
|
||||||
enum="${enum%%>*}"
|
for ((j = 1; j <= n; j++)); do
|
||||||
|
part="${COMP_WORDS[j]}"
|
||||||
|
[[ -z $part || $part == -* ]] && continue
|
||||||
|
command_prefix+="-$part"
|
||||||
|
done
|
||||||
|
|
||||||
if [[ $enum == *"|"* && $enum != *" "* ]]; then
|
command_path="$bin_dir/$command_prefix"
|
||||||
read -r -a candidates <<<"${enum//|/ }"
|
if [[ -x $command_path ]]; then
|
||||||
|
first_arg_index=$((n + 1))
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -n ${command_path:-} && -x $command_path ]]; then
|
||||||
|
local args spec alt token actual alts value match current_arg_index
|
||||||
|
args=$(grep -m 1 '^# omarchy:args=' "$command_path" 2>/dev/null)
|
||||||
|
args="${args#*omarchy:args=}"
|
||||||
|
current_arg_index=$((COMP_CWORD - first_arg_index))
|
||||||
|
|
||||||
|
alts="${args// | /$'\n'}"
|
||||||
|
while IFS= read -r alt; do
|
||||||
|
read -r -a spec <<<"$alt"
|
||||||
|
match=true
|
||||||
|
|
||||||
|
for ((j = 0; j < current_arg_index; j++)); do
|
||||||
|
token="${spec[j]:-}"
|
||||||
|
actual="${COMP_WORDS[first_arg_index + j]:-}"
|
||||||
|
if [[ -z $token ]]; then
|
||||||
|
match=false
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $token == \<*\> || $token == \[*\] ]]; then
|
||||||
|
value="${token#<}"
|
||||||
|
value="${value#\[}"
|
||||||
|
value="${value%>}"
|
||||||
|
value="${value%\]}"
|
||||||
|
if [[ $value == *"|"* ]]; then
|
||||||
|
[[ " ${value//|/ } " == *" $actual "* ]] || match=false
|
||||||
|
fi
|
||||||
|
elif [[ $token != "$actual" ]]; then
|
||||||
|
match=false
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
[[ $match == true ]] || continue
|
||||||
|
|
||||||
|
token="${spec[current_arg_index]:-}"
|
||||||
|
[[ -n $token ]] || continue
|
||||||
|
|
||||||
|
if [[ $token == \<*\> || $token == \[*\] ]]; then
|
||||||
|
value="${token#<}"
|
||||||
|
value="${value#\[}"
|
||||||
|
value="${value%>}"
|
||||||
|
value="${value%\]}"
|
||||||
|
if [[ $value == *"|"* ]]; then
|
||||||
|
read -r -a spec <<<"${value//|/ }"
|
||||||
|
for actual in "${spec[@]}"; do
|
||||||
|
[[ -n ${seen[$actual]:-} ]] && continue
|
||||||
|
seen[$actual]=1
|
||||||
|
candidates+=("$actual")
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
[[ -n ${seen[$token]:-} ]] && continue
|
||||||
|
seen[$token]=1
|
||||||
|
candidates+=("$token")
|
||||||
|
fi
|
||||||
|
done <<<"$alts"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -139,9 +139,25 @@ pass "shell config moves existing widgets without duplicates"
|
|||||||
|
|
||||||
HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-config-shell-bar show | jq -e '
|
HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-config-shell-bar show | jq -e '
|
||||||
def ids: map(.id // .);
|
def ids: map(.id // .);
|
||||||
.bar.layout.right | ids == ["omarchy.tray", "local.first", "omarchy.tailscale", "omarchy.bluetooth"]
|
(.layout.right | ids == ["omarchy.tray", "local.first", "omarchy.tailscale", "omarchy.bluetooth"]) and
|
||||||
|
has("version") | not
|
||||||
' >/dev/null
|
' >/dev/null
|
||||||
pass "shell config shows bar json"
|
pass "shell config shows only bar json"
|
||||||
|
|
||||||
|
HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-config-shell-bar position bottom
|
||||||
|
jq -e '
|
||||||
|
.bar.position == "bottom" and
|
||||||
|
.plugins == []
|
||||||
|
' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null
|
||||||
|
pass "shell config sets bar position"
|
||||||
|
|
||||||
|
HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-config-shell-bar transparent true
|
||||||
|
jq -e '
|
||||||
|
.bar.transparent == true and
|
||||||
|
.bar.position == "bottom" and
|
||||||
|
.plugins == []
|
||||||
|
' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null
|
||||||
|
pass "shell config sets bar transparency"
|
||||||
|
|
||||||
HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-config-shell-bar drop local.left
|
HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-config-shell-bar drop local.left
|
||||||
jq -e '
|
jq -e '
|
||||||
|
|||||||
Reference in New Issue
Block a user