From 81e8bca1664c4345fe7c5687be6297b9c40087d1 Mon Sep 17 00:00:00 2001 From: Daniel Lundin Date: Sat, 12 Oct 2024 13:24:53 +0200 Subject: [PATCH] fish: confirm before poweroff, reboot, shutdown --- home/common/fish.nix | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/home/common/fish.nix b/home/common/fish.nix index 239fe59..2166133 100644 --- a/home/common/fish.nix +++ b/home/common/fish.nix @@ -16,6 +16,33 @@ ]; functions = { + confirm = { + description = "Ask for confirmation"; + argumentNames = [ "message" ]; + body = '' + read -l -p 'printf "\\e[31;1m$message\\e[0m (y/N) "' confirm + test "$confirm" = 'y' + ''; + }; + + poweroff = { + description = "Wraps poweroff to first prompt for confirmation"; + wraps = "poweroff"; + body = ''confirm "⚠ Really poweroff $(hostname)?" && command poweroff $argv''; + }; + + reboot = { + description = "Wraps reboot to first prompt for confirmation"; + wraps = "reboot"; + body = ''confirm "⚠ Really reboot $(hostname)?" && command reboot $argv''; + }; + + shutdown = { + description = "Wraps shutdown to first prompt for confirmation"; + wraps = "shutdown"; + body = ''confirm "⚠ Really shutdown $(hostname)?" && command shutdown $argv''; + }; + tmux-refresh-env = { description = "Refresh environment variables from tmux session"; body = ''