dotfiles/dotlib/post/cattle.sh

43 lines
708 B
Bash
Raw Normal View History

2024-05-13 09:07:12 +00:00
cattle-reset-elapsed() {
(( last_cmd_at = SECONDS ))
}
cattle-ping-timer() {
kill -USR1 "$reaper_pid"
}
cattle-slay-reaper() {
kill -KILL "$reaper_pid"
}
cd() {
command cd "$@"
printf '\e[]1337;CurrentDir=%s\G' "$PWD"
printf %s "$PWD" > /tmp/iterm2-prev-dir.txt
}
{
trap cattle-reset-elapsed USR1
last_cmd_at=0
while sleep 10; do
(( elapsed = SECONDS - last_cmd_at ))
if (( elapsed > 600 )); then
kill -KILL "$$"
exit
fi
done
} 2> /dev/null &
reaper_pid=$! PROMPT_COMMAND+=(cattle-ping-timer)
trap cattle-slay-reaper EXIT
if [[ -f /tmp/iterm2-prev-dir.txt ]]; then
dir=$(</tmp/iterm2-prev-dir.txt)
if [[ -d $dir ]]; then
command cd "$dir"
fi
fi