Plugin cloning via menu (#6433)
* Add plugin cloning via menu * Split plugin commands by action * Keep plugin enablement in action commands * Remove unused plugin edit command * Simplify plugin rescan arguments * Assume Omarchy shell is running for plugin commands * Remove plugin compatibility dispatcher * Flatten plugin clone command * Keep only shared plugin helpers * Remove plugin rescan wrapper * Keep plugin commands self-contained * Simplify plugin clone lifecycle
This commit is contained in:
+15
-9
@@ -1,10 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
# omarchy:summary=Pick a shell plugin to enable, disable, or remove
|
||||
# omarchy:summary=Pick a shell plugin to enable, disable, clone, or remove
|
||||
# omarchy:group=menu
|
||||
# omarchy:name=plugin
|
||||
# omarchy:args=<enable|disable|remove>
|
||||
# omarchy:examples=omarchy menu plugin enable | omarchy menu plugin disable
|
||||
# omarchy:args=<enable|disable|clone|remove>
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
@@ -13,19 +12,21 @@ PLUGIN_ICON=$'\U000f0431'
|
||||
case "${1:-}" in
|
||||
enable) filter='(.enabled | not)' ;;
|
||||
disable) filter='.canDisable and .enabled' ;;
|
||||
clone) filter='.firstParty and ((.id | sub("^omarchy\\."; "local.")) as $clone_id | ($plugins | map(.id) | index($clone_id)) == null)' ;;
|
||||
remove) filter='(.firstParty | not)' ;;
|
||||
*)
|
||||
echo "Usage: omarchy-menu-plugin <enable|disable|remove>" >&2
|
||||
echo "Usage: omarchy-menu-plugin <enable|disable|clone|remove>" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
plugins=$(omarchy-plugin list --json) || exit 1
|
||||
plugins=$(omarchy-plugin-list --json)
|
||||
|
||||
# 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
|
||||
". as \$plugins
|
||||
| ([.[] | select($filter)]) as \$rows
|
||||
| \$rows[]
|
||||
| .name as \$name
|
||||
| (if ([\$rows[] | select(.name == \$name)] | length) > 1 then \$name + \" (\" + .id + \")\" else \$name end) as \$label
|
||||
@@ -38,8 +39,13 @@ name=$(omarchy-menu-select "${1^} plugin" < <(cut -f1,2 <<<"$rows")) || 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")"
|
||||
if [[ $1 == "clone" ]]; then
|
||||
new_id="local.${id#omarchy.}"
|
||||
target="$HOME/.config/omarchy/plugins/$new_id"
|
||||
omarchy-launch-floating-terminal-with-presentation \
|
||||
"omarchy-plugin-clone $(printf '%q' "$id") && exec \$EDITOR $(printf '%q' "$target")"
|
||||
elif [[ $1 == "remove" ]]; then
|
||||
omarchy-launch-floating-terminal-with-presentation "omarchy-plugin-remove $(printf '%q' "$id")"
|
||||
else
|
||||
omarchy-plugin "$1" "$id"
|
||||
"omarchy-plugin-$1" "$id"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user