Open killeik opened 4 weeks ago
open the index.js located in " /usr/lib/node_modules/alacritty-themes/"
and replace these code given below in the functions getCurrentTheme
and updateThemeWithFile
const imports = parsedAlacrittyConfig.import || [];
with
const imports = parsedAlacrittyConfig.general?.import || [];
and replace the conditional statement in updateThemeWithFile
function with
if (currentThemeIndex === undefined) {
parsedAlacrittyConfig.general = parsedAlacrittyConfig.general || {};
parsedAlacrittyConfig.general.import = [themePath];
} else {
parsedAlacrittyConfig.general.import[currentThemeIndex] = themePath;
}
So your two functions should be like this (Might as well copy and paste this code lol)
function getCurrentTheme(themesFolder) {
if (!alacrittyConfigPath()) {
console.log(
'No Alacritty configuration file found\nRun: `alacritty-themes -C` to create one'
);
exit(1);
}
const alacrittyConfig = fs.readFileSync(alacrittyConfigPath(), 'utf8');
const parsedAlacrittyConfig = TOML.parse(alacrittyConfig);
const imports = parsedAlacrittyConfig.general?.import || [];
// We'll consider the first theme import as the current theme
for (let i = 0; i < imports.length; i++) {
const relative = path.relative(themesFolder, imports[i]);
if (relative && !relative.startsWith('..') && !path.isAbsolute(relative)) {
return path.parse(imports[i]).name;
}
}
return 'default';
}
function updateThemeWithFile(themePath, themesPath, tomlPath, preview = false) {
const alacrittyConfig = fs.readFileSync(tomlPath, 'utf8');
const parsedAlacrittyConfig = TOML.parse(alacrittyConfig);
const imports = parsedAlacrittyConfig.general?.import || [];
let currentThemeIndex = undefined;
for (let i = 0; i < imports.length; i++) {
const relative = path.relative(themesPath, imports[i]);
if (relative && !relative.startsWith('..') && !path.isAbsolute(relative)) {
currentThemeIndex = i;
break;
}
}
if (currentThemeIndex === undefined) {
parsedAlacrittyConfig.general = parsedAlacrittyConfig.general || {};
parsedAlacrittyConfig.general.import = [themePath];
} else {
parsedAlacrittyConfig.general.import[currentThemeIndex] = themePath;
}
const newContent = TOML.stringify(parsedAlacrittyConfig);
const themeName = path.parse(themePath).name;
return fsPromises
.writeFile(tomlPath, newContent, 'utf8')
.then(() => {
if (!preview) {
console.log(`The theme "${themeName}" has been applied successfully!`);
}
})
.catch((err) => {
if (err) throw err;
});
}
Describe the bug
After alacritty update to 0.14.0 import=[] is deprecated, alacritty-themes need to set [general] and then import=[] in config file
To Reproduce
Steps to reproduce the behavior:
Expected behavior
alacritty-themes successfully adds to the config file:
But it should add:
Operating System:
Add your alacritty.yml content
it's toml btw:
Screenshots