TemplateProcessor: fix emacs template logic

This commit is contained in:
Ly-sec
2025-11-30 12:20:11 +01:00
parent 9266ccfec4
commit ca04156375

View File

@@ -2,6 +2,8 @@ pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
import Quickshell.Io
import qs.Commons
import qs.Services.System
@@ -127,15 +129,18 @@ Singleton {
}
} else if (app.id === "emacs" && app.checkDoomFirst) {
if (Settings.data.templates.emacs) {
const doomPath = app.outputs[0].path;
const standardPath = app.outputs[1].path;
const doomConfigDir = "~/.config/doom";
const standardDir = standardPath.substring(0, standardPath.lastIndexOf('/'));
const homeDir = Quickshell.env("HOME");
const doomPathTemplate = app.outputs[0].path; // ~/.config/doom/themes/noctalia-theme.el
const standardPathTemplate = app.outputs[1].path; // ~/.emacs.d/themes/noctalia-theme.el
const doomPath = doomPathTemplate.replace("~", homeDir);
const standardPath = standardPathTemplate.replace("~", homeDir);
const doomConfigDir = `${homeDir}/.config/doom`;
const doomDir = doomPath.substring(0, doomPath.lastIndexOf('/'));
lines.push(`\n[templates.emacs]`);
lines.push(`input_path = "${Quickshell.shellDir}/Assets/MatugenTemplates/${app.input}"`);
lines.push(`output_path = "${doomPath}"`);
lines.push(`post_hook = "sh -c 'if [ ! -d \\"${doomConfigDir}\\" ]; then mkdir -p \\"${standardDir}\\" && mv \\"${doomPath}\\" \\"${standardPath}\\" ; fi'"`);
lines.push(`output_path = "${standardPathTemplate}"`);
lines.push(`post_hook = "sh -c 'if [ -d \\"${doomConfigDir}\\" ]; then mkdir -p \\"${doomDir}\\" && mv \\"${standardPath}\\" \\"${doomPath}\\" && rmdir \\"${homeDir}/.emacs.d/themes\\" 2>/dev/null; rmdir \\"${homeDir}/.emacs.d\\" 2>/dev/null; fi'"`);
}
} else {
// Handle regular apps
@@ -276,12 +281,13 @@ Singleton {
if (app.id === "emacs" && app.checkDoomFirst) {
const doomPath = app.outputs[0].path.replace("~", homeDir);
const doomDir = doomPath.substring(0, doomPath.lastIndexOf('/'));
const doomConfigDir = doomDir.substring(0, doomDir.lastIndexOf('/')); // ~/.config/doom
const standardPath = app.outputs[1].path.replace("~", homeDir);
const standardDir = standardPath.substring(0, standardPath.lastIndexOf('/'));
const templatePath = `${Quickshell.shellDir}/Assets/MatugenTemplates/${app.input}`;
script += `\n`;
script += `if [ -d "${doomDir}" ]; then\n`;
script += `if [ -d "${doomConfigDir}" ]; then\n`;
script += ` mkdir -p ${doomDir}\n`;
script += ` cp '${templatePath}' '${doomPath}'\n`;
script += replaceColorsInFile(doomPath, palette);