Scaffold: Show current Git branch in title (#3834)

This commit is contained in:
Abe Jellinek 2024-03-12 01:33:03 -04:00 committed by GitHub
parent 844fd98c72
commit 5489b6cc4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -275,6 +275,8 @@ var Scaffold = new function () {
_lastModifiedTime = modifiedTime;
}
}
_updateTitle();
};
this.initImportEditor = function () {
@ -637,6 +639,7 @@ var Scaffold = new function () {
document.getElementById('textbox-label').focus();
_showTab('metadata');
_updateTitle();
};
/*
@ -727,6 +730,7 @@ var Scaffold = new function () {
Zotero.Prefs.set('scaffold.lastTranslatorID', translator.translatorID);
_updateTitle();
return true;
};
@ -2319,6 +2323,47 @@ var Scaffold = new function () {
}
return null;
}
async function _getGitBranchName() {
let gitPath = await Subprocess.pathSearch('git');
if (!gitPath) return null;
let dir = Scaffold_Translators.getDirectory();
if (!dir) return null;
let proc = await Subprocess.call({
command: gitPath,
arguments: ['rev-parse', '--abbrev-ref', 'HEAD'],
workdir: dir,
});
let output = '';
let chunk;
while ((chunk = await proc.stdout.readString())) {
output += chunk;
}
return output.trim();
}
async function _updateTitle() {
let title = 'Scaffold';
let label = document.getElementById('textbox-label').value;
if (label) {
title += ' - ' + label;
}
try {
let branch = await _getGitBranchName();
if (branch) {
title += ' (' + branch + ')';
}
}
catch (e) {
Zotero.logError(e);
}
document.title = title;
}
};
window.addEventListener("load", function (e) {