From 1cbc0b0e719398278f7f1bb9c6668e4cd5aa8a22 Mon Sep 17 00:00:00 2001 From: cscherr Date: Mon, 11 Aug 2025 16:27:42 +0200 Subject: [PATCH] make confirm work --- .zshrc | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/.zshrc b/.zshrc index 099f6a0..2e293ed 100644 --- a/.zshrc +++ b/.zshrc @@ -93,7 +93,7 @@ function k() function rscript () { TDIR=$(mktemp -d) - rustc -v -C lto -C opt-level=3 $1 -o $TDIR/rscript_executable + rustc -v -C opt-level=3 $1 -o $TDIR/rscript_executable $TDIR/rscript_executable ${@:2} rm -rf $TDIR } @@ -134,19 +134,25 @@ fi return $ret } function confirm() { - bash -c " - echo \"To be executed: $@\"; - read -p \"Confirm (Y/N): \" -n 1 -r; - case \"\$REPLY\" in - y|Y ) echo \"es\"; eval $@;; - n|N ) echo \"o\";; - * ) echo -e \"\ninvalid\";; - esac" $@ + CMD=$@ + echo "Execute: '$CMD' ?"; + echo -n "[Y/n]: " + # a weid difference between zsh and bash + if [[ "$SHELL" =~ (.*zsh) ]]; then + read -s -k1; + else + read -s -n1; + fi + case "${REPLY}" in + y|Y|$'\n'|" "|"A"|"" ) echo yes;eval $CMD;; + n|N ) echo no;echo 'Aborted.' ; return 1;; + * ) echo -e 'Invalid choice, aborted.'; return 2;; + esac; } function confirm-important() { echo "Write 'yes do as i say' to confirm that you REALLY want to do this: $@" read - if [[ "${REPLY,,}" = "yes do as i say" ]] + if [[ "${REPLY}" = "yes do as i say" ]] then eval $@ else