make confirm work

This commit is contained in:
cscherr 2025-08-11 16:27:42 +02:00
parent 5d5b94e6f3
commit 1cbc0b0e71
Signed by: cscherrNT
GPG key ID: 8E2B45BC51A27EA7

26
.zshrc
View file

@ -93,7 +93,7 @@ function k()
function rscript () function rscript ()
{ {
TDIR=$(mktemp -d) 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} $TDIR/rscript_executable ${@:2}
rm -rf $TDIR rm -rf $TDIR
} }
@ -134,19 +134,25 @@ fi
return $ret return $ret
} }
function confirm() { function confirm() {
bash -c " CMD=$@
echo \"To be executed: $@\"; echo "Execute: '$CMD' ?";
read -p \"Confirm (Y/N): \" -n 1 -r; echo -n "[Y/n]: "
case \"\$REPLY\" in # a weid difference between zsh and bash
y|Y ) echo \"es\"; eval $@;; if [[ "$SHELL" =~ (.*zsh) ]]; then
n|N ) echo \"o\";; read -s -k1;
* ) echo -e \"\ninvalid\";; else
esac" $@ 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() { function confirm-important() {
echo "Write 'yes do as i say' to confirm that you REALLY want to do this: $@" echo "Write 'yes do as i say' to confirm that you REALLY want to do this: $@"
read read
if [[ "${REPLY,,}" = "yes do as i say" ]] if [[ "${REPLY}" = "yes do as i say" ]]
then then
eval $@ eval $@
else else