Skip to content

Commit b5bc8ba

Browse files
authored
better command aliases (roc-lang#412)
1 parent 825bf45 commit b5bc8ba

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

flake.nix

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,16 @@
3030
rust =
3131
pkgs.rust-bin.fromRustupToolchainFile "${toString ./rust-toolchain.toml}";
3232

33-
aliases = ''
34-
alias buildcmd='bash jump-start.sh && roc ./build.roc -- --roc roc'
35-
alias testcmd='export ROC=roc && export EXAMPLES_DIR=./examples/ && ./ci/all_tests.sh'
33+
shellFunctions = ''
34+
buildcmd() {
35+
bash jump-start.sh && roc ./build.roc -- --roc roc
36+
}
37+
export -f buildcmd
38+
39+
testcmd() {
40+
export EXAMPLES_DIR=./examples/ && ./ci/all_tests.sh
41+
}
42+
export -f testcmd
3643
'';
3744

3845
linuxInputs = with pkgs;
@@ -72,10 +79,15 @@
7279
if pkgs.stdenv.isLinux then "${pkgs.glibc.out}/lib" else "";
7380

7481
shellHook = ''
75-
${aliases}
82+
export ROC=roc
83+
84+
${shellFunctions}
7685
77-
echo "Some convenient command aliases:"
78-
echo "${aliases}" | grep -E "alias .*" -o | sed 's/alias / /' | sed 's/=/ = /'
86+
echo "Some convenient commands:"
87+
echo "${shellFunctions}" | grep -E '^\s*[a-zA-Z_][a-zA-Z0-9_]*\(\)' | sed 's/().*//' | sed 's/^[[:space:]]*/ /' | while read func; do
88+
body=$(echo "${shellFunctions}" | sed -n "/''${func}()/,/^[[:space:]]*}/p" | sed '1d;$d' | tr '\n' ';' | sed 's/;$//' | sed 's/[[:space:]]*$//')
89+
echo " $func = $body"
90+
done
7991
echo ""
8092
'';
8193
};

0 commit comments

Comments
 (0)