]> git.ekhem.eu.org Git - guix.git/commitdiff
status-line: show abbreviated worktree as prefix instead of suffix
authorJakub Czajka <jakub@ekhem.eu.org>
Sun, 2 Aug 2026 09:14:39 +0000 (09:14 +0000)
committerJakub Czajka <jakub@ekhem.eu.org>
Mon, 24 Aug 2026 15:04:04 +0000 (15:04 +0000)
Co-Authored-By: Claude <noreply@anthropic.com>
.claude/hooks/status-line

index e36628de2122b007e5515ccbf9a58706b8c7aff2..2eabd9dcab0fa0773ef94ae1566a320f8a8ce9d2 100755 (executable)
@@ -19,8 +19,12 @@ fi
 
 GIT_BIN="$HOME/.guix-profile/bin/git"
 
+# Determine worktree state and compute an abbreviated name
+# (first 7 characters of the session ID, like a git short hash).
+wt_abbrev=""
 if echo "$PWD" | $GUIX_BIN/grep -q '/worktrees/'; then
-    echo "🌿 $CLAUDE_CODE_SESSION_ID"
+    wt_abbrev=$(echo "$CLAUDE_CODE_SESSION_ID" | $GUIX_BIN/cut -c1-7)
+    echo "🌿 $wt_abbrev"
 else
     if [ -x "$GIT_BIN" ]; then
         branch=$($GIT_BIN -C "$PWD" branch --show-current 2>/dev/null)
@@ -48,16 +52,18 @@ if [ -n "$agent_id" ] && [ -x "$PASEO" ]; then
         | $GUIX_BIN/sed \
             's/.*"Name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/')
 
-    if echo "$PWD" | $GUIX_BIN/grep -q '/worktrees/'; then
-        suffix="🌿 $CLAUDE_CODE_SESSION_ID"
-        if ! echo "$current_name" | $GUIX_BIN/grep -qF "$suffix"; then
+    if [ -n "$wt_abbrev" ]; then
+        # In a worktree: prepend the abbreviation as prefix.
+        prefix="🌿 $wt_abbrev"
+        if ! echo "$current_name" | $GUIX_BIN/grep -qF "$prefix"; then
             "$PASEO" agent update "$agent_id" \
-                --name "$current_name $suffix" >/dev/null 2>&1
+                --name "$prefix $current_name" >/dev/null 2>&1
         fi
     else
+        # Outside a worktree: strip any worktree prefix.
         if echo "$current_name" | $GUIX_BIN/grep -q '🌿'; then
             clean_name=$(echo "$current_name" \
-                | $GUIX_BIN/sed 's/ ðŸŒ¿ [a-f0-9-]*$//')
+                | $GUIX_BIN/sed 's/^🌿 [a-f0-9]\{1,8\} //')
             "$PASEO" agent update "$agent_id" \
                 --name "$clean_name" >/dev/null 2>&1
         fi