rclaude: bare invocation and '.' default to local + $PWD
This commit is contained in:
parent
8a55bef58a
commit
ebf578dc3f
1 changed files with 39 additions and 18 deletions
57
bin/rclaude
57
bin/rclaude
|
|
@ -23,20 +23,50 @@
|
|||
# other --permission-mode value) if you want prompts back.
|
||||
#
|
||||
# Usage:
|
||||
# rclaude # local, current pwd (shorthand)
|
||||
# rclaude . # same
|
||||
# rclaude apricot # remote home dir on apricot
|
||||
# rclaude apricot ~/Code/@projects/foo # remote, specific dir
|
||||
# rclaude local ~/Code/@projects/foo # local tmux-wrapped session
|
||||
# rclaude $(hostname) ~ # same — detected as local
|
||||
# rclaude local . # local, current pwd (explicit)
|
||||
# rclaude local ~/Code/@projects/foo # local, specific dir
|
||||
# rclaude $(hostname) ~ # also local (hostname match)
|
||||
|
||||
set -eu
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "usage: $0 <host> [dir] (dir defaults to remote/local \$HOME)" >&2
|
||||
exit 2
|
||||
# Argument resolution:
|
||||
# `rclaude` → local, $PWD
|
||||
# `rclaude .` → local, $PWD
|
||||
# `rclaude <host>` → host, default dir (~ remote, $PWD local)
|
||||
# `rclaude <host> <dir>` → host, dir (with `.` resolving to $PWD)
|
||||
if [ $# -eq 0 ] || [ "${1:-}" = "." ]; then
|
||||
host=local
|
||||
dir=$PWD
|
||||
else
|
||||
host=$1
|
||||
dir=${2:-}
|
||||
fi
|
||||
|
||||
host=$1
|
||||
dir=${2:-\~}
|
||||
is_local() {
|
||||
case $1 in
|
||||
local|localhost|127.0.0.1|::1) return 0 ;;
|
||||
esac
|
||||
[ "$1" = "$(hostname)" ] && return 0
|
||||
[ "$1" = "$(hostname -s 2>/dev/null)" ] && return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
# Defaults + `.` expansion now that we know whether we're local or remote.
|
||||
if is_local "$host"; then
|
||||
case ${dir:-.} in
|
||||
.|"") dir=$PWD ;;
|
||||
esac
|
||||
else
|
||||
if [ "$dir" = "." ]; then
|
||||
echo "error: '.' as dir requires a local target; pass an explicit remote path" >&2
|
||||
exit 2
|
||||
fi
|
||||
[ -z "$dir" ] && dir=\~
|
||||
fi
|
||||
|
||||
slug=$(printf %s "$dir" | sed -e 's|^[~/]*||' -e 's|[^A-Za-z0-9]|-|g')
|
||||
[ -z "$slug" ] && slug=home
|
||||
|
|
@ -48,18 +78,9 @@ case $perms in
|
|||
*) flag="--permission-mode $perms" ;;
|
||||
esac
|
||||
|
||||
is_local() {
|
||||
case $1 in
|
||||
local|localhost|127.0.0.1|::1) return 0 ;;
|
||||
esac
|
||||
[ "$1" = "$(hostname)" ] && return 0
|
||||
[ "$1" = "$(hostname -s 2>/dev/null)" ] && return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
if is_local "$host"; then
|
||||
# No ssh hop — just local tmux. eval expands ~ and env vars in dir.
|
||||
eval "cd ${dir}"
|
||||
# No ssh hop — local tmux. dir is already an absolute path here.
|
||||
cd "$dir"
|
||||
exec tmux new-session -A -s "$session" "exec claude --continue ${flag}"
|
||||
fi
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue