* 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
142 lines
3.6 KiB
Bash
Executable File
142 lines
3.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# omarchy:summary=Remove an installed shell plugin
|
|
# omarchy:group=plugin
|
|
# omarchy:args=[id] [--yes]
|
|
# omarchy:alias=omarchy plugin rm
|
|
|
|
set -euo pipefail
|
|
|
|
PLUGINS_DIR="$HOME/.config/omarchy/plugins"
|
|
ASSUME_YES=0
|
|
|
|
fail() {
|
|
echo "omarchy-plugin-remove: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
interactive() {
|
|
[[ -t 0 && -t 1 ]]
|
|
}
|
|
|
|
confirm() {
|
|
local prompt="$1"
|
|
(( ASSUME_YES )) && return 0
|
|
if interactive; then
|
|
gum confirm "$prompt"
|
|
else
|
|
fail "refusing to continue without confirmation; pass --yes"
|
|
fi
|
|
}
|
|
|
|
valid_plugin_id() {
|
|
[[ $1 =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ && $1 != *..* ]]
|
|
}
|
|
|
|
id=""
|
|
|
|
while (( $# > 0 )); do
|
|
case "$1" in
|
|
--yes | -y)
|
|
ASSUME_YES=1
|
|
shift
|
|
;;
|
|
-h | --help)
|
|
echo "Usage: omarchy plugin remove [id] [--yes]"
|
|
exit 0
|
|
;;
|
|
-*)
|
|
fail "unknown remove option: $1"
|
|
;;
|
|
*)
|
|
[[ -z $id ]] || fail "unexpected argument: $1"
|
|
id="$1"
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
|
|
[[ -d $PLUGINS_DIR ]] || fail "no plugins installed"
|
|
|
|
if [[ -z $id ]]; then
|
|
interactive || fail "a plugin-id is required"
|
|
id=$(find "$PLUGINS_DIR" -mindepth 1 -maxdepth 1 \( -type d -o -type l \) \
|
|
! -name '.*' -printf '%f\n' 2>/dev/null |
|
|
sort |
|
|
gum choose --header="Remove which plugin?") || fail "cancelled"
|
|
[[ -n $id ]] || fail "nothing selected"
|
|
fi
|
|
valid_plugin_id "$id" || fail "invalid plugin id '$id'"
|
|
|
|
target="$PLUGINS_DIR/$id"
|
|
[[ -e $target || -L $target ]] || fail "plugin '$id' is not installed"
|
|
|
|
was_enabled=""
|
|
shell_plugins=$(omarchy-shell shell listPlugins)
|
|
if [[ -n $shell_plugins ]]; then
|
|
was_enabled=$(jq -r --arg id "$id" '
|
|
.[] | select(.id == $id) | .enabled
|
|
' <<<"$shell_plugins")
|
|
fi
|
|
|
|
cloned_from=""
|
|
restored_source=0
|
|
if [[ -f $target/manifest.json ]]; then
|
|
cloned_from=$(jq -r '.omarchy.clonedFrom // empty' "$target/manifest.json")
|
|
fi
|
|
|
|
if [[ -L $target ]]; then
|
|
confirm "Unlink '$id' (symlink -> $(readlink "$target"))?" || fail "aborted"
|
|
elif [[ -d $target/.git ]]; then
|
|
confirm "Delete '$id'? Its git repo remains upstream." || fail "aborted"
|
|
else
|
|
confirm "Remove '$id'? The folder will be backed up." || fail "aborted"
|
|
fi
|
|
|
|
if [[ -n $cloned_from ]]; then
|
|
is_bar=$(jq -r '(.kinds | index("bar")) != null' "$target/manifest.json")
|
|
is_bar_widget=$(jq -r '(.kinds | index("bar-widget")) != null' "$target/manifest.json")
|
|
has_non_widget_kind=$(jq -r 'any(.kinds[]; . != "bar-widget")' "$target/manifest.json")
|
|
|
|
if [[ $is_bar == "true" && $was_enabled == "true" ]]; then
|
|
omarchy-bar use "$cloned_from"
|
|
restored_source=1
|
|
elif [[ $is_bar_widget == "true" && $was_enabled == "true" ]]; then
|
|
omarchy-bar-plugin replace "$id" "$cloned_from"
|
|
[[ $has_non_widget_kind == "false" ]] || omarchy-plugin-enable "$cloned_from"
|
|
restored_source=1
|
|
elif [[ $has_non_widget_kind == "true" ]]; then
|
|
[[ $was_enabled != "true" ]] || omarchy-shell shell setPluginEnabled "$id" false >/dev/null
|
|
omarchy-plugin-enable "$cloned_from"
|
|
restored_source=1
|
|
fi
|
|
elif [[ $was_enabled == "true" ]]; then
|
|
omarchy-shell shell setPluginEnabled "$id" false >/dev/null
|
|
fi
|
|
|
|
if [[ -L $target ]]; then
|
|
rm -f "$target"
|
|
echo "Unlinked $id."
|
|
elif [[ -d $target/.git ]]; then
|
|
rm -rf "$target"
|
|
echo "Removed $id."
|
|
else
|
|
base="$PLUGINS_DIR/.${id}.bak.$(date -u +%Y%m%d%H%M%S)"
|
|
backup="$base"
|
|
n=1
|
|
while [[ -e $backup ]]; do
|
|
backup="${base}-${n}"
|
|
n=$((n + 1))
|
|
done
|
|
mv "$target" "$backup" || fail "failed to move $target to backup"
|
|
echo "Removed $id. Backup at: $backup"
|
|
fi
|
|
|
|
omarchy-shell shell rescanPlugins >/dev/null
|
|
|
|
if (( restored_source )); then
|
|
echo "Restored $cloned_from."
|
|
elif [[ $was_enabled == "true" ]]; then
|
|
echo "Plugin was enabled and was unloaded from omarchy-shell."
|
|
fi
|