Skip to content

Instantly share code, notes, and snippets.

@eugenk
Last active May 23, 2024 05:39
Show Gist options
  • Select an option

  • Save eugenk/adc2d7dc5300b0dba80da7f962632381 to your computer and use it in GitHub Desktop.

Select an option

Save eugenk/adc2d7dc5300b0dba80da7f962632381 to your computer and use it in GitHub Desktop.
Create Gitmoji Pager for Git CLI
#!/usr/bin/env node
/**
* This script gives you a git pager that translates gitmoji to emoji in your
* terminal. This displays actual emojis in the terminal, so only use this with
* a terminal application that supports it (e.g. iterm2).
*
* Make this file executable. Adjust the `targetFile` in the first JS-line.
* When you execute this file, it will populate the `targetFile` with a pager
* script.
*
* The resulting pager script replaces all :gitmoji: text with the actual emoji.
*
* To enable the pager for your git installation, run
* git config --global core.pager PATH_TO_THE_targetFile
*/
const targetFile = `${__dirname}/gitmoji-pager`;
const fs = require("node:fs/promises");
(async () => {
const gitmojiJson = await (
await fetch(
"https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json"
)
).json();
let pagerScript = `#!/bin/zsh
exec awk '${gitmojiJson.gitmojis
.map(({ name, emoji }) => `gsub(":${name}:", "${emoji}")`)
.join(" ")}'
| less
`;
await fs.writeFile(targetFile, pagerScript);
await fs.chmod(targetFile, "755");
})();
@eugenk
Copy link
Author

eugenk commented May 16, 2024

The resulting pager changes the first output to the second output:
Screenshot 2024-05-16 at 08 39 12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment