feat: add hostname substitution in user@host patterns

jsmith@macbook-pro now becomes ademo@mycomputer when both username
and hostname are configured in the Identity tab. Hostnames are also
caught standalone (e.g. just "macbook-pro" in text).

Also rewrites README with detailed step-by-step Mozilla API key
setup instructions for Firefox signing.

https://claude.ai/code/session_01Dvgwe7XMoSxnWXkih8p1Cw
This commit is contained in:
Claude
2026-03-26 00:15:26 +00:00
parent 387b22530b
commit 34f1131c23
5 changed files with 139 additions and 29 deletions
+26 -3
View File
@@ -222,13 +222,17 @@ const SmartPatterns = {
return { text: result, replacements };
},
// ----- Usernames -----
// ----- Usernames + Hostnames -----
// Catches: user@hostname, ~username, /home/username, mentions of username
// in shell/code contexts
// in shell/code contexts. Also substitutes hostnames independently.
_substituteUsernames(text, identity) {
const replacements = [];
let result = text;
const usernames = identity.usernames || [];
const hostMap = new Map();
for (const h of (identity.hostnames || [])) {
if (h.real && h.substitute) hostMap.set(h.real.toLowerCase(), h);
}
for (const u of usernames) {
if (!u.real || !u.substitute) continue;
@@ -240,7 +244,10 @@ const SmartPatterns = {
);
result = result.replace(userHostRegex, (matched) => {
const host = matched.slice(u.real.length + 1);
const sub = u.substitute + '@' + host;
// Also substitute hostname if configured
const hostEntry = hostMap.get(host.toLowerCase());
const subHost = hostEntry ? hostEntry.substitute : host;
const sub = u.substitute + '@' + subHost;
replacements.push({
original: matched,
replaced: sub,
@@ -279,6 +286,22 @@ const SmartPatterns = {
}
}
// Standalone hostname substitution (catches hostnames appearing on their own)
for (const [, h] of hostMap) {
if (h.real.length >= 3) {
const hostRegex = new RegExp('\\b' + esc(h.real) + '\\b', 'gi');
result = result.replace(hostRegex, (matched) => {
replacements.push({
original: matched,
replaced: h.substitute,
category: 'hostname',
pattern: 'smart-hostname',
});
return h.substitute;
});
}
}
return { text: result, replacements };
},