Skip to content

Commit 9f422d9

Browse files
authored
Merge pull request #249 from roc-lang/better-cmd-alias
better command alias
2 parents 8400a6f + ab48568 commit 9f422d9

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

flake.nix

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323

2424
rocPkgs = roc.packages.${system};
2525

26-
aliases = ''
27-
alias testcmd='export ROC=roc && ./ci_scripts/all_tests.sh'
26+
shellFunctions = ''
27+
testcmd() {
28+
./ci_scripts/all_tests.sh
29+
}
30+
export -f testcmd
2831
'';
2932

3033
linuxInputs = with pkgs;
@@ -54,10 +57,15 @@
5457
if pkgs.stdenv.isLinux then "${pkgs.glibc.out}/lib" else "";
5558

5659
shellHook = ''
57-
${aliases}
60+
export ROC=roc
61+
62+
${shellFunctions}
5863
59-
echo "Some convenient command aliases:"
60-
echo "${aliases}" | grep -E "alias .*" -o | sed 's/alias / /' | sed 's/=/ = /'
64+
echo "Some convenient commands:"
65+
echo "${shellFunctions}" | grep -E '^\s*[a-zA-Z_][a-zA-Z0-9_]*\(\)' | sed 's/().*//' | sed 's/^[[:space:]]*/ /' | while read func; do
66+
body=$(echo "${shellFunctions}" | sed -n "/''${func}()/,/^[[:space:]]*}/p" | sed '1d;$d' | tr '\n' ';' | sed 's/;$//' | sed 's/[[:space:]]*$//')
67+
echo " $func = $body"
68+
done
6169
echo ""
6270
'';
6371
};

0 commit comments

Comments
 (0)