From 6a863b0b87cfaed19599bf60b08d6f3ef77b3528 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Fri, 31 Oct 2025 15:14:05 +0100 Subject: [PATCH] better command aliases --- flake.nix | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index d0951155..2005ebfd 100644 --- a/flake.nix +++ b/flake.nix @@ -30,9 +30,16 @@ rust = pkgs.rust-bin.fromRustupToolchainFile "${toString ./rust-toolchain.toml}"; - aliases = '' - alias buildcmd='bash jump-start.sh && roc ./build.roc -- --roc roc' - alias testcmd='export ROC=roc && export EXAMPLES_DIR=./examples/ && ./ci/all_tests.sh' + shellFunctions = '' + buildcmd() { + bash jump-start.sh && roc ./build.roc -- --roc roc + } + export -f buildcmd + + testcmd() { + export EXAMPLES_DIR=./examples/ && ./ci/all_tests.sh + } + export -f testcmd ''; linuxInputs = with pkgs; @@ -72,10 +79,15 @@ if pkgs.stdenv.isLinux then "${pkgs.glibc.out}/lib" else ""; shellHook = '' - ${aliases} + export ROC=roc + + ${shellFunctions} - echo "Some convenient command aliases:" - echo "${aliases}" | grep -E "alias .*" -o | sed 's/alias / /' | sed 's/=/ = /' + echo "Some convenient commands:" + echo "${shellFunctions}" | grep -E '^\s*[a-zA-Z_][a-zA-Z0-9_]*\(\)' | sed 's/().*//' | sed 's/^[[:space:]]*/ /' | while read func; do + body=$(echo "${shellFunctions}" | sed -n "/''${func}()/,/^[[:space:]]*}/p" | sed '1d;$d' | tr '\n' ';' | sed 's/;$//' | sed 's/[[:space:]]*$//') + echo " $func = $body" + done echo "" ''; };