Add a TTL to the directory cache

This commit is contained in:
Nick Chambers 2022-10-24 05:23:52 -05:00
parent 9ffef6b8aa
commit 230b2ed959
1 changed files with 13 additions and 4 deletions

View File

@ -34,11 +34,20 @@ reaper_pid=$! PROMPT_COMMAND+=(ping-timer)
trap slay-reaper EXIT
if [[ -f /tmp/iterm2-prev-dir.txt ]]; then
dir=$(</tmp/iterm2-prev-dir.txt)
cur_time=$(date +%s)
last_mod=$(stat -f%c /tmp/iterm2-prev-dir.txt)
if [[ -d $dir ]]; then
command cd "$dir"
if (( cur_time - last_mod > 1200 )); then
rm -f /tmp/iterm2-prev-dir.txt
else
dir=$(</tmp/iterm2-prev-dir.txt)
if [[ -d $dir ]]; then
command cd "$dir"
fi
unset dir
fi
unset dir
unset cur_time last_mod
fi