Close the shell after 10 minutes of inactivity

This commit is contained in:
Nick Chambers 2022-10-20 03:00:10 -05:00
parent ebd99c2295
commit 04fa68bfed
1 changed files with 28 additions and 0 deletions

28
dotlib/cattle.sh Normal file
View File

@ -0,0 +1,28 @@
reset-elapsed() {
(( last_cmd_at = SECONDS ))
}
ping-timer() {
kill -USR1 "$reaper_pid" 2>/dev/null
}
kill-reaper() {
kill -KILL "$reaper_pid"
}
{
trap reset-elapsed USR1
last_cmd_at=0
while sleep 1; do
(( elapsed = SECONDS - last_cmd_at ))
if (( elapsed > 600 )); then
kill -KILL "$$"
exit
fi
done
} &
reaper_pid=$! prompt_cmds+=(ping-timer)
trap kill-reaper EXIT