Merge remote-tracking branch 'origin/omarchy-shell' into omarchy-4
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# omarchy:summary=Mutate the user shell.json bar layout
|
||||
# omarchy:args=show | list [--json] [--all] | add [plugin] [left|center|right] | remove [plugin] | drop [plugin] | position <top|bottom|left|right> | transparent <true|false>
|
||||
# omarchy:examples=omarchy config shell bar show | omarchy config shell bar list | omarchy config shell bar add | omarchy config shell bar remove | omarchy config shell bar add omarchy.tailscale | omarchy config shell bar position top | omarchy config shell bar transparent true
|
||||
# omarchy:summary=Mutate the user shell.json bar layout and active bar option
|
||||
# omarchy:args=show | options [--json] | use <plugin> | reset | list [--json] [--all] | add [plugin] [left|center|right] | remove [plugin] | drop [plugin] | position <top|bottom|left|right> | transparent <true|false>
|
||||
# omarchy:examples=omarchy config shell bar show | omarchy config shell bar options | omarchy config shell bar use local.neon-bar | omarchy config shell bar reset | omarchy config shell bar list | omarchy config shell bar add omarchy.tailscale | omarchy config shell bar position top | omarchy config shell bar transparent true
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
@@ -11,7 +11,7 @@ OMARCHY_ROOT="${OMARCHY_PATH:-}"
|
||||
DEFAULTS_FILE="$OMARCHY_ROOT/config/omarchy/shell.json"
|
||||
|
||||
usage() {
|
||||
echo "Usage: omarchy-config-shell-bar show | list [--json] [--all] | add [plugin] [left|center|right] | remove [plugin] | drop [plugin] | position <top|bottom|left|right> | transparent <true|false>" >&2
|
||||
echo "Usage: omarchy-config-shell-bar show | options [--json] | use <plugin> | reset | list [--json] [--all] | add [plugin] [left|center|right] | remove [plugin] | drop [plugin] | position <top|bottom|left|right> | transparent <true|false>" >&2
|
||||
}
|
||||
|
||||
fail() {
|
||||
@@ -49,6 +49,95 @@ bar_widget_manifest_paths() {
|
||||
} | sort -u
|
||||
}
|
||||
|
||||
bar_option_manifest_paths() {
|
||||
{
|
||||
if [[ -n $OMARCHY_ROOT && -d $OMARCHY_ROOT/shell/plugins ]]; then
|
||||
find "$OMARCHY_ROOT/shell/plugins" -mindepth 2 -maxdepth 4 -type f \( -name manifest.json -o -name '*.manifest.json' \) 2>/dev/null
|
||||
fi
|
||||
|
||||
if [[ -d $HOME/.config/omarchy/plugins ]]; then
|
||||
find -L "$HOME/.config/omarchy/plugins" -mindepth 2 -maxdepth 2 -type f -name manifest.json 2>/dev/null
|
||||
fi
|
||||
} | sort -u
|
||||
}
|
||||
|
||||
current_bar_option_id() {
|
||||
jq -r '(.bar.id // "omarchy.bar") | tostring' "$(source_file)"
|
||||
}
|
||||
|
||||
available_bar_options_json() {
|
||||
local current_id
|
||||
local manifest_paths=()
|
||||
|
||||
current_id=$(current_bar_option_id)
|
||||
mapfile -t manifest_paths < <(bar_option_manifest_paths)
|
||||
|
||||
if (( ${#manifest_paths[@]} == 0 )); then
|
||||
printf '[]\n'
|
||||
return
|
||||
fi
|
||||
|
||||
jq -s --arg currentId "$current_id" '
|
||||
map(
|
||||
select(((.kinds // []) | index("bar")) and ((.entryPoints.bar // "") != "")) |
|
||||
{
|
||||
id: (.id // ""),
|
||||
name: (.name // .id // ""),
|
||||
description: (.description // ""),
|
||||
firstParty: ((.id // "") | startswith("omarchy.")),
|
||||
active: ((.id // "") == $currentId)
|
||||
} |
|
||||
select(.id != "")
|
||||
) |
|
||||
unique_by(.id) |
|
||||
sort_by((if .id == "omarchy.bar" then 0 else 1 end), .name, .id)
|
||||
' "${manifest_paths[@]}"
|
||||
}
|
||||
|
||||
print_bar_options() {
|
||||
local json="false"
|
||||
|
||||
while (( $# > 0 )); do
|
||||
case "$1" in
|
||||
--json)
|
||||
json="true"
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
fail "unknown options option: $1"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ $json == "true" ]]; then
|
||||
available_bar_options_json
|
||||
return
|
||||
fi
|
||||
|
||||
available_bar_options_json | jq -r '
|
||||
.[] |
|
||||
[
|
||||
.id,
|
||||
(if .active then "active" else "available" end),
|
||||
(if .firstParty then "built-in" else "plugin" end),
|
||||
.name,
|
||||
.description
|
||||
] | @tsv
|
||||
' | awk -F '\t' '
|
||||
BEGIN { printf "%-32s %-10s %-8s %-22s %s\n", "ID", "STATUS", "SOURCE", "NAME", "DESCRIPTION" }
|
||||
{ printf "%-32s %-10s %-8s %-22s %s\n", $1, $2, $3, $4, $5 }
|
||||
'
|
||||
}
|
||||
|
||||
bar_option_exists() {
|
||||
local id="$1"
|
||||
available_bar_options_json | jq -e --arg id "$id" 'any(.[]; .id == $id)' >/dev/null
|
||||
}
|
||||
|
||||
current_bar_ids_json() {
|
||||
jq -c '
|
||||
def array_or_empty: if type == "array" then . else [] end;
|
||||
@@ -256,7 +345,88 @@ case "$command" in
|
||||
|
||||
jq '.bar // {}' "$(source_file)"
|
||||
;;
|
||||
list|available|options)
|
||||
selected|active)
|
||||
if (( $# != 1 )); then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
current_bar_option_id
|
||||
;;
|
||||
options|option)
|
||||
shift
|
||||
print_bar_options "$@"
|
||||
;;
|
||||
use)
|
||||
if (( $# != 2 )); then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
plugin="${2:-}"
|
||||
[[ -n $plugin ]] || fail "bar option id is required"
|
||||
if [[ $plugin == "default" || $plugin == "built-in" ]]; then
|
||||
plugin="omarchy.bar"
|
||||
fi
|
||||
bar_option_exists "$plugin" || fail "$plugin is not a known bar option; run 'omarchy config shell bar options'"
|
||||
|
||||
mkdir -p "$(dirname "$CONFIG_FILE")"
|
||||
|
||||
source="$(source_file)"
|
||||
tmp=$(mktemp)
|
||||
trap 'rm -f "$tmp"' EXIT
|
||||
|
||||
if [[ $plugin == "omarchy.bar" ]]; then
|
||||
jq '
|
||||
def object_or_empty: if type == "object" then . else {} end;
|
||||
|
||||
object_or_empty
|
||||
| .version = 1
|
||||
| .bar = (.bar | object_or_empty)
|
||||
| del(.bar.id)
|
||||
' "$source" >"$tmp"
|
||||
else
|
||||
jq --arg plugin "$plugin" '
|
||||
def object_or_empty: if type == "object" then . else {} end;
|
||||
|
||||
object_or_empty
|
||||
| .version = 1
|
||||
| .bar = (.bar | object_or_empty)
|
||||
| .bar.id = $plugin
|
||||
' "$source" >"$tmp"
|
||||
fi
|
||||
|
||||
mv "$tmp" "$CONFIG_FILE"
|
||||
trap - EXIT
|
||||
omarchy-shell -q shell rescanPlugins >/dev/null 2>&1 || true
|
||||
refresh_shell_config
|
||||
;;
|
||||
reset)
|
||||
if (( $# != 1 )); then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$(dirname "$CONFIG_FILE")"
|
||||
|
||||
source="$(source_file)"
|
||||
tmp=$(mktemp)
|
||||
trap 'rm -f "$tmp"' EXIT
|
||||
|
||||
jq '
|
||||
def object_or_empty: if type == "object" then . else {} end;
|
||||
|
||||
object_or_empty
|
||||
| .version = 1
|
||||
| .bar = (.bar | object_or_empty)
|
||||
| del(.bar.id)
|
||||
' "$source" >"$tmp"
|
||||
|
||||
mv "$tmp" "$CONFIG_FILE"
|
||||
trap - EXIT
|
||||
refresh_shell_config
|
||||
;;
|
||||
list|available|widgets)
|
||||
shift
|
||||
print_available_widgets "$@"
|
||||
;;
|
||||
|
||||
+25
-1
@@ -41,9 +41,13 @@ Clone options:
|
||||
--prompt <prompt> Initial prompt when opening with AI
|
||||
--replace Replace the first source bar instance
|
||||
--add [placement] Add cloned bar widget to the bar
|
||||
--use Use cloned bar options as the active bar
|
||||
|
||||
Bar widget commands:
|
||||
bar settings Open the inline bar config panel
|
||||
bar options [--json] List available bar options
|
||||
bar use <id> Use a bar option as the active bar
|
||||
bar reset Return to the built-in Omarchy bar
|
||||
bar list [--json] List current bar layout
|
||||
bar add <id> [placement] [--duplicate]
|
||||
bar move <id> [placement] [--from-section SECTION] [--from-index N]
|
||||
@@ -65,6 +69,9 @@ Examples:
|
||||
omarchy plugin edit local.clock --with editor
|
||||
omarchy plugin edit local.clock --with ai --prompt "Customize this clock"
|
||||
omarchy plugin enable acme.weather --section right
|
||||
omarchy plugin bar options
|
||||
omarchy plugin bar use local.neon-bar
|
||||
omarchy plugin bar reset
|
||||
omarchy plugin bar add acme.weather --section right --before omarchy.tray
|
||||
omarchy plugin bar move omarchy.clock --section center --index 0
|
||||
omarchy plugin bar remove acme.weather
|
||||
@@ -705,7 +712,7 @@ clone_source_options() {
|
||||
first_party_manifest_paths | while IFS= read -r manifest; do
|
||||
id=$(jq -r '.id // empty' "$manifest" 2>/dev/null || true)
|
||||
name=$(jq -r '.barWidget.displayName // .name // .id // empty' "$manifest" 2>/dev/null || true)
|
||||
[[ -n $id && $id != "omarchy.bar" ]] || continue
|
||||
[[ -n $id ]] || continue
|
||||
if jq -e '(.kinds // []) | index("bar-widget")' "$manifest" >/dev/null 2>&1; then
|
||||
printf '%s\tBuilt-in widget\t%s\n' "$id" "${name:-$id}"
|
||||
else
|
||||
@@ -1030,6 +1037,7 @@ clone_command() {
|
||||
local prompt=""
|
||||
local replace="false"
|
||||
local add="false"
|
||||
local use_bar="false"
|
||||
local placement=()
|
||||
|
||||
while (( $# > 0 )); do
|
||||
@@ -1061,6 +1069,10 @@ clone_command() {
|
||||
add="true"
|
||||
shift
|
||||
;;
|
||||
--use)
|
||||
use_bar="true"
|
||||
shift
|
||||
;;
|
||||
--section | --index | --before | --after)
|
||||
placement+=("$1" "${2:-}")
|
||||
shift 2
|
||||
@@ -1155,6 +1167,9 @@ clone_command() {
|
||||
elif [[ $add == "true" ]]; then
|
||||
bar_add "$new_id" "${placement[@]}"
|
||||
echo "Cloned $source_id to $new_id"
|
||||
elif [[ $use_bar == "true" ]]; then
|
||||
omarchy-config-shell-bar use "$new_id"
|
||||
echo "Cloned $source_id to $new_id and selected it as the active bar option"
|
||||
else
|
||||
echo "Cloned $source_id to $new_id"
|
||||
fi
|
||||
@@ -1176,6 +1191,15 @@ bar_command() {
|
||||
(( $# == 0 )) || fail "bar settings does not take arguments"
|
||||
exec omarchy-launch-bar-settings
|
||||
;;
|
||||
options | option)
|
||||
exec omarchy-config-shell-bar options "$@"
|
||||
;;
|
||||
use)
|
||||
exec omarchy-config-shell-bar use "$@"
|
||||
;;
|
||||
reset)
|
||||
exec omarchy-config-shell-bar reset "$@"
|
||||
;;
|
||||
list)
|
||||
bar_list "$@"
|
||||
;;
|
||||
|
||||
Reference in New Issue
Block a user