detached e1b1a01

fix: improve pass token list parsing robustness

- Strip ANSI escape sequences from pass output (colored TTY output)
- Handle both Unicode and ASCII tree formatting characters
- Skip the header line (passTokenPath) in output
- Add extra TrimSpace after stripping prefixes

This fixes token listing when pass outputs colored text or uses
different tree-drawing characters depending on terminal settings.
commit
e1b1a01353acfd539dc5c3879afb7c951a7516f5
author
brice · · 2026-01-17 08:36 UTC
parent
7c3b292
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
1 file · +18 -3
M internal/adapters/out/tokenstore/pass.go +18 -3
@@ -6,6 +6,7 @@ import (
66 "encoding/json"
77 "fmt"
88 "os/exec"
9+ "regexp"
910 "strings"
1011 "time"
1112
@@ -14,6 +15,9 @@ import (
1415 "gordon/internal/domain"
1516 )
1617
18+// ansiRegex matches ANSI escape sequences for stripping from pass output.
19+var ansiRegex = regexp.MustCompile(`\x1b\[[0-9;]*m`)
20+
1721 const (
1822 // passTokenPath is the base path for tokens in pass.
1923 passTokenPath = "gordon/registry/tokens"
@@ -139,13 +143,24 @@ func (s *PassStore) ListTokens(ctx context.Context) ([]domain.Token, error) {
139143
140144 for _, line := range lines {
141145 line = strings.TrimSpace(line)
142- // Skip tree formatting characters and empty lines
146+
147+ // Strip ANSI escape sequences (pass outputs colored text on TTY)
148+ line = ansiRegex.ReplaceAllString(line, "")
149+
150+ // Skip tree formatting characters (both Unicode and ASCII variants)
151+ // Unicode: ├── └── │
143152 line = strings.TrimPrefix(line, "├── ")
144153 line = strings.TrimPrefix(line, "└── ")
145154 line = strings.TrimPrefix(line, "│ ")
155+ // ASCII: |-- `-- |
156+ line = strings.TrimPrefix(line, "|-- ")
157+ line = strings.TrimPrefix(line, "`-- ")
158+ line = strings.TrimPrefix(line, "| ")
159+
160+ line = strings.TrimSpace(line)
146161
147- // Skip .meta files and empty lines
148- if line == "" || strings.HasSuffix(line, ".meta") {
162+ // Skip .meta files, empty lines, and the header line
163+ if line == "" || strings.HasSuffix(line, ".meta") || line == passTokenPath {
149164 continue
150165 }
151166
@@ -6,6 +6,7 @@ import (
6 "encoding/json"6 "encoding/json"
7 "fmt"7 "fmt"
8 "os/exec"8 "os/exec"
9+ "regexp"
9 "strings"10 "strings"
10 "time"11 "time"
11 12
@@ -14,6 +15,9 @@ import (
14 "gordon/internal/domain"15 "gordon/internal/domain"
15 )16 )
16 17
18+// ansiRegex matches ANSI escape sequences for stripping from pass output.
19+var ansiRegex = regexp.MustCompile(`\x1b\[[0-9;]*m`)
20+
17 const (21 const (
18 // passTokenPath is the base path for tokens in pass.22 // passTokenPath is the base path for tokens in pass.
19 passTokenPath = "gordon/registry/tokens"23 passTokenPath = "gordon/registry/tokens"
@@ -139,13 +143,24 @@ func (s *PassStore) ListTokens(ctx context.Context) ([]domain.Token, error) {
139 143
140 for _, line := range lines {144 for _, line := range lines {
141 line = strings.TrimSpace(line)145 line = strings.TrimSpace(line)
142- // Skip tree formatting characters and empty lines146+
147+ // Strip ANSI escape sequences (pass outputs colored text on TTY)
148+ line = ansiRegex.ReplaceAllString(line, "")
149+
150+ // Skip tree formatting characters (both Unicode and ASCII variants)
151+ // Unicode: ├── └── │
143 line = strings.TrimPrefix(line, "├── ")152 line = strings.TrimPrefix(line, "├── ")
144 line = strings.TrimPrefix(line, "└── ")153 line = strings.TrimPrefix(line, "└── ")
145 line = strings.TrimPrefix(line, "│ ")154 line = strings.TrimPrefix(line, "│ ")
155+ // ASCII: |-- `-- |
156+ line = strings.TrimPrefix(line, "|-- ")
157+ line = strings.TrimPrefix(line, "`-- ")
158+ line = strings.TrimPrefix(line, "| ")
159+
160+ line = strings.TrimSpace(line)
146 161
147- // Skip .meta files and empty lines162+ // Skip .meta files, empty lines, and the header line
148- if line == "" || strings.HasSuffix(line, ".meta") {163+ if line == "" || strings.HasSuffix(line, ".meta") || line == passTokenPath {
149 continue164 continue
150 }165 }
151 166

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close