tmux-kanagawa/scripts/sleep_weather.sh

46 lines
1,011 B
Bash
Raw Normal View History

2020-04-29 17:35:35 +02:00
#!/usr/bin/env bash
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8
#wrapper script for running weather on interval
2020-04-29 20:33:51 +02:00
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
2020-03-16 07:15:26 +01:00
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ ! -f $current_dir/../data/weather.txt ]; then
printf "Loading..." > $current_dir/../data/weather.txt
fi
2020-03-16 07:15:26 +01:00
$current_dir/weather.sh > $current_dir/../data/weather.txt
2020-03-16 01:20:04 +01:00
while tmux has-session &> /dev/null
do
2020-04-29 20:33:51 +02:00
$current_dir/weather.sh $fahrenheit > $current_dir/../data/weather.txt
2020-03-15 20:59:20 +01:00
if tmux has-session &> /dev/null
then
2020-03-31 21:13:42 +02:00
sleep 1200
2020-03-15 20:41:10 +01:00
else
break
fi
done
rm $LOCKFILE
}
#run main driver function
main