mirror of
https://github.com/Permissionless-Software-Foundation/psf-memo-client.git
synced 2026-09-21 16:52:02 -07:00
61 lines
1.2 KiB
Bash
Executable File
61 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
TERMINAL_ADAPTERS_DIR="${SCRIPT_DIR:-$(cd "$(dirname "$0")" && pwd)}/terminal-adapters"
|
|
|
|
normalize_terminal_backend() {
|
|
local backend="$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')"
|
|
|
|
case "$backend" in
|
|
iterm|iterm2|iterm.app)
|
|
echo "iterm2"
|
|
;;
|
|
terminal|terminal-app|terminal.app)
|
|
echo "terminal-app"
|
|
;;
|
|
windows|windows-terminal|wt)
|
|
echo "windows-terminal"
|
|
;;
|
|
none|current|fallback)
|
|
echo "none"
|
|
;;
|
|
*)
|
|
echo "$backend"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
detect_terminal_backend() {
|
|
if [[ -n "${SWARMFORGE_TERMINAL:-}" ]]; then
|
|
normalize_terminal_backend "$SWARMFORGE_TERMINAL"
|
|
return
|
|
fi
|
|
|
|
if has_command osascript; then
|
|
if [[ "${TERM_PROGRAM:-}" == "iTerm.app" ]]; then
|
|
echo "iterm2"
|
|
return
|
|
fi
|
|
echo "terminal-app"
|
|
return
|
|
fi
|
|
|
|
if has_command wt.exe; then
|
|
echo "windows-terminal"
|
|
return
|
|
fi
|
|
|
|
echo "none"
|
|
}
|
|
|
|
load_terminal_backend() {
|
|
local backend="$1"
|
|
local adapter_file="$TERMINAL_ADAPTERS_DIR/$backend.sh"
|
|
|
|
if [[ ! -r "$adapter_file" ]]; then
|
|
echo "Unknown terminal backend '$backend'. Expected adapter file: $adapter_file" >&2
|
|
return 1
|
|
fi
|
|
|
|
source "$adapter_file"
|
|
}
|