From 5c9d05e4d030d9fb99792332d5cc5efa310b6c8b Mon Sep 17 00:00:00 2001 From: autocommit Date: Sun, 26 Apr 2026 21:06:05 -0700 Subject: [PATCH] =?UTF-8?q?refactor(cli):=20=E2=99=BB=EF=B8=8F=20Introduce?= =?UTF-8?q?=20helper=20function=20to=20resolve=20CLI=20script=20paths=20an?= =?UTF-8?q?d=20standardize=20path=20resolution=20across=20scripts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- bin/rclaude | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/bin/rclaude b/bin/rclaude index d79c474..f4e22cc 100755 --- a/bin/rclaude +++ b/bin/rclaude @@ -31,6 +31,19 @@ set -eu # Helpers # --------------------------------------------------------------------------- +# Resolve $0 to its real path, correctly handling relative symlinks at each hop. +resolve_self() { + _rs=$0 + while [ -L "$_rs" ]; do + _link=$(readlink "$_rs") + case "$_link" in + /*) _rs="$_link" ;; + *) _rs="$(dirname "$_rs")/$_link" ;; + esac + done + printf '%s' "$_rs" +} + is_local() { case $1 in local|localhost|127.0.0.1|::1) return 0 ;; @@ -66,8 +79,7 @@ list_tmux_on() { # \tdisk\t\t> list_disk_on() { _host=$1 - _self=$0; while [ -L "$_self" ]; do _self=$(readlink "$_self"); done - _helper_dir=$(dirname "$_self") + _helper_dir=$(dirname "$(resolve_self)") if is_local "$_host"; then _raw=$("$_helper_dir/_claude-projects" 2>/dev/null || true) else @@ -167,9 +179,7 @@ cmd_resume() { # --------------------------------------------------------------------------- cmd_version() { - # Resolve symlink → real script → repo root. - _self=$0 - while [ -L "$_self" ]; do _self=$(readlink "$_self"); done + _self=$(resolve_self) _repo=$(cd "$(dirname "$_self")/.." 2>/dev/null && pwd) if [ -d "$_repo/.git" ] && command -v git >/dev/null 2>&1; then _sha=$(git -C "$_repo" rev-parse --short HEAD 2>/dev/null)