Skip to content

Instantly share code, notes, and snippets.

@AlanGreene
Forked from tigt/git-branch-to-favicon.js
Created April 5, 2020 13:34
Show Gist options
  • Save AlanGreene/4f1b9425d76b11b9085612166500cbc1 to your computer and use it in GitHub Desktop.
Save AlanGreene/4f1b9425d76b11b9085612166500cbc1 to your computer and use it in GitHub Desktop.
Creates an SVG string that can be used as a favicon across different Git branches. Actually getting this into the browser is sadly project-specific.
const { execSync } = require('child_process')
const { createHash } = require('crypto')
const invertColor = require('invert-color')
const branchName = execSync('git rev-parse --abbrev-ref HEAD')
const hash = createHash('sha256')
hash.update(branchName)
const color = '#' + hash.digest().toString('hex').substring(0, 6)
const invertedColor = invertColor(color, true)
module.exports = `<svg viewBox="0 0 64 64" font-size="64" font-family="monospace,monospace" xmlns="http://www.w3.org/2000/svg">
<rect width="64" height="64" fill="${color}"/>
<text y="64" textLength="64" lengthAdjust="spacingAndGlyphs"
fill="${invertedColor}">${branchName.substring(0, 4)}</text>
</svg>`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment