New functions and confirmation aliases for reboot, shutdown, poweroff

This commit is contained in:
Elmar Sönser 2021-12-05 12:29:18 +01:00
parent f999215cf2
commit a254811e4b
3 changed files with 55 additions and 19 deletions

View file

@ -1,16 +0,0 @@
### to prevent accidental shudown, add confirm dialog to commands:
confirm() {
# call with a prompt string or use a default
read -r -p "${1:-Server: $HOST - Are you sure? [y/N]} " response
case "$response" in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}
alias reboot="confirm && reboot"
alias shutdown="confirm && shutdown"
alias poweroff="confirm && poweroff"

51
.zshrc
View file

@ -193,5 +193,52 @@ alias geoes="sshuttle --dns -r es -x 192.189.78.0/23 -x 192.168.178.0/23 -x 128.
#### Show OS Info on startup
#if [ -f /usr/bin/screenfetch ]; then screenfetch; fi
### to enable confirmatoin for reboot uncomment next line
source .confirm_reboot
### to prevent accidental shudown, add confirm dialog to commands:
askreboot() {
autoload colors; colors
read -q "answ?Server: $fg[red]$HOST$reset_color - Continue (y/N)?"
if [[ "$answ" =~ ^[Yy]$ ]]
then
echo
echo "OK - Rebooting..."
sleep 2
reboot
else
echo
echo "Canceling..."
return
fi
}
askshutdown() {
read -q "answ?Server: $fg[red]$HOST$reset_color - Continue (y/N)?"
if [[ "$answ" =~ ^[Yy]$ ]]
then
echo
echo "OK - Shutting down..."
sleep 2
shutdown
else
echo
echo "Canceling..."
return
fi
}
askpoweroff() {
read -q "answ?Server: $fg[red]$HOST$reset_color - Continue (y/N)?"
if [[ "$answ" =~ ^[Yy]$ ]]
then
echo
echo "OK - Powering down..."
sleep 2
poweroff
else
echo
echo "Canceling..."
return
fi
}
alias reboot="askreboot"
alias shutdown="askshutdown"
alias poweroff="askpoweroff"

View file

@ -18,7 +18,6 @@
- `git clone https://git.gc4.at/linux/nerd-fonts.git`
- `cd nerd-fonts && ./install.sh`
- `gem install colorls`
- Install
- mkdir ~/.dotfiles
- cd ~/.dotfiles
@ -43,6 +42,12 @@
- Change /`usr/bin/bash` to `/usr/bin/zsh` in `/etc/passwd` for your user
- AD/Ldap User
- AD/Ldap Users do no have an entry, so you need to grep it from AD/LDAP wit `getent passwd USERNAME` and then paste it into `/etc/passwd`
- Import bash history with ruby script
- `ruby ~/.dotfiles/zsh-settings/bash_to_zsh_history.rb`
- Confirmation dialog on reboot / poweroff / shutdown
- If you want to disable the confirmation dialog for reboots / shutdowns, comment out the aliases in .zshrc
- Sources:
- Check the Repos for instructions:
- https://git.gc4.at/linux/nerd-fonts