Skip to content

Instantly share code, notes, and snippets.

@JuanM04
Last active March 29, 2021 18:37
Show Gist options
  • Save JuanM04/aad9901ff70f7aed8abe1c976b248c77 to your computer and use it in GitHub Desktop.
Save JuanM04/aad9901ff70f7aed8abe1c976b248c77 to your computer and use it in GitHub Desktop.
Gitmoji commit template

Gitmoji Commit Template

You can generate a Commit Template for creating commits messages easier.

Steps

$ node gitmoji.js > your/commit/template.txt
$ git config --global commit.template your/commit/template.txt
// Only if you are using Node.js
const fetch = require("node-fetch");
async function main() {
const res = await fetch(
"https://raw.githubusercontent.com/carloscuesta/gitmoji/master/src/data/gitmojis.json"
);
let { gitmojis } = await res.json();
gitmojis = gitmojis.sort((a, b) =>
a.code < b.code ? -1 : a.code > b.code ? 1 : 0
);
let longestCode = 0;
let longestDescription = 0;
for (const { code, description } of gitmojis) {
if (code.length > longestCode) longestCode = code.length;
if (description.length > longestDescription)
longestDescription = description.length;
}
let lines = gitmojis.map(
({ emoji, code, description }) =>
` ${emoji} ${code}${" ".repeat(
longestCode - code.length
)} ${description}`
);
let longestLine = 0;
for (const line of lines) {
if (line.length > longestLine) longestLine = line.length;
}
const separator = "-".repeat(longestLine) + "--";
const file = [separator, "Gitmojis", separator, ...lines, separator]
.map((l) => `# ${l}`)
.join("\n");
console.log(file);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment