From 5489b6cc4b204f8530a58b400fc818fcaec61211 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Tue, 12 Mar 2024 01:33:03 -0400 Subject: [PATCH] Scaffold: Show current Git branch in title (#3834) --- chrome/content/scaffold/scaffold.js | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/chrome/content/scaffold/scaffold.js b/chrome/content/scaffold/scaffold.js index 9013728f1a..fbb12e195d 100644 --- a/chrome/content/scaffold/scaffold.js +++ b/chrome/content/scaffold/scaffold.js @@ -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) {