make confirm work
This commit is contained in:
parent
5d5b94e6f3
commit
1cbc0b0e71
1 changed files with 16 additions and 10 deletions
26
.zshrc
26
.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
|
||||
|
|
Loading…
Add table
Reference in a new issue