fix: extract title column from hermes sessions list, strip [Project] prefix for pre-fill

The hermes sessions list format is:
  Title    Preview    Last Active   ID

Session display (menu) = full line including Title+Preview+Time
Title pre-fill = first column only, [Project] prefix stripped

- Use split-string with 3+ whitespace to extract first column
- No longer try to strip source/timestamp from 'before'
- Cleaner titles alist: sid -> clean-title without project prefix
This commit is contained in:
2026-07-18 18:51:43 -04:00
parent 104a7b0764
commit 47d26a6a8d
3 changed files with 54 additions and 69 deletions

1
doom/.config/doom/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.bak

View File

@@ -993,7 +993,7 @@ Broken for now..
(truncate p1) (1+ (truncate p2)) nil (truncate p1) (1+ (truncate p2)) nil
`(priority ,(setq elgantt-user-set-color-priority-counter `(priority ,(setq elgantt-user-set-color-priority-counter
(1- elgantt-user-set-color-priority-counter)) (1- elgantt-user-set-color-priority-counter))
:elgantt-user-overlay ,elgantt-org-id))))))))))) :elgantt-user-overlay ,elgantt-org-id))))))))))
;; --- Rule 3: Blocker Lines --- ;; --- Rule 3: Blocker Lines ---
(elgantt-create-display-rule draw-blocker-lines (elgantt-create-display-rule draw-blocker-lines
@@ -2175,35 +2175,31 @@ If SESSION-ID is empty, show a menu of recent sessions to browse."
(if (string-empty-p id) (if (string-empty-p id)
(let* ((output (shell-command-to-string "hermes sessions list --limit 50 2>&1")) (let* ((output (shell-command-to-string "hermes sessions list --limit 50 2>&1"))
(lines (split-string output "\n" t)) (lines (split-string output "\n" t))
(data-lines (nthcdr 2 lines)) ; skip header + separator (data-lines (nthcdr 2 lines))
(id-re "[0-9]\\{8\\}_[0-9]\\{6\\}_[a-f0-9]\\{6\\}") (id-regex "[0-9]\\{8\\}_[0-9]\\{6\\}_[a-f0-9]\\{6\\}")
(items (delq nil (sessions (delq nil
(mapcar (lambda (line) (mapcar
(when (string-match (concat id-re "$") line) (lambda (line)
(let* ((id (match-string 0 line)) (when (string-match (concat id-regex "$") line)
(before-id (substring line 0 (match-beginning 0))) (let* ((sid (match-string 0 line))
(full-preview (string-trim (before (substring line 0 (match-beginning 0))))
(replace-regexp-in-string (list (string-trim before) sid))))
"\\s-+[a-z][a-z0-9]*\\s-*$" "" before-id)))) data-lines)))
(cons full-preview id))) (items (mapcar (lambda (s) (cons (car s) (cadr s))) sessions))
data-lines))
(titles (delq nil (titles (delq nil
(mapcar (lambda (line) (mapcar
(when (string-match (concat id-re "$") line) (lambda (s)
(let* ((id (match-string 0 line)) (let* ((sid (cadr s))
(before-id (substring line 0 (match-beginning 0))) (full (car s))
(full (string-trim (title (car (split-string full "\\s-\\{3,\\}" t)))
(replace-regexp-in-string
"\\s-+[a-z][a-z0-9]*\\s-*$" "" before-id)))
(clean (string-trim (clean (string-trim
(replace-regexp-in-string (replace-regexp-in-string
"\\s-+\\(just now\\|[0-9]+[mhd] ago\\|[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\)$" "^\\[[^]]+\\]\\s-+" "" title))))
"" full)))) (when sid (cons sid clean))))
(cons id clean))) sessions))))
data-lines))))
(if (null items) (if (null items)
(user-error "No recent sessions found") (user-error "No recent sessions found")
(let* ((vertico-sort-function 'identity) ; keep vertico, no re-sort (let* ((vertico-sort-function 'identity)
(choice (completing-read "Session: " items nil t)) (choice (completing-read "Session: " items nil t))
(sid (cdr (assoc choice items))) (sid (cdr (assoc choice items)))
(default-title (cdr (assoc sid titles)))) (default-title (cdr (assoc sid titles))))
@@ -2213,10 +2209,6 @@ If SESSION-ID is empty, show a menu of recent sessions to browse."
(gortium/hermes--rename-session id (format "[%s] %s" name title)) (gortium/hermes--rename-session id (format "[%s] %s" name title))
(gortium/hermes-append-session sfile id title) (gortium/hermes-append-session sfile id title)
(message "Session %s linked to project %s as \"%s\"" id name title))) (message "Session %s linked to project %s as \"%s\"" id name title)))
;; -------------------------------------------------------------------
;; Keybindings (under SPC p)
;; -------------------------------------------------------------------
(map! :leader (map! :leader
:desc "New Hermes session" "p h" #'gortium/hermes-start :desc "New Hermes session" "p h" #'gortium/hermes-start
:desc "Resume Hermes session" "p H" #'gortium/hermes-resume :desc "Resume Hermes session" "p H" #'gortium/hermes-resume

View File

@@ -1371,35 +1371,31 @@ If SESSION-ID is empty, show a menu of recent sessions to browse."
(if (string-empty-p id) (if (string-empty-p id)
(let* ((output (shell-command-to-string "hermes sessions list --limit 50 2>&1")) (let* ((output (shell-command-to-string "hermes sessions list --limit 50 2>&1"))
(lines (split-string output "\n" t)) (lines (split-string output "\n" t))
(data-lines (nthcdr 2 lines)) ; skip header + separator (data-lines (nthcdr 2 lines))
(id-re "[0-9]\\{8\\}_[0-9]\\{6\\}_[a-f0-9]\\{6\\}") (id-regex "[0-9]\\{8\\}_[0-9]\\{6\\}_[a-f0-9]\\{6\\}")
(items (delq nil (sessions (delq nil
(mapcar (lambda (line) (mapcar
(when (string-match (concat id-re "$") line) (lambda (line)
(let* ((id (match-string 0 line)) (when (string-match (concat id-regex "$") line)
(before-id (substring line 0 (match-beginning 0))) (let* ((sid (match-string 0 line))
(full-preview (string-trim (before (substring line 0 (match-beginning 0))))
(replace-regexp-in-string (list (string-trim before) sid))))
"\\s-+[a-z][a-z0-9]*\\s-*$" "" before-id)))) data-lines)))
(cons full-preview id))) (items (mapcar (lambda (s) (cons (car s) (cadr s))) sessions))
data-lines))
(titles (delq nil (titles (delq nil
(mapcar (lambda (line) (mapcar
(when (string-match (concat id-re "$") line) (lambda (s)
(let* ((id (match-string 0 line)) (let* ((sid (cadr s))
(before-id (substring line 0 (match-beginning 0))) (full (car s))
(full (string-trim (title (car (split-string full "\\s-\\{3,\\}" t)))
(replace-regexp-in-string
"\\s-+[a-z][a-z0-9]*\\s-*$" "" before-id)))
(clean (string-trim (clean (string-trim
(replace-regexp-in-string (replace-regexp-in-string
"\\s-+\\(just now\\|[0-9]+[mhd] ago\\|[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\)$" "^\\[[^]]+\\]\\s-+" "" title))))
"" full)))) (when sid (cons sid clean))))
(cons id clean))) sessions))))
data-lines))))
(if (null items) (if (null items)
(user-error "No recent sessions found") (user-error "No recent sessions found")
(let* ((vertico-sort-function 'identity) ; keep vertico, no re-sort (let* ((vertico-sort-function 'identity)
(choice (completing-read "Session: " items nil t)) (choice (completing-read "Session: " items nil t))
(sid (cdr (assoc choice items))) (sid (cdr (assoc choice items)))
(default-title (cdr (assoc sid titles)))) (default-title (cdr (assoc sid titles))))
@@ -1409,10 +1405,6 @@ If SESSION-ID is empty, show a menu of recent sessions to browse."
(gortium/hermes--rename-session id (format "[%s] %s" name title)) (gortium/hermes--rename-session id (format "[%s] %s" name title))
(gortium/hermes-append-session sfile id title) (gortium/hermes-append-session sfile id title)
(message "Session %s linked to project %s as \"%s\"" id name title))) (message "Session %s linked to project %s as \"%s\"" id name title)))
;; -------------------------------------------------------------------
;; Keybindings (under SPC p)
;; -------------------------------------------------------------------
(map! :leader (map! :leader
:desc "New Hermes session" "p h" #'gortium/hermes-start :desc "New Hermes session" "p h" #'gortium/hermes-start
:desc "Resume Hermes session" "p H" #'gortium/hermes-resume :desc "Resume Hermes session" "p H" #'gortium/hermes-resume