Someone (sorry, I forget who) mentioned in #guix that we can use
binfmt_misc to handle the shebang.

I tried coding it in C, and it seems to working fine.
Here it is: <https://github.com/iyzsong/duang>.

Try it with care:
--8<---------------cut here---------------start------------->8---
$ sudo mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc
$ git clone https://github.com/iyzsong/duang.git
$ cd duang
$ make
$ sudo make install
$ sudo make register
--8<---------------cut here---------------end--------------->8---

This will install the handler into `/libexec/@', and register it in
`/proc/sys/fs/binfmt_misc/duang'.  With it activated, intepreter in
the shebang doesn't need to be absolute path, and can handle multiple
arguments, eg: `#!emacs -Q --script'.  And when the interpreter in
absolute path is not exist, it will fallback to be searched in the PATH,
so `#!/usr/bin/perl -w' equals to `#!perl -w'.  On GuixSD, this means
if we remove the `/bin/sh' symlink, the sh-scripts will fallbacked to
use `sh' in PATH, so we can remove /bin.

I dunno if it's a good idea though :-)

Reply via email to