diff --git a/bin/omarchy-bar-plugin b/bin/omarchy-bar-plugin index 58c89692..cabf31f2 100755 --- a/bin/omarchy-bar-plugin +++ b/bin/omarchy-bar-plugin @@ -121,6 +121,13 @@ widget_is_known() { ' >/dev/null } +widget_default_section() { + omarchy-plugin-catalog | jq -r --arg id "$1" ' + (map(select(.id == $id))[0].barWidget.defaultSection // "center") as $section + | if ["left", "center", "right"] | index($section) then $section else "center" end + ' +} + # --------------------------------------------------------------------- placement # Parse placement flags shared by add/move/remove/set. Sets the globals below. @@ -217,7 +224,7 @@ cmd_add() { widget_is_known "$id" || fail "$id is not a known bar widget; run 'omarchy plugin list' to see valid ids" - local default_section="${PLACEMENT_SECTION:-right}" + local default_section="${PLACEMENT_SECTION:-$(widget_default_section "$id")}" local explicit="false" if [[ -n $PLACEMENT_INDEX || -n $PLACEMENT_BEFORE || -n $PLACEMENT_AFTER || $PLACEMENT_DUPLICATE == true ]]; then explicit="true" diff --git a/bin/omarchy-menu-plugin b/bin/omarchy-menu-plugin new file mode 100755 index 00000000..d0c77788 --- /dev/null +++ b/bin/omarchy-menu-plugin @@ -0,0 +1,45 @@ +#!/bin/bash + +# omarchy:summary=Pick a shell plugin to enable, disable, or remove +# omarchy:group=menu +# omarchy:name=plugin +# omarchy:args= +# omarchy:examples=omarchy menu plugin enable | omarchy menu plugin disable + +set -euo pipefail + +PLUGIN_ICON=$'\U000f0431' + +case "${1:-}" in + enable) filter='(.enabled | not)' ;; + disable) filter='.canDisable and .enabled' ;; + remove) filter='(.firstParty | not)' ;; + *) + echo "Usage: omarchy-menu-plugin " >&2 + exit 1 + ;; +esac + +plugins=$(omarchy-plugin list --json) || exit 1 + +# Two plugins may share a name, so keep the id with the row and show it when the +# name alone cannot identify the pick. +rows=$(jq -r --arg icon "$PLUGIN_ICON" \ + "([.[] | select($filter)]) as \$rows + | \$rows[] + | .name as \$name + | (if ([\$rows[] | select(.name == \$name)] | length) > 1 then \$name + \" (\" + .id + \")\" else \$name end) as \$label + | \$icon + \"\\t\" + \$label + \"\\t\" + .id" <<<"$plugins") +[[ -n $rows ]] || { omarchy-notification-send "No plugin to ${1}"; exit 0; } + +name=$(omarchy-menu-select "${1^} plugin" < <(cut -f1,2 <<<"$rows")) || exit 0 +[[ -n $name ]] || exit 0 + +id=$(awk -F'\t' -v label="$name" '$2 == label { print $3; exit }' <<<"$rows") +[[ -n $id ]] || exit 1 + +if [[ $1 == "remove" ]]; then + omarchy-launch-floating-terminal-with-presentation "omarchy-plugin remove $(printf '%q' "$id")" +else + omarchy-plugin "$1" "$id" +fi diff --git a/bin/omarchy-menu-select b/bin/omarchy-menu-select index 7914aa1f..5a5dde55 100755 --- a/bin/omarchy-menu-select +++ b/bin/omarchy-menu-select @@ -6,6 +6,9 @@ # omarchy:args=prompt [option...] [-- menu args...] # omarchy:examples=omarchy menu select Format jpg png|omarchy-menu-select Resolution 4k 1080p 720p -- --width 400 +# An option may lead with an icon, as "