Add default AI and launch command

This commit is contained in:
Ryan Hughes
2026-05-23 04:32:20 -04:00
parent 734e7d9ff2
commit fc180af54e
2 changed files with 137 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
#!/bin/bash
# omarchy:summary=Set the default AI harness used by omarchy-launch-ai
# omarchy:args=[pi|claude|codex|opencode]
# omarchy:examples=omarchy default ai | omarchy default ai pi | omarchy default ai claude
ai_file="$HOME/.local/state/omarchy/defaults/ai"
if (( $# == 0 )); then
if [[ -f $ai_file ]]; then
read -r harness <"$ai_file"
fi
[[ -n ${harness:-} ]] && echo "$harness" || echo "pi"
exit 0
fi
case "$1" in
pi) harness="pi"; name="Pi"; glyph=󰚩 ;;
claude) harness="claude"; name="Claude Code"; glyph=󰚩 ;;
codex) harness="codex"; name="Codex"; glyph=󰚩 ;;
opencode) harness="opencode"; name="OpenCode"; glyph=󰚩 ;;
*)
echo "Usage: omarchy-default-ai <pi|claude|codex|opencode>" >&2
exit 1
;;
esac
mkdir -p "$(dirname "$ai_file")"
printf '%s\n' "$harness" >"$ai_file"
omarchy-notification-send -g "$glyph" "$name is now the default AI harness"
+105
View File
@@ -0,0 +1,105 @@
#!/bin/bash
# omarchy:summary=Launch the default AI coding harness in a project path
# omarchy:args=[--path <path>] [--prompt <prompt>] [--harness <pi|claude|codex|opencode>] [path]
# omarchy:examples=omarchy launch ai --path ~/.config/omarchy/plugins/local.clock | omarchy launch ai --harness claude --path . --prompt "Review this plugin"
set -euo pipefail
path="."
prompt=""
harness=""
usage() {
cat <<'USAGE'
Usage: omarchy-launch-ai [--path <path>] [--prompt <prompt>] [--harness <pi|claude|codex|opencode>] [path]
Launches an interactive AI coding harness in the given path. If no harness is
provided, uses the value from `omarchy default ai`.
USAGE
}
fail() {
echo "omarchy-launch-ai: $*" >&2
exit 1
}
while (( $# > 0 )); do
case "$1" in
--path)
path="${2:-}"
[[ -n $path ]] || fail "--path requires a value"
shift 2
;;
--prompt)
prompt="${2:-}"
shift 2
;;
--harness)
harness="${2:-}"
[[ -n $harness ]] || fail "--harness requires a value"
shift 2
;;
-h | --help)
usage
exit 0
;;
--)
shift
break
;;
--*)
fail "unknown option: $1"
;;
*)
path="$1"
shift
;;
esac
done
[[ -d $path ]] || fail "path is not a directory: $path"
path=$(cd "$path" && pwd)
if [[ -z $harness ]]; then
harness=$(omarchy-default-ai)
fi
case "$harness" in
pi | claude | codex | opencode)
;;
*)
fail "unknown AI harness: $harness"
;;
esac
launch_in_place() {
cd "$path"
case "$harness" in
pi)
omarchy-cmd-present pi || fail "pi is not installed"
if [[ -n $prompt ]]; then exec pi "$prompt"; else exec pi; fi
;;
claude)
omarchy-cmd-present claude || fail "claude is not installed"
if [[ -n $prompt ]]; then exec claude "$prompt"; else exec claude; fi
;;
codex)
omarchy-cmd-present codex || fail "codex is not installed"
if [[ -n $prompt ]]; then exec codex "$prompt"; else exec codex; fi
;;
opencode)
omarchy-cmd-present opencode || fail "opencode is not installed"
if [[ -n $prompt ]]; then exec opencode --prompt "$prompt" .; else exec opencode .; fi
;;
esac
}
if [[ -t 0 && -t 1 ]]; then
launch_in_place
fi
quoted_path=$(printf '%q' "$path")
quoted_prompt=$(printf '%q' "$prompt")
quoted_harness=$(printf '%q' "$harness")
exec omarchy-launch-tui bash -lc "cd $quoted_path && exec omarchy-launch-ai --harness $quoted_harness --prompt $quoted_prompt --path ."