Last active
May 23, 2024 05:39
-
-
Save eugenk/adc2d7dc5300b0dba80da7f962632381 to your computer and use it in GitHub Desktop.
Create Gitmoji Pager for Git CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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"); | |
| })(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The resulting pager changes the first output to the second output:
