// Formatting helpers for panel and menu labels. import GLib from 'gi://GLib'; /** Compact age: "45s", "12m", "2h 5m". Seconds only below a minute, because * the panel is glanced at, not read. */ export function formatAge(seconds) { const s = Math.max(0, Math.floor(seconds)); if (s < 60) return `${s}s`; const m = Math.floor(s / 60); if (m < 60) return `${m}m`; const h = Math.floor(m / 60); return `${h}h ${m % 60}m`; } /** Last path segment, with ~ collapsed. Two worktrees of one repo share a * basename, so this is a panel-only label; menus show the full path. */ export function projectName(path) { if (!path) return '?'; const trimmed = path.replace(/\/+$/, ''); const base = trimmed.split('/').pop(); return base || trimmed || '?'; } /** Full path with the home directory shortened to "~". */ export function shortenHome(path) { if (!path) return ''; const home = GLib.get_home_dir(); if (home && path.startsWith(home)) return `~${path.slice(home.length)}`; return path; }