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:
+20
-3
@@ -186,15 +186,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Usernames + paths
|
||||
// Usernames + hostnames + paths
|
||||
if (id.enabled.usernames !== false) {
|
||||
const hostMap = new Map();
|
||||
for (const h of (id.hostnames || [])) {
|
||||
if (h.real && h.substitute) hostMap.set(h.real.toLowerCase(), h);
|
||||
}
|
||||
|
||||
for (const u of (id.usernames || [])) {
|
||||
if (!u.real || !u.substitute) continue;
|
||||
|
||||
// user@hostname
|
||||
// user@hostname (substitute both username and hostname if configured)
|
||||
result = result.replace(new RegExp(esc(u.real) + '@[a-zA-Z0-9._\\-]+', 'g'), (matched) => {
|
||||
const host = matched.slice(u.real.length + 1);
|
||||
const sub = u.substitute + '@' + host;
|
||||
const hostEntry = hostMap.get(host.toLowerCase());
|
||||
const subHost = hostEntry ? hostEntry.substitute : host;
|
||||
const sub = u.substitute + '@' + subHost;
|
||||
replacements.push({ original: matched, replaced: sub, category: 'username', pattern: 'smart' });
|
||||
return sub;
|
||||
});
|
||||
@@ -228,6 +235,16 @@
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Standalone hostname substitution
|
||||
for (const [, h] of hostMap) {
|
||||
if (h.real.length >= 3) {
|
||||
result = result.replace(new RegExp('\\b' + esc(h.real) + '\\b', 'gi'), (matched) => {
|
||||
replacements.push({ original: matched, replaced: h.substitute, category: 'hostname', pattern: 'smart' });
|
||||
return h.substitute;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { text: result, replacements };
|
||||
|
||||
@@ -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 };
|
||||
},
|
||||
|
||||
|
||||
@@ -74,7 +74,12 @@
|
||||
<span class="arrow">→</span>
|
||||
<input type="text" id="idUserSub" placeholder="ademo" class="input input-sm">
|
||||
</div>
|
||||
<div class="id-hint">Catches: jsmith@hostname, /home/jsmith, ~jsmith, C:\Users\jsmith</div>
|
||||
<div class="id-row">
|
||||
<input type="text" id="idHostReal" placeholder="macbook-pro" class="input input-sm">
|
||||
<span class="arrow">→</span>
|
||||
<input type="text" id="idHostSub" placeholder="mycomputer" class="input input-sm">
|
||||
</div>
|
||||
<div class="id-hint">Catches: jsmith@macbook-pro, /home/jsmith, ~jsmith, C:\Users\jsmith</div>
|
||||
</div>
|
||||
|
||||
<div class="id-section">
|
||||
|
||||
@@ -111,6 +111,11 @@ function loadIdentityForm() {
|
||||
$('#idUserReal').value = user.real || '';
|
||||
$('#idUserSub').value = user.substitute || '';
|
||||
}
|
||||
const host = (identity.hostnames || [])[0];
|
||||
if (host) {
|
||||
$('#idHostReal').value = host.real || '';
|
||||
$('#idHostSub').value = host.substitute || '';
|
||||
}
|
||||
if (phone) {
|
||||
$('#idPhoneReal').value = phone.real || '';
|
||||
$('#idPhoneSub').value = phone.substitute || '';
|
||||
@@ -144,6 +149,13 @@ async function saveIdentity() {
|
||||
usernames.push({ real: userReal, substitute: userSub });
|
||||
}
|
||||
|
||||
const hostnames = [];
|
||||
const hostReal = $('#idHostReal').value.trim();
|
||||
const hostSub = $('#idHostSub').value.trim();
|
||||
if (hostReal && hostSub) {
|
||||
hostnames.push({ real: hostReal, substitute: hostSub });
|
||||
}
|
||||
|
||||
const phones = [];
|
||||
const phoneReal = $('#idPhoneReal').value.trim();
|
||||
const phoneSub = $('#idPhoneSub').value.trim();
|
||||
@@ -155,6 +167,7 @@ async function saveIdentity() {
|
||||
names,
|
||||
emails,
|
||||
usernames,
|
||||
hostnames,
|
||||
phones,
|
||||
catchAllEmail: $('#idCatchAllEmail').value.trim(),
|
||||
emailDomains: identity.emailDomains || [],
|
||||
|
||||
Reference in New Issue
Block a user