fix(@scripts): 🐛 update session handling and add new flags
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
4204a1e85a
commit
6610424e67
1 changed files with 24 additions and 11 deletions
35
bin/crc
35
bin/crc
|
|
@ -20,6 +20,14 @@
|
|||
# crc -n ... # open a NEW iTerm window instead of current tab
|
||||
# crc -h | --help
|
||||
#
|
||||
# Options:
|
||||
# -s, --session <name> override the derived tmux session name (so a boot
|
||||
# unit and an interactive attach share ONE session)
|
||||
# --ensure start the session detached if not already running,
|
||||
# then exit (no attach) — for systemd / scripting
|
||||
# --respawn run `claude rc` in a restart loop inside the session,
|
||||
# so a crash is recovered without systemd intervention
|
||||
#
|
||||
# host may be any ssh target (alias, user@host, IP), or local/./localhost to run
|
||||
# on this machine. When <dir> is omitted, $PWD is mirrored to the same path
|
||||
# under the remote's $HOME (like rclaude); paths outside $HOME fall back to ~.
|
||||
|
|
@ -32,8 +40,11 @@ set -eu
|
|||
host=${CRC_HOST:-apricot.lan}
|
||||
new_window=0
|
||||
dry_run=0
|
||||
session_override=''
|
||||
ensure=0
|
||||
respawn=0
|
||||
|
||||
usage() { sed -n '2,29p' "$0" | sed 's/^# \{0,1\}//'; }
|
||||
usage() { sed -n '2,37p' "$0" | sed 's/^# \{0,1\}//'; }
|
||||
|
||||
# --- arg parse -------------------------------------------------------------
|
||||
positional='' # collected host/dir (max 2), space-free tokens unsafe so
|
||||
|
|
@ -48,6 +59,11 @@ while [ $# -gt 0 ]; do
|
|||
-h|--help) usage; exit 0 ;;
|
||||
-n|--new-window) new_window=1; shift ;;
|
||||
--dry-run) dry_run=1; shift ;;
|
||||
-s|--session)
|
||||
[ $# -ge 2 ] || { echo "crc: $1 needs a value" >&2; exit 2; }
|
||||
session_override=$2; shift 2 ;;
|
||||
--ensure) ensure=1; shift ;;
|
||||
--respawn) respawn=1; shift ;;
|
||||
--) shift; rc_args=$*; break ;;
|
||||
-*) echo "crc: unknown option: $1" >&2; exit 2 ;;
|
||||
*)
|
||||
|
|
@ -63,8 +79,9 @@ done
|
|||
if [ "$new_window" -eq 1 ]; then
|
||||
cmd="crc"
|
||||
[ $have_host -eq 1 ] && cmd="$cmd $(printf %q "$host")"
|
||||
[ $dir_set -eq 1 ] && cmd="$cmd $(printf %q "$dir")"
|
||||
[ -n "$rc_args" ] && cmd="$cmd -- $rc_args"
|
||||
[ $dir_set -eq 1 ] && cmd="$cmd $(printf %q "$dir")"
|
||||
[ -n "$session_override" ] && cmd="$cmd --session $(printf %q "$session_override")"
|
||||
[ -n "$rc_args" ] && cmd="$cmd -- $rc_args"
|
||||
escaped=$(printf %s "$cmd" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g')
|
||||
osascript <<OSA
|
||||
tell application "iTerm"
|
||||
|
|
@ -107,14 +124,10 @@ REL=$(printf %q "$rel")
|
|||
ABS=$(printf %q "$abs")
|
||||
RC_ARGS=$(printf %q "$rc_args")
|
||||
SESS=$(printf %q "$session")
|
||||
if [ -n "\$ABS" ]; then
|
||||
case "\$ABS" in
|
||||
"~") DIR=\$HOME ;;
|
||||
"~/"*) DIR="\$HOME/\${ABS#~/}" ;;
|
||||
*) DIR=\$ABS ;;
|
||||
esac
|
||||
else
|
||||
DIR="\$HOME\${REL:+/\$REL}"
|
||||
if [ "\$ABS" = "~" ]; then DIR=\$HOME
|
||||
elif [ -n "\$ABS" ] && [ "\${ABS#~/}" != "\$ABS" ]; then DIR="\$HOME/\${ABS#~/}"
|
||||
elif [ -n "\$ABS" ]; then DIR=\$ABS
|
||||
else DIR="\$HOME\${REL:+/\$REL}"
|
||||
fi
|
||||
if ! cd "\$DIR" 2>/dev/null; then
|
||||
echo "crc: directory not found on host: \$DIR" >&2
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue