Last active
January 8, 2025 21:46
-
-
Save ttscoff/8079c8776e8f5e1f32610ba5c4992a6c to your computer and use it in GitHub Desktop.
A fish function to test for minimum idle time (using beengone) before executing a command.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function idletil --description 'Wait until system idle time has reached X seconds and optionally execute command' | |
argparse 'h/help' 'c/command=+' -- $argv | |
or return | |
if set -q _flag_help | |
echo "Usage: idletil SECONDS [-c \"command to execute\"]" | |
echo "SECONDS may be represented as XdXhXmXs or any combination" | |
return 0 | |
end | |
set -l minimum "$argv" | |
echo "> Waiting for $minimum of idle time" | |
beengone -w $minimum | |
echo "Time's up: "(beengone -n)" seconds" | |
for cmd in $_flag_c | |
eval $cmd | |
if test $status != 0 | |
return $status | |
end | |
end | |
return 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment