feat(@scripts): update remote mirroring logic

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Natalie 2026-05-17 03:31:04 -07:00
parent d3a377e5c5
commit 9065abdca6

View file

@ -20,10 +20,15 @@
# Usage:
# rclaude # local, $PWD
# rclaude . # local, $PWD
# rclaude <host> # remote $HOME on <host>
# rclaude <host> # remote: $PWD mirrored under remote $HOME
# rclaude <host> . # same as above (explicit form)
# rclaude <host> <dir> # remote (or local) at <dir>
# rclaude list # show active sessions across hosts
# rclaude resume [pattern] # reattach (interactive if pattern matches >1)
#
# Mirror semantics: if local $PWD is $HOME/X/Y, the remote dir defaults to
# ~/X/Y on the remote (the remote's $HOME, not $HOME from this machine).
# If $PWD is outside $HOME, falls back to the remote's $HOME.
set -eu
@ -221,11 +226,16 @@ if is_local "$host"; then
.|"") dir=$PWD ;;
esac
else
if [ "$dir" = "." ]; then
echo "error: '.' as dir requires a local target; pass an explicit remote path" >&2
exit 2
# Remote default: mirror local $PWD relative to $HOME onto the remote's
# $HOME. Same behavior for omitted dir or explicit `.`. Falls back to
# remote $HOME if local $PWD isn't under $HOME.
if [ "$dir" = "." ] || [ -z "$dir" ]; then
case $PWD in
"$HOME") dir=\~ ;;
"$HOME"/*) _rel=${PWD#"$HOME"/}; dir="~/$_rel" ;;
*) dir=\~ ;;
esac
fi
[ -z "$dir" ] && dir=\~
fi
slug=$(printf %s "$dir" | sed -e 's|^[~/]*||' -e 's|[^A-Za-z0-9]|-|g')