#!/bin/bash # omarchy:summary=Add a shell plugin from git # omarchy:group=plugin # omarchy:args=[git-url] [--enable] [--yes] # omarchy:examples=omarchy plugin add https://github.com/acme/omarchy-weather.git --enable # omarchy:alias=omarchy plugin install set -euo pipefail export GIT_TERMINAL_PROMPT=0 export GIT_SSH_COMMAND="${GIT_SSH_COMMAND:-ssh -oBatchMode=yes}" PLUGINS_DIR="$HOME/.config/omarchy/plugins" ASSUME_YES=0 fail() { echo "omarchy-plugin-add: $*" >&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 } place_bar_widget() { local id="$1" local section local default_section interactive || return 0 (( ASSUME_YES )) && return 0 jq -e '(.kinds // []) | (index("bar") | not) and (index("bar-widget") != null)' \ "$PLUGINS_DIR/$id/manifest.json" >/dev/null 2>&1 || return 0 default_section=$(jq -r '.barWidget.defaultSection // "center"' "$PLUGINS_DIR/$id/manifest.json") section=$(printf '%s\n' left center right | gum choose --header="Place $id in which bar section?" --selected "$default_section") || return 0 [[ -n $section ]] || return 0 omarchy-bar-plugin move "$id" --section "$section" >/dev/null && echo "Placed $id in the $section section" } plugin_id_manifest() { omarchy-plugin-catalog | jq -r --arg id "$1" ' map(select(.id == $id))[0].manifestPath // empty ' } url="" enable_after="" while (( $# > 0 )); do case "$1" in --enable) enable_after=true shift ;; --yes | -y) ASSUME_YES=1 shift ;; -h | --help) echo "Usage: omarchy plugin add [git-url] [--enable] [--yes]" exit 0 ;; -*) fail "unknown add option: $1" ;; *) [[ -z $url ]] || fail "unexpected argument: $1" url="$1" shift ;; esac done if [[ -z $url ]]; then interactive || fail "a git URL is required (e.g. omarchy plugin add https://github.com/acme/omarchy-weather.git)" url=$(gum input --prompt "Git URL of the plugin repo: ") || fail "cancelled" [[ -n $url ]] || fail "a git URL is required" fi if (( ! ASSUME_YES )); then cat >&2 </dev/null if [[ -z $enable_after ]]; then if (( ASSUME_YES )) || ! interactive; then enable_after=false elif confirm "Enable '$id' now?"; then enable_after=true else enable_after=false fi fi if [[ $enable_after == true ]]; then for (( attempt = 0; attempt < 40; attempt++ )); do result=$(omarchy-shell shell setPluginEnabled "$id" true) [[ $result == "ok" ]] && break sleep 0.05 done [[ $result == "ok" ]] || fail "plugin '$id' is not known" if omarchy-plugin-catalog | jq -e --arg id "$id" ' any(.[]; .id == $id and (.kinds | index("bar"))) ' >/dev/null; then echo "Now using $id as the bar" else echo "Enabled $id" fi place_bar_widget "$id" else echo "Enable it later with: omarchy plugin enable $id" fi