diff --git a/src/web/public/constants.js b/src/web/public/constants.js index 2d65ad1c..71995cbd 100644 --- a/src/web/public/constants.js +++ b/src/web/public/constants.js @@ -2163,7 +2163,9 @@ const FOLDER_PATH_LINK_PATTERN = * without a slash at the end is prose, not a folder. */ function folderLinkPath(candidate) { - const path = String(candidate || '').replace(/[.,:;!?'"]+$/, ''); + // `$` and `#` too: a shell prompt (`user@host:~/proj$ `, `root@c:/app# `) ends + // its cwd with one. A folder whose name really ends in one links one short. + const path = String(candidate || '').replace(/[.,:;!?'"$#]+$/, ''); if (!path || path === '~/' || /^\/[^/]+\/$/.test(path)) return null; if (path.endsWith('/')) return /[^/.]/.test(path) ? path : null; if (!path.startsWith('/') && !path.startsWith('~/')) return null; diff --git a/test/file-path-link-forms.test.ts b/test/file-path-link-forms.test.ts index 3399873c..3e6f23a5 100644 --- a/test/file-path-link-forms.test.ts +++ b/test/file-path-link-forms.test.ts @@ -90,6 +90,11 @@ describe('findFilePathLinks', () => { expect(paths('see src/a.ts:120.')).toEqual(['src/a.ts']); }); + it("keeps a shell prompt's trailing `$` or `#` out of the folder it links", () => { + expect(paths('arkon@tnode:~/default/claudeman$ ls')).toEqual(['~/default/claudeman']); + expect(paths('root@c:/workspace/app# ls')).toEqual(['/workspace/app']); + }); + it('still finds rooted absolute paths, and never a relative path inside one', () => { expect(paths('sign-off from /mnt/raid1/x/refs/look_montage.png.')).toEqual(['/mnt/raid1/x/refs/look_montage.png']); // Unknown root: not linked at all (no `nix/store/…` cut out of it).