Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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')
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="">
<rect width="64" height="64" fill="${color}"/>
<text y="64" textLength="64" lengthAdjust="spacingAndGlyphs"
fill="${invertedColor}">${branchName.substring(0, 4)}</text>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment