feat(@scripts): ✨ add session archiving feature for hiding sessions
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
c6927d4ae8
commit
3f7c9ecbfc
1 changed files with 47 additions and 1 deletions
48
bin/rclaude
48
bin/rclaude
|
|
@ -358,6 +358,12 @@ _SSH_LIVE_OPTS='-o ServerAliveInterval=30 -o ServerAliveCountMax=6 -o TCPKeepAli
|
|||
# Cache dir for per-host setup markers. A marker file means we've already
|
||||
# probed + installed deps on that host within RCLAUDE_SETUP_TTL days.
|
||||
_SETUP_CACHE_DIR=${XDG_CACHE_HOME:-$HOME/.cache}/rclaude
|
||||
|
||||
# Archive: per-user list of session UUIDs to hide from `rclaude resume`. One
|
||||
# uuid per line. Populated via the picker's `-` key (then a selection key).
|
||||
_ARCHIVE_FILE=${XDG_DATA_HOME:-$HOME/.local/share}/rclaude/archived-uuids
|
||||
mkdir -p "$(dirname "$_ARCHIVE_FILE")" 2>/dev/null
|
||||
[ -f "$_ARCHIVE_FILE" ] || touch "$_ARCHIVE_FILE" 2>/dev/null
|
||||
_SETUP_TTL_DAYS=${RCLAUDE_SETUP_TTL:-7}
|
||||
|
||||
# Detect package-manager family on <host>. Output: macos | rhel | debian | unknown.
|
||||
|
|
@ -700,6 +706,13 @@ cmd_resume() {
|
|||
_matches=$(scan_hosts | while IFS= read -r h; do deep_search_on "$h" "$_pattern"; done | dedupe_sessions)
|
||||
fi
|
||||
fi
|
||||
# Filter out archived UUIDs (added via picker `-` key, see below).
|
||||
if [ -s "$_ARCHIVE_FILE" ]; then
|
||||
_matches=$(printf '%s\n' "$_matches" | awk -F'\t' -v af="$_ARCHIVE_FILE" '
|
||||
BEGIN { while ((getline u < af) > 0) arch[u]=1; close(af) }
|
||||
($2 == "tmux") || !($3 in arch)
|
||||
')
|
||||
fi
|
||||
_count=0
|
||||
[ -n "$_matches" ] && _count=$(printf '%s\n' "$_matches" | wc -l | tr -d ' ')
|
||||
if [ "$_count" -eq 0 ]; then
|
||||
|
|
@ -793,6 +806,9 @@ cmd_resume() {
|
|||
if ($2 == "session") return $4 " " c_dim "[" substr($3,1,8) "]" r
|
||||
return $3
|
||||
}
|
||||
# Col B: the explicit `claude -n` display name (NF). Blank when
|
||||
# the session was never named — col C (dir) carries the project
|
||||
# identity in that case.
|
||||
function name_col() { return ($2=="tmux") ? "" : $NF }
|
||||
{
|
||||
printf "%s%-10s%s %s%-22s%s %s%-22s%s %s",
|
||||
|
|
@ -835,10 +851,40 @@ cmd_resume() {
|
|||
"$_Cdim" "$_d_room" "$_d_total" "$_R" >&2
|
||||
fi
|
||||
_last_key=$(printf %s "$_keys" | cut -c"$_count")
|
||||
printf '%sselect [1-%s] (q to cancel):%s ' "$_Ckey" "$_last_key" "$_R" >&2
|
||||
printf '%sselect [1-%s] (- archive, q cancel):%s ' "$_Ckey" "$_last_key" "$_R" >&2
|
||||
_old=$(stty -g 2>/dev/null || true)
|
||||
stty -icanon -echo min 1 time 0 2>/dev/null || true
|
||||
_key=$(dd bs=1 count=1 2>/dev/null </dev/tty || true)
|
||||
# Archive flow: `-` triggers a second prompt; the row at that key's
|
||||
# index gets its uuid appended to $_ARCHIVE_FILE so future
|
||||
# `rclaude resume` invocations hide it.
|
||||
if [ "$_key" = "-" ]; then
|
||||
printf '%sarchive which [1-%s]:%s ' "$_Ckey" "$_last_key" "$_R" >&2
|
||||
_key=$(dd bs=1 count=1 2>/dev/null </dev/tty || true)
|
||||
[ -n "$_old" ] && stty "$_old" 2>/dev/null || true
|
||||
printf '%s\n' "$_key" >&2
|
||||
_idx=0; _c=1
|
||||
while [ "$_c" -le "$_count" ]; do
|
||||
if [ "$(printf %s "$_keys" | cut -c"$_c")" = "$_key" ]; then
|
||||
_idx=$_c; break
|
||||
fi
|
||||
_c=$((_c + 1))
|
||||
done
|
||||
if [ "$_idx" -eq 0 ]; then
|
||||
echo "rclaude: invalid selection: '$_key'" >&2; exit 1
|
||||
fi
|
||||
_row=$(printf '%s\n' "$_matches" | sed -n "${_idx}p")
|
||||
_au=$(printf %s "$_row" | awk -F'\t' '{print $3}')
|
||||
_akind=$(printf %s "$_row" | awk -F'\t' '{print $2}')
|
||||
if [ "$_akind" = "tmux" ]; then
|
||||
echo "rclaude: can't archive a live tmux row — kill the session instead (tmux kill-session)" >&2
|
||||
exit 1
|
||||
fi
|
||||
printf '%s\n' "$_au" >> "$_ARCHIVE_FILE"
|
||||
printf 'rclaude: archived %s (hidden from future resume lists; edit %s to undo)\n' \
|
||||
"$(printf %s "$_au" | cut -c1-8)" "$_ARCHIVE_FILE" >&2
|
||||
exit 0
|
||||
fi
|
||||
[ -n "$_old" ] && stty "$_old" 2>/dev/null || true
|
||||
# Render the keystroke we just consumed. Empty (EOF), Enter, Esc, q,
|
||||
# and Ctrl-C all mean "cancel" — just exit cleanly.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue