tonsky / FiraCode

Free monospaced font with programming ligatures
SIL Open Font License 1.1
76.78k stars 3.09k forks source link

Feature: Shorten the Nix paths #1449

Open gurjeet opened 2 years ago

gurjeet commented 2 years ago

The Nix package management relies on hash (sha256) in file names and path names for its core functionality. For example:

/nix/store/nmv9xdibyaw71a3vq2skaapzif6cb8n1-vim-darwin-8.2.4350/share/vim/vimfiles

Seeing these hash names in our output just clutters the screen, does not provide much value, and in fact causes information to be missed by the reader/people. For example, following is the content of 'runtimepath' variable in my Vim session. It's very easy to miss the various values, because the comma separates the values, but the sha256 hashes make the values unreadable.

runtimepath=/nix/store/nmv9xdibyaw71a3vq2skaapzif6cb8n1-vim-darwin-8.2.4350/share/vim/vimfiles,/nix/store/nmv9xdibyaw71a3vq2skaapzif6cb8n1-vim-darwin-8.2.4350/share/vim/vim82,/nix/store/nmv9xdibyaw71a3vq2skaapzif6cb8n1-vim-darwin-8.2.4350/share/vim/vimfiles/after

I would like the display to be compact, so that the same output would look like:

runtimepath=/nix/store/nmv...-vim-darwin-8.2.4350/share/vim/vimfiles,/nix/store/nmv...-vim-darwin-8.2.4350/share/vim/vim82,/nix/store/nmv...-vim-darwin-8.2.4350/share/vim/vimfiles/after

I think a font, like FirCode, is ideal for this kind of compaction, rather than change the Nix tooling to do the same work. Since doing so via fonts won't clutter the screen visually, but when copied-pasted, the information will be retained.

I was wondering if FiraCode could be customized to achieve this kind of compaction. I looked for instructions to add one's own glyphs, etc., but could not find any instructions on how to do it. Typically a project contains instructions on how to contribute, and those seem to be missing from this project; at least I could not easily find them.

Ideally, we'd like the strings of format /nix/store/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx to be shortened to /nix/store/xxx....

Another example of how the output would change, before and after the requested feature.

Before:

$ ls -1 /nix/store/ | head
00sgasgxp8jxgj87zmdmzljb18v0hc48-xz-5.2.5
026l3vp2pwb3nryx99clka9565ppf8y3-ruby2.7.5-wdm-0.1.1
0286s0vppcdk3zlxa8pvx098h58zf5kc-ensure-newer-sources-hook.sh.drv
0548jxy8by325jhwn7xzs7bxnpxrj3fg-httpclient-2.8.3.gem.drv
05hbwlry4adliqyl7s5nvr1h6vyyfj83-ruby2.7.5-rexml-3.2.5
05rf5hxbih4ssngvqcb5mna4p8ds2xyy-hook.drv
0631vf1bz8gkw4j1llvid53qxnjsxz5h-compiler-rt-11.1.0.src.tar.xz.drv
07qb0ariqsmkdisa4w8zlfigj9wq6vq8-bsdmake-24.drv
07y7nmv5miwnf985qc335zfmnd6j7gbq-tcl-8.6.11.drv
07zngbds28lwjnk1ix103bqlls9mrq6i-Test-Warn-0.36.tar.gz.drv

After:

$ ls -1 /nix/store/ | head
00s...-xz-5.2.5
026...-ruby2.7.5-wdm-0.1.1
028...-ensure-newer-sources-hook.sh.drv
054...-httpclient-2.8.3.gem.drv
05h...-ruby2.7.5-rexml-3.2.5
05r...-hook.drv
063...-compiler-rt-11.1.0.src.tar.xz.drv
07q...-bsdmake-24.drv
07y...-tcl-8.6.11.drv
07z...-Test-Warn-0.36.tar.gz.drv
tonsky commented 2 years ago

I don’t think it’s possible to do this kind of compaction in a font because there’s no clear pattern to it. It’ll probably also generate a ton of false positives (strings being compacted that you didn’t expect to be compacted

gurjeet commented 2 years ago

there’s no clear pattern to it.

Respectfully, I disagree. If we consider the full filesystem path, I think we can identify this pattern easily, and then target this pattern with high precision.

Below is an example sed invocation that recognizes this pattern, and shows the desired output.

String /nix/store/ followed by 32 alpha-numeric characters, followed by a hyphen. Retain the /nix/store/ prefix, first 3 of those 32 alpha-numeric characters, and replace the rest 29 with ....

$ ls -1 /nix/store/* | head | sed -E 's"(/nix/store/[[:alnum:]]{3})[[:alnum:]]{29}-"\1...-"'
/nix/store/028...-ensure-newer-sources-hook.sh.drv
/nix/store/054...-httpclient-2.8.3.gem.drv
/nix/store/05r...-hook.drv
/nix/store/063...-compiler-rt-11.1.0.src.tar.xz.drv
/nix/store/07q...-bsdmake-24.drv
/nix/store/07y...-tcl-8.6.11.drv
/nix/store/07z...-Test-Warn-0.36.tar.gz.drv
/nix/store/089...-libunwind-35.3.drv
/nix/store/0a6...-ruby2.7.5-wdm-0.1.1.drv
/nix/store/0fh...-Csu-85.tar.gz.drv

The same output, but without sed replacing the text pattern.

$ ls -1 /nix/store/* | head | sed -E 's"(/nix/store/[[:alnum:]]{3})[[:alnum:]]+-"\1...-"'
/nix/store/0286s0vppcdk3zlxa8pvx098h58zf5kc-ensure-newer-sources-hook.sh.drv
/nix/store/0548jxy8by325jhwn7xzs7bxnpxrj3fg-httpclient-2.8.3.gem.drv
/nix/store/05rf5hxbih4ssngvqcb5mna4p8ds2xyy-hook.drv
/nix/store/0631vf1bz8gkw4j1llvid53qxnjsxz5h-compiler-rt-11.1.0.src.tar.xz.drv
/nix/store/07qb0ariqsmkdisa4w8zlfigj9wq6vq8-bsdmake-24.drv
/nix/store/07y7nmv5miwnf985qc335zfmnd6j7gbq-tcl-8.6.11.drv
/nix/store/07zngbds28lwjnk1ix103bqlls9mrq6i-Test-Warn-0.36.tar.gz.drv
/nix/store/089b3jlg7fj960wrxr6khwgvkgxa3zk0-libunwind-35.3.drv
/nix/store/0a6bcnrppza7i66pf89vyjp8h199n9zw-ruby2.7.5-wdm-0.1.1.drv
/nix/store/0fhy310gh8w0s484xiswz5j9qchw2nsz-Csu-85.tar.gz.drv

It’ll probably also generate a ton of false positives

Given that the location /nix/store/ is quite unique to the Nix package manager, I don't think there will be any false positives. And even if there were, those few false positives would be acceptable.

If given directions/help in how to hack on FiraCode, and some handholding with Clojure code, I would like to try implementing this feature myself. I'll at least get to keep my fork of FiraCode, then :-)

tonsky commented 2 years ago

But that won’t work on your second example, the one without prefix.

With prefix, you can try, might be possible. It’s difficult to give directions, since Fira Code is built using Glyphs.app. I suggest you open ttf and modify it directly instead of figuring out Clojure build scripts. You’ll need to look at calt table.