refactor(cli): ♻️ Introduce helper function to resolve CLI script paths and standardize path resolution across scripts
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
a654360dca
commit
5c9d05e4d0
1 changed files with 15 additions and 5 deletions
20
bin/rclaude
20
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() {
|
|||
# <host>\tdisk\t<cwd>\t<sessions=N, last used <relative-time>>
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue