tmux-kanagawa/scripts/sleep_weather.sh
Ben Aaron Goldberg d9cc97a1d9 Change weather_sleep to avoid writing to tracked files
Changed weather_sleep.sh and dracula.sh so that they do
not assume that weather.txt exist.  As a result I was
able to remove weather.txt as a tracked file.
2020-09-12 19:11:25 -04:00

43 lines
888 B
Bash
Executable file

#!/usr/bin/env bash
#wrapper script for running weather on interval
fahrenheit=$1
LOCKFILE=/tmp/.dracula-tmux-weather.lock
ensure_single_process()
{
# check for another running instance of this script and terminate it if found
[ -f $LOCKFILE ] && ps -p "$(cat $LOCKFILE)" -o cmd= | grep -F " ${BASH_SOURCE[0]}" && kill "$(cat $LOCKFILE)"
echo $$ > $LOCKFILE
}
main()
{
ensure_single_process
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ ! -f $current_dir/../data/weather.txt ]; then
printf "Loading..." > $current_dir/../data/weather.txt
fi
$current_dir/weather.sh > $current_dir/../data/weather.txt
while tmux has-session &> /dev/null
do
$current_dir/weather.sh $fahrenheit > $current_dir/../data/weather.txt
if tmux has-session &> /dev/null
then
sleep 1200
else
break
fi
done
rm $LOCKFILE
}
#run main driver function
main