dotfiles/polybar/script/hebcal/hebcal.sh
Irrlicht 83c029e337
[polybar][module] Write a custom module for Hebrew dates.
POC for a module displaying the current date according to the Hebrew
calendar. Can also display the date in Hebrew. See README.
2026-08-26 03:45:07 +02:00

86 lines
1.6 KiB
Shell
Executable file

#!/bin/bash
data_dir="/tmp"
hebcal_api_url="https://www.hebcal.com/converter"
hebcal_json="$data_dir/hebcal.json"
hebcal_hebrew_path="$data_dir/hebcal-hebrew.txt"
# Mandatory option
opt_version=1
# Does the person resides in Isreal
opt_isreal="off"
# Candle lighting time for Shabbat, defaut on
opt_candle_lighting="on"
opt_language="fr"
opt_city="Rennes"
opt_city_geonameid="2983990"
today=$(date -d today +%Y-%m-%d)
request_url="$hebcal_api_url?cfg=json&date=$today&g2h=1"
hebrew_year=$(jq -r -M .hy "$hebcal_json")
hebrew_month=$(jq -r -M .hm "$hebcal_json")
hebrew_day=$(jq -r -M .hd "$hebcal_json")
hebrew_full=$(jq -r -M .hebrew "$hebcal_json")
read_hebrew() {
curl -o "$hebcal_json" -s "$request_url"
if [ ! -f $hebcal_hebrew_path ]
then
echo "0" > "${hebcal_hebrew_path}"
echo 0
else
head -n1 $hebcal_hebrew_path
fi
}
toggle_hebrew() {
hebrew_opt=$(read_hebrew)
echo "Toggle, hebrew: $hebrew_opt"
if [ $hebrew_opt -eq 0 ]
then
echo "1" > "${hebcal_hebrew_path}"
else
echo "0" > "${hebcal_hebrew_path}"
fi
pid=$(cat "$path_pid")
if [ "$pid" != "" ]
then
kill -10 "-$pid"
fi
print_date
}
print_date() {
hebrew_opt=$(read_hebrew)
if [ $hebrew_opt -lt 1 ]
then
echo "$hebrew_day $hebrew_month $hebrew_year"
else
echo "$hebrew_full" | rev
fi
}
path_pid="/tmp/polybar-hebdcal.pid"
case "$1" in
--hebrew)
toggle_hebrew
;;
*)
echo $$ > $path_pid
while true
do
print_date
sleep 600 &
wait
done
;;
esac