dotfiles bugabingas dorkfiles
owned by bugabinga
README Source History Refs Compare Notes Search Review guide feat(pi): add nerdfont icons skill
322157c54615b06ae6a51f3e5c58f4fcc14a95ad
Oliver Jan Krylow <oliver@bugabinga.net > · 20 May 2026
unsigned
Browse files Compare with HEAD
Changed files (3) pi/agent/skills/nerdfont-icons/SKILL.md Added new file mode 100644 3 + description: Resolve Nerd Font nf-* names to verified code points, glyphs, and dev-language escapes. Use when matching Nerd Font icons to hex/Unicode/JS/CSS/HTML/etc.
5 + compatibility: "Requires Node.js 18+ with fetch"
10 + Never guess. Use script.
13 + node scripts/get-nerdfont-codepoint.js
< query
> [ format
] 19 + hex codepoint glyph js html java json-escape css css-content
20 + python rust go c cpp swift lua shell printf toml yaml vim elisp wezterm
27 + node scripts/get-nerdfont-codepoint.js nf-md-brain all
28 + node scripts/get-nerdfont-codepoint.js brain all
29 + node scripts/get-nerdfont-codepoint.js nf-cod-account wezterm
34 + - Do not read DB unless debugging.
35 + - DB: `references/nerdfont-icons.txt.br` Brotli text, `name<TAB>hex`.
36 + - Empty result → auto-refresh from Nerd Fonts cheat sheet → retry.
37 + - Multiple results → show choices; do not invent.
pi/agent/skills/nerdfont-icons/references/nerdfont-icons.txt.br Added new file mode 100644Current version contains binary or non-UTF-8 data.
pi/agent/skills/nerdfont-icons/scripts/get-nerdfont-codepoint.js Added new file mode 100755 4 + const fs
= require (
"node:fs" );
5 + const path
= require (
"node:path" );
6 + const zlib
= require (
"node:zlib" );
8 + const URL
= "https://www.nerdfonts.com/cheat-sheet?q=nf" ;
9 + const ROOT
= path.resolve(
__dirname ,
".." );
10 + const DB
= path.join(ROOT,
"references" ,
"nerdfont-icons.txt.br" );
11 + const FORMATS
= new Set ([
12 + "hex" ,
"codepoint" ,
"glyph" ,
"json" ,
"all" ,
13 + "js" ,
"html" ,
"java" ,
"json-escape" ,
"css" ,
"css-content" ,
14 + "python" ,
"rust" ,
"go" ,
"c" ,
"cpp" ,
"swift" ,
"lua" ,
"shell" ,
"printf" ,
15 + "toml" ,
"yaml" ,
"vim" ,
"elisp" ,
"wezterm" ,
18 + function usage (exitCode
= 2 ) {
19 + const msg
= `usage: node scripts/get-nerdfont-codepoint.js <query> [format]\n\nformat enum:\n hex eb99\n codepoint U+EB99\n glyph actual glyph char\n js \\u{EB99}\n html \n java \\uEB99 or surrogate pair\n json-escape \\uEB99 or surrogate pair\n css \\EB99\n css-content content: "\\EB99";\n python \\U0000EB99\n rust \\u{EB99}\n go \\U0000EB99\n c|cpp \\U0000EB99\n swift \\u{EB99}\n lua utf8.char(0xEB99)\n shell $'\\U0000EB99'\n printf printf '\\U0000EB99\\n'\n toml|yaml \\U0000EB99\n vim nr2char(0xEB99)\n elisp (string #xEB99)\n wezterm wezterm.nerdfonts.cod_account\n json { name, hex, ... }\n all name<TAB>hex<TAB>codepoint<TAB>glyph\n\nflags:\n --refresh update references/nerdfont-icons.txt\n` ;
20 + (exitCode
? console .
error : console .
log )(msg);
21 + process .
exit (exitCode);
25 + if (
! fs.existsSync(DB))
return [];
26 + const raw
= fs.readFileSync(DB);
27 + const text
= zlib.brotliDecompressSync(raw).
toString (
"utf8" );
32 + const [name, hex]
= line.split(
/\s + / );
33 + return name
&& hex
? { name, hex: hex.toLowerCase() }
: null ;
38 + async function fetchText (url) {
39 + const res
= await fetch(url, { headers: {
"user-agent" :
"pi-nerdfont-icons-skill" } });
40 + if (
! res.ok)
throw new Error (
`fetch failed: ${res.status}
${res.statusText}
` );
41 + return await res.text();
44 + async function refreshDb () {
45 + const html
= await fetchText(URL);
46 + const match
= html.match(
/const glyphs = \{([\s\S] *? )\n\}\n<\/script>/ );
47 + if (
! match)
throw new Error (
"glyph table not found" );
49 + const entries
= [
... match[
1 ].matchAll(
/"([ ^ "] + )"\s * :\s * "([0-9a-fA-F] + )"/ g )]
50 + .map((m)
=> [m[
1 ], m[
2 ].toLowerCase()]);
51 + const lines
= entries
52 + .filter(([name])
=> name.startsWith(
"nf-" ))
53 + .sort(([a], [b])
=> a.localeCompare(b))
54 + .map(([name, hex])
=> ` ${name}
\t ${hex}
` );
56 + fs.mkdirSync(path.dirname(DB), { recursive:
true });
57 + const next
= ` ${lines.join(
"\n" )}
\n` ;
58 + const nextBytes
= zlib.brotliCompressSync(next, { params: {
59 + [zlib.constants.BROTLI_PARAM_QUALITY]:
11 ,
60 + [zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_TEXT,
63 + if (fs.existsSync(DB)) {
64 + const raw
= fs.readFileSync(DB);
65 + prev
= zlib.brotliDecompressSync(raw).
toString (
"utf8" );
67 + if (next
!== prev) fs.writeFileSync(DB, nextBytes);
68 + return lines.length;
71 + function normalizeName (s) {
72 + return s.trim().toLowerCase().replace(
/\s + / g ,
"_" );
75 + function findMatches (db, query) {
76 + const q
= normalizeName(query);
77 + const variants
= new Set ([q]);
78 + if (
! q.startsWith(
"nf-" )) {
79 + variants.add(
`nf- ${q}
` );
80 + variants.add(
`nf-md- ${q}
` );
81 + variants.add(
`nf-fa- ${q}
` );
82 + variants.add(
`nf-fae- ${q}
` );
83 + variants.add(
`nf-cod- ${q}
` );
84 + variants.add(
`nf-oct- ${q}
` );
87 + const exact
= db.filter((x)
=> variants.has(x.name.toLowerCase()));
88 + if (exact.length)
return exact;
90 + const needle
= q.replace(
/ ^ nf-[a-z] + -/ ,
"" );
91 + return db.filter((x)
=> x.name.toLowerCase().includes(needle));
94 + function javaEscape (cp) {
95 + if (cp
<= 0xffff )
return `\\u ${cp.
toString (
16 ).toUpperCase().padStart(
4 ,
"0" )}
` ;
96 + const n
= cp
- 0x10000 ;
97 + const hi
= 0xd800 + (n
>> 10 );
98 + const lo
= 0xdc00 + (n
& 0x3ff );
99 + return `\\u ${hi.
toString (
16 ).toUpperCase()}
\\u ${lo.
toString (
16 ).toUpperCase()}
` ;
102 + function eightHex (cp) {
103 + return cp.
toString (
16 ).toUpperCase().padStart(
8 ,
"0" );
106 + function render (item, format) {
107 + const cp
= Number .
parseInt (item.hex,
16 );
108 + const hexUpper
= item.hex.toUpperCase();
109 + const glyph
= String .
fromCodePoint (cp);
113 + codepoint:
`U+ ${hexUpper}
` ,
115 + js:
`\\u{ ${hexUpper}
}` ,
116 + html:
`&#x ${hexUpper}
;` ,
117 + java: javaEscape(cp),
118 + jsonEscape: javaEscape(cp),
119 + css:
`\\ ${hexUpper}
` ,
120 + cssContent:
`content: "\\ ${hexUpper}
";` ,
121 + python:
`\\U ${eightHex(cp)}
` ,
122 + rust:
`\\u{ ${hexUpper}
}` ,
123 + go:
`\\U ${eightHex(cp)}
` ,
124 + c:
`\\U ${eightHex(cp)}
` ,
125 + cpp:
`\\U ${eightHex(cp)}
` ,
126 + swift:
`\\u{ ${hexUpper}
}` ,
127 + lua:
`utf8.char(0x ${hexUpper}
)` ,
128 + shell:
`$'\\U ${eightHex(cp)}
'` ,
129 + printf:
`printf '\\U ${eightHex(cp)}
\\n'` ,
130 + toml:
`\\U ${eightHex(cp)}
` ,
131 + yaml:
`\\U ${eightHex(cp)}
` ,
132 + vim:
`nr2char(0x ${hexUpper}
)` ,
133 + elisp:
`(string #x ${hexUpper}
)` ,
134 + wezterm:
`wezterm.nerdfonts. ${item.name.replace(
/ ^ nf-/ ,
"" ).replace(
/-/ g ,
"_" )}
` ,
138 + case "hex" :
return row.hex;
139 + case "codepoint" :
return row.codepoint;
140 + case "glyph" :
return row.glyph;
141 + case "js" :
return row.js;
142 + case "html" :
return row.html;
143 + case "java" :
return row.java;
144 + case "json-escape" :
return row.jsonEscape;
145 + case "css" :
return row.css;
146 + case "css-content" :
return row.cssContent;
147 + case "python" :
return row.python;
148 + case "rust" :
return row.rust;
149 + case "go" :
return row.go;
150 + case "c" :
return row.c;
151 + case "cpp" :
return row.cpp;
152 + case "swift" :
return row.swift;
153 + case "lua" :
return row.lua;
154 + case "shell" :
return row.shell;
155 + case "printf" :
return row.printf;
156 + case "toml" :
return row.toml;
157 + case "yaml" :
return row.yaml;
158 + case "vim" :
return row.vim;
159 + case "elisp" :
return row.elisp;
160 + case "wezterm" :
return row.wezterm;
161 + case "json" :
return JSON .
stringify (row);
162 + case "all" :
return ` ${row.name}
\t ${row.hex}
\t ${row.codepoint}
\t ${row.glyph}
` ;
163 + default :
throw new Error (
`bad format: ${format}
` );
167 + async function main () {
168 + const args
= process .
argv .slice(
2 );
169 + if (args.includes(
"-h" )
|| args.includes(
"--help" )) usage(
0 );
171 + const refresh
= args.includes(
"--refresh" );
172 + const rest
= args.filter((x)
=> x
!== "--refresh" );
173 + const query
= rest[
0 ];
174 + const format
= rest[
1 ]
?? "codepoint" ;
177 + const count
= await refreshDb();
179 + console .
error (
`updated ${count}
icons: ${DB}
` );
184 + if (
! query
|| ! FORMATS .has(format)) usage(
2 );
187 + let matches
= findMatches(db, query);
189 + if (matches.length
=== 0 ) {
192 + matches
= findMatches(db, query);
195 + if (matches.length
=== 0 )
process .
exit (
1 );
197 + const exact
= matches.find((x)
=> x.name.toLowerCase()
=== normalizeName(query));
198 + const out
= exact
? [exact]
: matches;
199 + console .
log (out.map((x)
=> render(x, format)).join(
"\n" ));
202 + main().catch((err)
=> {
203 + console .
error (err.message);