add script-interpreter

This commit is contained in:
James Andariese 2022-10-17 10:42:06 -05:00
parent 4d0a87386e
commit 5b510c550d

14
script-interpreter.nix Normal file
View File

@ -0,0 +1,14 @@
with builtins;
let file-lines = import ./file-lines.nix; in
f: ( let n = head (split-filename f); in
let
lines = file-lines f;
firstLine = head lines;
shebangMatch = match ''#! *(.*[/])?(([\][ ]|[^ /])*)( (.*))?'' firstLine;
in
if shebangMatch == null
then rec { interpreter = "sh"; args = "";}
else rec { interpreter = (elemAt shebangMatch 1); args = (elemAt shebangMatch 4);}
)