web: abbreviate the home directory in chat group labels

Use ~ for the server home prefix in directory bands and row meta, with the
full path still in the band's tooltip. Keeps long repository paths readable
inside the centred collapsible header.
This commit is contained in:
2026-10-20 14:39:15 +01:00
parent 3799d37d7c
commit f982c0b712
5 changed files with 65 additions and 10 deletions
+26
View File
@@ -917,6 +917,32 @@ export function directoryLabel(directory) {
return isBlank(directory) ? NO_DIRECTORY_LABEL : str(directory);
}
/**
* The home prefix shared by the server's reported directories, or "" when none
* looks like a user home. The server always returns home first in
* chat_directories; session paths are the fallback so the list can abbreviate
* before the create picker has ever been opened. macOS /Users/<name>, Linux
* /home/<name> and /root are recognised; any other absolute path is left alone.
*/
export function homeDirectoryFor(paths) {
for (const value of paths ?? []) {
const match = str(value).match(/^(\/Users\/[^/]+|\/home\/[^/]+|\/root)(?=\/|$)/);
if (match) return match[1];
}
return "";
}
/** Replace [home] and its descendants with `~` for a compact directory label. */
export function abbreviateHome(path, home) {
const directory = str(path).trim();
if (isBlank(directory)) return directory;
const prefix = str(home).trim().replace(/\/+$/, "");
if (prefix === "" || prefix === "~") return directory;
if (directory === prefix) return "~";
if (directory.startsWith(prefix + "/")) return `~${directory.slice(prefix.length)}`;
return directory;
}
// ---------------------------------------------------------------------------
// The create flow's directory choices (ChatDirectories.kt)
// ---------------------------------------------------------------------------