47 lines
1.3 KiB
Bash
Executable File
47 lines
1.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# blob:summary=Pick a shell plugin to enable, disable, clone, or remove
|
|
# blob:group=menu
|
|
# blob:name=plugin
|
|
# blob:args=<enable|disable|clone|remove>
|
|
|
|
set -euo pipefail
|
|
|
|
PLUGIN_ICON=$'\U000f0431'
|
|
|
|
case "${1:-}" in
|
|
enable) filter='(.enabled | not)' ;;
|
|
disable) filter='.canDisable and .enabled' ;;
|
|
clone) filter='.firstParty and (.id as $id | ($plugins | map(.clonedFrom // "") | index($id)) == null)' ;;
|
|
remove) filter='(.firstParty | not)' ;;
|
|
*)
|
|
echo "Usage: blob-menu-plugin <enable|disable|clone|remove>" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
plugins=$(blob-plugin-list --json)
|
|
|
|
# The id rides along as row subtext: it tells same-named plugins apart on
|
|
# screen and comes back with the selection as the key to act on.
|
|
rows=$(jq -r --arg icon "$PLUGIN_ICON" \
|
|
". as \$plugins
|
|
| .[] | select($filter)
|
|
| \$icon + \"\\t\" + .name + \"\\t\" + .id" <<<"$plugins")
|
|
[[ -n $rows ]] || { blob-notify-send "No plugin to ${1}"; exit 0; }
|
|
|
|
selection=$(blob-menu-select "${1^} plugin" <<<"$rows") || exit 0
|
|
[[ -n $selection ]] || exit 0
|
|
|
|
id=$(cut -f2 <<<"$selection")
|
|
[[ -n $id ]] || exit 1
|
|
|
|
if [[ $1 == "clone" ]]; then
|
|
blob-launch-floating \
|
|
"blob-plugin-clone $(printf '%q' "$id") --edit"
|
|
elif [[ $1 == "remove" ]]; then
|
|
blob-launch-floating "blob-plugin-remove $(printf '%q' "$id")"
|
|
else
|
|
"blob-plugin-$1" "$id"
|
|
fi
|