summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pkgs/claude-remote.nix102
1 files changed, 79 insertions, 23 deletions
diff --git a/pkgs/claude-remote.nix b/pkgs/claude-remote.nix
index 7f62b5b..ff49102 100644
--- a/pkgs/claude-remote.nix
+++ b/pkgs/claude-remote.nix
@@ -38,27 +38,83 @@ let
usage() {
cat <<'EOF'
- usage: claude-remote [list] the remotes: name, kind, state, trusted
- claude-remote inspect NAME a remote, in more detail
- claude-remote start NAME start a remote (lasts until stop)
- claude-remote stop NAME
- claude-remote restart NAME
- claude-remote attach [NAME] its terminal (tmux; default: main)
- claude-remote log NAME [JOURNALCTL-OPTION...]
- claude-remote rename OLD NEW [--stop]
- A remote is claude-remote-control@NAME, working in ~claude/remotes/NAME.
- Static ones are started by the system's configuration; others, started
- here, are dynamic: they last, across reboots, until stopped here.
- rename: checks first, and changes nothing unless all's well; stops OLD
- if it runs (asking first, or with --stop); moves its directory, Claude
- Code project, trust, worktrees and branches (OLD/* to NEW/*); starts
- NEW if OLD ran. All or nothing: if a step fails, it takes back those
- done. rename NEW OLD takes it back. Not for static ones: take them
- out of the system's configuration first.
+ usage: claude-remote [COMMAND [NAME...]]
+
+ The remotes: claude-remote-control@NAME, each a Claude Code Remote
+ Control server, working in ~claude/remotes/NAME.
+
+ Commands:
+ list (the default)
+ The remotes: name, kind, state, trusted; and copies of
+ ~claude/.claude.json that a failed rename kept.
+ inspect NAME
+ A remote, in more detail: its unit, directory, trust, claude.ai
+ session, and its terminal's last lines.
+ start NAME
+ Start a remote; a dynamic one lasts, across reboots, until stop.
+ stop NAME
+ restart NAME
+ attach [NAME]
+ Its terminal (tmux; default: main; C-b d to leave).
+ log NAME [JOURNALCTL-OPTION...]
+ Its unit's journal.
+ rename OLD NEW [--stop]
+ Check first, and change nothing unless all's well; stop OLD if
+ it runs (asking first, or with --stop); move its directory,
+ Claude Code project, trust, worktrees and branches (OLD/* to
+ NEW/*); start NEW if OLD ran. All or nothing: if a step
+ fails, it takes back those done. rename NEW OLD takes it back.
+ As root, and not from OLD itself; not for static ones (take
+ them out of the system's configuration first).
+ help, -h, --help
+ This.
+
+ Kinds:
+ static started by the system's configuration
+ dynamic started here: lasts, across reboots, until stopped here
+ - neither: stopped, or not started yet
EOF
}
+ # colors, if FD (1 or 2) is a terminal, as claude-inbox has them:
+ # commands, options, names, and bold for headings; none with NO_COLOR,
+ # or a dumb one
+ colors() {
+ C_CMD= C_OPT= C_NAME= C_HEAD= C_OFF=
+ test -t "$1" && test -z "''${NO_COLOR-}" || return 0
+ case ''${TERM-dumb} in dumb | "") return 0 ;; esac
+ local n p
+ case ''${COLORTERM-} in
+ truecolor | 24bit) p="38;2;230;180;80 38;2;150;150;175 38;2;100;160;240" ;;
+ *)
+ case $TERM in
+ *256color*) n=256 ;;
+ *) n=$(tput colors 2>/dev/null) || n=8 ;;
+ esac
+ if test "''${n:-0}" -ge 256; then p="38;5;179 38;5;103 38;5;75"
+ elif test "''${n:-0}" -ge 8; then p="33 35 34"
+ else return 0
+ fi ;;
+ esac
+ set -- $p
+ C_CMD=$'\e['$1m C_OPT=$'\e['$2m C_NAME=$'\e['$3m C_OFF=$'\e[0m'
+ C_HEAD=$'\e[1m'
+ }
+ # the headings (bold), commands (where they lead a line, or follow
+ # claude-remote), options and names in a text (the help, an error), in
+ # their colors, if any (a colored word follows an m, so each loop ends)
+ paint() {
+ if test -z "$C_OFF"; then cat; return; fi
+ local x='[^-A-Za-z0-9_]' c='list|inspect|start|stop|restart|attach|log|rename|help'
+ sed -E \
+ -e "s/^([A-Z][A-Za-z ]*:)$/$C_HEAD\1$C_OFF/" \
+ -e "s/^( )($c)($x|$)/\1$C_CMD\2$C_OFF\3/" \
+ -e ":a; s/(claude-remote |, |^usage: claude-remote \[)($c|COMMAND)($x|$)/\1$C_CMD\2$C_OFF\3/; ta" \
+ -e ":b; s/(^|$x)(--stop|-h|--help|JOURNALCTL-OPTION)($x|$)/\1$C_OPT\2$C_OFF\3/; tb" \
+ -e ":c; s/(^|$x)(NAME|OLD|NEW)($x|$)/\1$C_NAME\2$C_OFF\3/; tc"
+ }
die() {
- echo "claude-remote: $*" >&2
+ colors 2
+ printf 'claude-remote: %s\n' "$*" | paint >&2
exit 1
}
unit() {
@@ -349,11 +405,11 @@ let
for a; do
case $a in
--stop) stop=1 ;;
- -*) usage >&2; exit 1 ;;
+ -*) die "rename: $a: no such option (claude-remote -h)" ;;
*) args+=("$a")
esac
done
- test ''${#args[@]} = 2 || { usage >&2; exit 1; }
+ test ''${#args[@]} = 2 || die "rename OLD NEW [--stop] (claude-remote -h)"
do_rename "''${args[0]}" "''${args[1]}" "$stop"
;;
inspect)
@@ -401,11 +457,11 @@ let
names
;;
help | -h | --help)
- usage
+ colors 1
+ usage | paint
;;
*)
- usage >&2
- exit 1
+ die "$cmd: no such command (claude-remote -h)"
esac
'';