feat: add prayer timer to polybar

This commit is contained in:
Flinner Yuu 2024-11-14 16:21:29 +03:00
parent 2763a2059c
commit 6880a03eec
Signed by: flinner
GPG Key ID: 95CE0DA7F0E58CA6
9 changed files with 2101 additions and 1520 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#xset r rate 400 100
xset r rate 180 40
##emacs -fs &
rm -rf ~/.cache/fontconfig
@ -25,6 +25,7 @@ source ~/.fehbg
(sleep 1 && warpd)&
killall wired
(sleep 1 && wired ) &
(sleep 3 && greenclip daemon) &
#(sleep 3 && optimus-manager-qt) &
(sleep 3 && flameshot) &
@ -32,7 +33,9 @@ killall wired
(sleep 6 && bspc rule -r KeePassXC ) &
(sleep 5 && syncthing -no-browser) &
(sleep 100 && nextcloud --background) &
(sleep 5 && kdeconnect-indicator) &
(sleep 4 && kdeconnectd) &
#(sleep 100 && nextcloud --background) &
#(sleep 5 && thunderbird ) &
#(sleep 7 && bspc rule -r Thunderbird ) &
@ -61,6 +64,12 @@ killall goimapnotify
# Japanses Input
#(sleep 1 && fcitx -d ) &
(sleep 0 && ~/bin/keyboard ) &
#(sleep 4 && ~/bin/battery-alert ) &
(sleep 1 && udiskie --tray) &
(sleep 1 && nm-applet) &
(sleep 2 && blueberry-tray) &
## Audio
(sleep 0 && dbus-run-session pipewire ) &

354
bin/bin/prayer-times Executable file
View File

@ -0,0 +1,354 @@
#!/bin/bash
# ----- Parameters ------ #
# Coordinates: https://www.mapcoordinates.net/en
# Set explicitly, or leave commented to get them automatically from ipinfo.io
# lat='100.00000'
# long='100.00000'
# Calculation Method: https://api.aladhan.com/v1/methods
method='4'
# Print Text Language (en/ar)
print_lang="ar"
# Notifcation Daemon
notify="mako"
# ----------------------- #
prayers_json="$HOME/.local/share/prayers.json"
prayers=("Fajr" "Dhuhr" "Asr" "Maghrib" "Isha")
declare -A date
declare -A epochtimes
declare -A prayers_ar
prayers_ar=(
["Fajr"]="الفجر"
["Sunrise"]="الشروق"
["Dhuhr"]="الظهر"
["Asr"]="العصر"
["Maghrib"]="المغرب"
["Isha"]="العشاء"
)
date=(
[day_idx]=$(($(date +%-d) - 1))
[weekday]=$(date +%a)
[month]=$(date +%-m)
[year]=$(date +%Y)
)
nameof() {
if [[ "$print_lang" != "en" ]]; then
local array_name="prayers_$print_lang"
eval "echo -n \${${array_name}[$1]}"
else
echo -n "$1"
fi
}
check() {
local available_month
if [[ -r $prayers_json ]]; then
available_month=$(jq -r ".data[0].date.gregorian.month.number" "$prayers_json")
else
local fetch_prayers=1
fi
if [[ "$fetch_prayers" || "$available_month" != "${date[month]}" ]]; then
# Fetch the geolocation data from ipinfo.io
response=$(curl -s https://ipinfo.io)
echo "-- fetching latitude and longitude"
# Parse the latitude and longitude
location=$(echo $response | jq -r '.loc')
# Separate latitude and longitude
latitude=$(echo $location | cut -d',' -f1)
longitude=$(echo $location | cut -d',' -f2)
# Set `lat` to `latitude`, or default to the specified value above
lat=${latitude:lat}
long=${longitude:long}
echo "-- latitude: ${lat}, longitude: ${long}"
echo "-- fetching current month prayer calendar (${date[month]}-${date[year]})"
# Documentation: https://aladhan.com/prayer-times-api#GetCalendar
curl -Lso "$prayers_json" "https://api.aladhan.com/v1/calendar/${date[year]}/${date[month]}?latitude=$lat&longitude=$long&method=$method"
fi
}
add-jobs() {
# WARNING: THIS SCRIPTS REMOVES ALL JOBS IN QUEUE "P" SCHEDULED USING AT (ADJUST ACCORDINGLY)
echo "-- removing all jobs in queue 'p'"
if [[ "$(at -q p -l | wc -l)" != "0" ]]; then
for i in $(at -q p -l | awk '{ print $1 }'); do
atrm "$i"
done
fi
for prayer in "${prayers[@]}"; do
echo "-- creating at job for $prayer prayer"
if [[ "$notify" == "mako" ]]; then
printf 'notify-send -t 30000 --icon="clock-applet-symbolic" "Prayer Times" "It is time for %s prayer 🕌"' "$prayer" | at -q p "$(timeof "$prayer" '%H:%M %F')"
else
printf '[ "$(dunstify --icon="clock-applet-symbolic" --action="Reply,reply" "Prayer Times" "Time for %s prayer 🕌" -t 30000)" = "2" ] && %s' "$prayer" "$HOME/.local/bin/toggle-athan" | at -q p "$(timeof "$prayer" '%H:%M %F')"
fi
done
}
timeof() {
[[ "$#" -lt "1" ]] && echo "atleast 1 argument is needed" && return 1
echo -n "$(date -d "$(jq -r ".data[${date[day_idx]}].timings.$1" "$prayers_json")" "+${2:-%I:%M}")"
}
hijri() {
case "$1" in
weekday)
if [[ "$print_lang" == "ar" ]]; then
echo -n "$(jq -r ".data[${date[day_idx]}].date.hijri.weekday.ar" "$prayers_json")"
else
echo -n "$(jq -r ".data[${date[day_idx]}].date.hijri.weekday.en" "$prayers_json")"
fi
;;
day)
echo -n "$(jq -r ".data[${date[day_idx]}].date.hijri.day" "$prayers_json")"
;;
month)
if [[ "$print_lang" == "ar" ]]; then
echo -n "$(jq -r ".data[${date[day_idx]}].date.hijri.month.ar" "$prayers_json")"
else
echo -n "$(jq -r ".data[${date[day_idx]}].date.hijri.month.en" "$prayers_json")"
fi
;;
year)
echo -n "$(jq -r ".data[${date[day_idx]}].date.hijri.year" "$prayers_json")"
;;
*)
echo "unsupported argument: $1" && return 1
;;
esac
}
settimes() {
# return if array already populated
[[ "${#epochtimes[@]}" -gt 0 ]] && return 0
epochtimes=(
[now]=$(date +%s)
[fajr]=$(timeof Fajr %s)
[dhuhr]=$(timeof Dhuhr %s)
[asr]=$(timeof Asr %s)
[maghrib]=$(timeof Maghrib %s)
[isha]=$(timeof Isha %s)
)
local nxt_idx=0
local curr_idx=4
for i in {4..0}; do
local prayer_key="${prayers[$i],,}"
if [[ "${epochtimes[now]}" -ge "${epochtimes[$prayer_key]}" ]]; then
[[ "$i" -lt "4" ]] && curr_idx=$i && nxt_idx=$((i + 1))
break
fi
done
local next_key="${prayers[$nxt_idx],,}"
epochtimes[next]="${epochtimes[$next_key]}"
currentprayer="${prayers[$curr_idx]}"
nextprayer="${prayers[$nxt_idx]}"
if [[ "$nxt_idx" == "1" && "${date[weekday]}" == "Fri" ]]; then
nextprayer="Jumuaa"
fi
}
timeto() {
[[ "$#" -lt "1" ]] && echo "atleast 1 argument are needed" && return 1
settimes
remain="$((epochtimes["${1,,}"] - epochtimes[now]))"
[[ "$remain" -lt "0" ]] && remain="$((remain + 86400))"
date -u -d"@$remain" "+${2:-%H:%M}"
}
print() {
local format="📅 %s،%s\n%-12s%-10s\n%-12s%-10s\n%-12s%-10s\n%-12s%-10s\n%-12s%-10s\n%-12s%-10s\n"
if [[ "$print_lang" == "ar" ]]; then
format="📅 %s،%s\n%s%11s\n%s%10s\n%s%11s\n%s%11s\n%s%10s\n%s%10s\n"
fi
printf "$format" \
"$(hijri weekday)" \
"$(hijri day)-$(hijri month)-$(hijri year)" \
"۞ $(nameof Fajr)" "$(timeof Fajr)" \
"۞ $(nameof Sunrise)" "$(timeof Sunrise)" \
"۞ $(nameof Dhuhr)" "$(timeof Dhuhr)" \
"۞ $(nameof Asr)" "$(timeof Asr)" \
"۞ $(nameof Maghrib)" "$(timeof Maghrib)" \
"۞ $(nameof Isha)" "$(timeof Isha)"
}
yad-en() {
yad \
--text-width=10 \
--on-top \
--text \
"<span font-size='large'><b>📅 $(hijri weekday),$(hijri day)-$(hijri month)-$(hijri year)</b></span>" \
--list \
--width=300 \
--posx=550 \
--posy=20 \
--height=270 \
--title="Prayers" \
--column="Prayer" \
--column="Time" \
--expand-column=1 \
--no-buttons \
--no-click \
--no-selection \
"<span font-size='large'>$(nameof Fajr)</span>" "<span font-size='large'>$(timeof Fajr)</span>" \
"<span font-size='large'>$(nameof Sunrise)</span>" "<span font-size='large'>$(timeof Sunrise)</span>" \
"<span font-size='large'>$(nameof Dhuhr)</span>" "<span font-size='large'>$(timeof Dhuhr)</span>" \
"<span font-size='large'>$(nameof Asr)</span>" "<span font-size='large'>$(timeof Asr)</span>" \
"<span font-size='large'>$(nameof Maghrib)</span>" "<span font-size='large'>$(timeof Maghrib)</span>" \
"<span font-size='large'>$(nameof Isha)</span>" "<span font-size='large'>$(timeof Isha)</span>"
}
yad-ar() {
yad \
--text-width=10 \
--on-top \
--text-align='right' \
--text \
"<span font-size='large'><b>📅 $(hijri weekday),$(hijri day)-$(hijri month)-$(hijri year)</b></span>" \
--list \
--width=250 \
--posx=550 \
--posy=20 \
--height=280 \
--title="Prayers" \
--column="الوقت" \
--column="الصلاة" \
--expand-column=1 \
--no-buttons \
--no-click \
--no-selection \
"<span font-size='large'>$(timeof Fajr)</span>" "<span font-size='large'>$(nameof Fajr)</span>" \
"<span font-size='large'>$(timeof Sunrise)</span>" "<span font-size='large'>$(nameof Sunrise)</span>" \
"<span font-size='large'>$(timeof Dhuhr)</span>" "<span font-size='large'>$(nameof Dhuhr)</span>" \
"<span font-size='large'>$(timeof Asr)</span>" "<span font-size='large'>$(nameof Asr)</span>" \
"<span font-size='large'>$(timeof Maghrib)</span>" "<span font-size='large'>$(nameof Maghrib)</span>" \
"<span font-size='large'>$(timeof Isha)</span>" "<span font-size='large'>$(nameof Isha)</span>"
}
yad-toggle() {
local yad_pid
yad_pid=$(pgrep -f 'yad.*Prayers')
if [[ -z "$yad_pid" ]]; then
if [[ "$print_lang" == "ar" ]]; then
yad-ar
else
yad-en
fi
else
kill "$yad_pid"
fi
}
current() {
settimes
echo "$currentprayer"
}
next() {
settimes
echo "$nextprayer"
}
remaining() {
settimes
timeto next "%H:%M:%S"
}
status() {
settimes
local remain
remain="$(timeto next)"
echo "$nextprayer in $remain"
}
waybar-status() {
settimes
local remain
remain="$(timeto next)"
local next_text="$nextprayer in $remain"
printf '{ "text": "%s", "class": "%s" }' "$next_text" "$nextprayer"
}
case "$1" in
check)
check
;;
jobs)
add-jobs
;;
sync)
check
add-jobs
;;
print)
print
;;
current)
current
;;
next)
next
;;
remaining)
remaining
;;
status)
status
;;
yad)
yad-toggle
;;
waybar)
waybar-status
;;
timeto)
if [[ -n "$2" ]]; then
if [[ "$2" == "next" ]]; then
valid=1
else
for p in "${prayers[@]}"; do
if [[ "${2^}" == "$p" ]]; then
valid=1
break
fi
done
fi
fi
if [[ -z "$valid" ]]; then
IFS='|'
echo "Usage: $(basename "$0") timeto (next|${prayers[*],,})"
exit 1
fi
timeto "$2"
;;
*)
echo "Usage: $(basename "$0") [command]"
echo "Command:"
echo " check Check if prayer time data needs to be fetched"
echo " jobs Add prayer time notifications as at jobs"
echo " sync Check and sync prayer time data, and add notifications"
echo " print Print prayer times"
echo " current Get the current prayer"
echo " next Get the next prayer"
echo " remaining Get the remaining time for the next prayer"
echo " status Get the status message indicating the next prayer"
echo " timeto Get the time remaining for a prayer"
echo " yad Toggle the yad window showing prayer times"
echo " waybar Print waybar JSON-formatted status"
exit 1
;;
esac

View File

@ -44,7 +44,9 @@ import subprocess
commands = ['isbn to bibtex',
'emoji',
'c']
'calc',
'spellcheck',
'nvidia rofi']
rofi_process = subprocess.Popen(['rofi', '-dmenu'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True)
@ -58,12 +60,20 @@ if selected_command:
clipboard = read_clipboard()
isbn = bash_it(f"echo \"{clipboard}\n'Esc to Cancel'\" | rofi -dmenu")
exit(0) if not isbn else False
isbn = isbn.replace("\n", ",")
isbn = isbn.replace("\n", " ")
eprint("isbn:", isbn)
res = bash_it('echo ' + isbn + '| isbn_to_bibtex.py')
eprint(res)
write_to_clipboard(res)
send_notif("status", "done!: "+ res)
elif selected_command == 'emoji':
bash_it("rofi -show emoji")
elif selected_command == 'calc':
bash_it("rofi -show calc -modi calc -no-show-match -no-sort")
elif selected_command == 'spellcheck':
bash_it("rofi -show spell -modes \"spell:rofi-spellcheck.sh\"")
elif selected_command == 'nvidia rofi':
bash_it("nvidia-offload ~/.config/polybar/forest/scripts/launcher.sh")
else:
send_notif("Failure", "Unkown Command")
exit(1)

View File

@ -8,7 +8,7 @@ pgrep ~/bin/wm/bspswallow || ~/bin/wm/bspswallow &
# not sure if I can count using Roman Numerals :)
bspc monitor -d I II III IV V VI VII VIII IX X
bspc monitor eDP1 -d I II III IV V VI VII VIII IX X
#bspc config ignore_ewmh_fullscreen all
bspc config ignore_ewmh_focus true
@ -27,18 +27,24 @@ bspc config single_monocle true
bspc config focus_follows_pointer true
bspc config pointer_follows_focus true
bspc config remove_unplugged_monitors true
bspc config remove_disabled_monitors true
# bspc rule -a Gimp desktop='^8' state=floating follow=on
#bspc rule -a Chromium desktop='^1'
# these 2 rules are removed after the program starts, in ~/bin/autostart
bspc rule -a Thunderbird desktop='^8'
bspc rule -a KeePassXC desktop='^8'
bspc rule -a KeePassXC desktop='^9'
# the confirm dialog
bspc rule -a "KeePassXC:*:Confirm Auto-Type" sticky=on
bspc rule -a "keepassxc:*:Confirm Auto-Type" sticky=on
bspc rule -a "Dragon-drop" sticky=on
bspc rule -a "No Title Yet:*:*" state=floating # for ngscopeclient
bspc rule -a "*:*:Quick Format Citation" state=floating # for ngscopeclient
bspc rule -a Dino desktop='^8'
bspc rule -a Peek state=floating
bspc rule -a Qalculate-gtk state=floating
bspc rule -a Connman-gtk state=floating
bspc rule -a mplayer2 state=floating
bspc rule -a Emacs state=tiled
@ -50,6 +56,11 @@ bspc rule -a wmpin sticky=on
bspc rule -a Floating state=floating
bspc rule -a \*:\*:org-capture state=floating
# Fix MATLAB https://github.com/baskerville/bspwm/issues/1204
#bspc rule -a 'MATLAB R2024a - academic use:sun-awt-X11-XWindowPeer:DefaultOverlayManager.JWindow' manage=off
#bspc rule -a 'MATLAB R2024a - academic use:sun-awt-X11-XWindowPeer:TabCompletionPopup' manage=off
bspc rule -a 'MATLAB*:TabCompletionPopup' manage=off
bspc rule -a 'MATLAB*:DefaultOverlayManager.JWindow' manage=off
~/bin/autostart
xsetroot -cursor_name left_ptr &

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
# Beware! This file is rewritten by htop when settings are changed in the interface.
# The parser is also very primitive, and not human-friendly.
htop_version=3.2.2
htop_version=3.3.0
config_reader_min_version=3
fields=0 48 17 18 38 39 40 2 46 47 49 1
hide_kernel_threads=1
@ -39,25 +39,25 @@ column_meter_modes_0=1 1 1 4 3
column_meters_1=RightCPUs2 Tasks LoadAverage Uptime DiskIO
column_meter_modes_1=1 2 2 4 3
tree_view=0
sort_key=47
sort_key=46
tree_sort_key=0
sort_direction=-1
tree_sort_direction=1
tree_view_always_by_pid=0
all_branches_collapsed=0
screen:Main=PID USER PRIORITY NICE M_VIRT M_RESIDENT M_SHARE STATE PERCENT_CPU PERCENT_MEM TIME Command
.sort_key=PERCENT_MEM
.sort_key=PERCENT_CPU
.tree_sort_key=PID
.tree_view=0
.tree_view_always_by_pid=0
.tree_view=0
.sort_direction=-1
.tree_sort_direction=1
.all_branches_collapsed=0
screen:I/O=PID USER IO_PRIORITY IO_RATE IO_READ_RATE IO_WRITE_RATE PERCENT_SWAP_DELAY PERCENT_IO_DELAY Command
.sort_key=IO_RATE
.tree_sort_key=PID
.tree_view=0
.tree_view_always_by_pid=0
.tree_view=0
.sort_direction=-1
.tree_sort_direction=1
.all_branches_collapsed=0

View File

@ -140,13 +140,13 @@ font-1 = "waffle:size=10;3"
; modules-right = ipc clock
;modules-left = launcher sep workspaces sep cpu memory temperature filesystem
;modules-center = mpd sep date
;modules-center = mpd sep date China
;modules-right = color-switch sep mail sep network sep keyboard battery volume backlight sep sysmenu try
#modules-right = color-switch sep network sep keyboard battery volume backlight sep sysmenu try
modules-left = launcher sep workspaces sep memory_bar cpu_bar sep temperature sep org-clock
modules-center = date sep mu4e_edu mu4e ssh keepassxc
modules-right = color-switch sep network sep keyboard sep volume brightness sep filesystem_bar sep battery sep sysmenu tray
modules-center = prayers date sep mu4e_a mu4e_edu mu4e ssh keepassxc
modules-right = color-switch sep network sep keyboard sep volume brightness sep filesystem_bar sep battery sep sysmenu
;; _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
; The separator will be inserted between the output of each module

View File

@ -17,6 +17,35 @@
;format-prefix = 
;label-padding = 1
;format-prefix-foreground = ${color.yellow}
;
[module/prayers]
type = custom/script
exec = $HOME/bin/prayer-times status
interval = 60
;label = %{A:$HOME/bin/prayer-times yad:}%{F#83CAFA}󱠧 %{F-} %output%%{A}
label = %{A:$HOME/bin/prayer-times yad:}%{F#83CAFA} %{F-}%output%%{A}
[module/China]
type = custom/script
interval = 5
#exec = TZ=Asia/Shanghai date "+%H:%M %Z"
exec = echo "("$(TZ=Asia/Riyadh date "+%H:%M %Z")")"
content-foreground = ${color.blue}
[module/mu4e_a]
type = custom/script
# Educational emails
exec = find ~/.mail -path '*\\.com/*/new/*' -type f | wc -l
interval = 5
format = <label>
label-padding = 1
format-prefix =
format-prefix-foreground = ${color.green}
[module/mu4e_edu]
type = custom/script
@ -35,7 +64,7 @@ format-prefix-foreground = ${color.yellow}
type = custom/script
# anything /but/ educational emails
exec = find ~/.mail -path '*/*/new/*' -not -path '*\\.edu.*/*/new/*' -type f | wc -l
exec = find ~/.mail -path '*/*/new/*' -not -path '*\\.edu.*/*/new/*' -not -path '*\\.com/*/new/*' -type f | wc -l
interval = 5

View File

@ -132,11 +132,11 @@ handle_image() {
# convert -- "${FILE_PATH}" "${IMAGE_CACHE_PATH}" && exit 6
# exit 1;;
## DjVu
# image/vnd.djvu)
# ddjvu -format=tiff -quality=90 -page=1 -size="${DEFAULT_SIZE}" \
# - "${IMAGE_CACHE_PATH}" < "${FILE_PATH}" \
# && exit 6 || exit 1;;
# DjVu
image/vnd.djvu)
ddjvu -format=tiff -quality=90 -page=1 -size="${DEFAULT_SIZE}" \
- "${IMAGE_CACHE_PATH}" < "${FILE_PATH}" \
&& exit 6 || exit 1;;
## Image
image/*)