summaryrefslogtreecommitdiff
path: root/ar/.local/bin/statusbar/sb-clock
blob: d4110be70d427d555a0fbd1a0693e86682c30839 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh

# Get current hour and minute
calendar="🗓"
hour=$(date '+%I')
minute=$(date '+%M')

# Determine the icon based on hour and minute
if crontab -l 2>/dev/null | grep -q '^[^#[:space:]]'; then
  if [ "$minute" -ge 30 ]; then
    case "$hour" in
    "00" | "12") icon="🕧" ;; # 12:30
    "01" | "13") icon="🕜" ;; # 1:30
    "02" | "14") icon="🕝" ;; # 2:30
    "03" | "15") icon="🕞" ;; # 3:30
    "04" | "16") icon="🕟" ;; # 4:30
    "05" | "17") icon="🕠" ;; # 5:30
    "06" | "18") icon="🕡" ;; # 6:30
    "07" | "19") icon="🕢" ;; # 7:30
    "08" | "20") icon="🕣" ;; # 8:30
    "09" | "21") icon="🕤" ;; # 9:30
    "10" | "22") icon="🕥" ;; # 10:30
    "11" | "23") icon="🕦" ;; # 11:30
    esac
  else
    case "$hour" in
    "00" | "12") icon="🕛" ;; # 12:00
    "01" | "13") icon="🕐" ;; # 1:00
    "02" | "14") icon="🕑" ;; # 2:00
    "03" | "15") icon="🕒" ;; # 3:00
    "04" | "16") icon="🕓" ;; # 4:00
    "05" | "17") icon="🕔" ;; # 5:00
    "06" | "18") icon="🕕" ;; # 6:00
    "07" | "19") icon="🕖" ;; # 7:00
    "08" | "20") icon="🕗" ;; # 8:00
    "09" | "21") icon="🕘" ;; # 9:00
    "10" | "22") icon="🕙" ;; # 10:00
    "11" | "23") icon="🕚" ;; # 11:00
    esac
  fi
else
  icon="⏰"
fi

# Shows the current moon phase.
locationfile="${XDG_CACHE_HOME:-${HOME}/.cache}/statusbar/location"
moonfile="${XDG_DATA_HOME:-${HOME}/.local/share}/wallpapers/moonphase"

# Cache location for 24 hours
if [ ! -s "$locationfile" ] || [ $(($(date +%s) - $(stat -c %Y "$locationfile" 2>/dev/null || echo 0))) -gt 86400 ]; then
  mkdir -p "${XDG_CACHE_HOME:-${HOME}/.cache}/statusbar"
  curl -s http://ip-api.com/json | jq -r '[.regionName, .countryCode] | join(",")' > "$locationfile" 2>/dev/null &
fi

location=$(cat "$locationfile" 2>/dev/null || echo "")

# Update moon phase only once per day
if [ ! -s "$moonfile" ] || [ "$(stat -c %y "$moonfile" 2>/dev/null | cut -d' ' -f1)" != "$(date '+%Y-%m-%d')" ]; then
  if [ -n "$location" ]; then
    moon=$(curl -sf "wttr.in/$location?format=%m" 2>/dev/null)
    [ -n "$moon" ] && ! echo "$moon" | grep -q 'Unknown location' && echo "$moon" >"$moonfile" &
  fi
fi

moonicon="$(cat "$moonfile" 2>/dev/null)"

case $BLOCK_BUTTON in
1) notify-send "This Month" "$(cal | sed "s/\<$(date +'%B' | tr -d ' ')\>/<b><span color='blue'>&<\/span><\/b>/;s/\<$(date +'%Y' | sed 's/ //g')\>/<b><span color='blue'>&<\/span><\/b>/;s/\<$(date +'%B' | sed 's/ //g')\>/<b><span color='blue'>&<\/span><\/b>/;s/\<$(date +'%e' | sed 's/ //g')\>/<b><span color='red'>&<\/span><\/b>/")" && notify-send "Appointments" "$(calcurse -d3)" ;;
2) setsid -f "$TERMINAL" -e calcurse ;;
3)
  notify-send "📅 Time/date module" "\- Left click to show upcoming appointments for the next three days via \`calcurse -d3\` and show the month via \`cal\`
- Left click also displays the current time in other cities.
- Middle click opens calcurse if installed"
  notify-send "🌜 Moon phase module" "Displays current moon phase
- 🌑: New
- 🌒: Waxing Crescent
- 🌓: First Quarter
- 🌔: Waxing Gibbous
- 🌕: Full
- 🌖: Waning Gibbous
- 🌗: Last Quarter
- 🌘: Waning Crescent"
  ;;
6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
7) timezones ;;
esac

# Output the formatted date and time
date "+${moonicon:-$calendar}%a,%d $icon%H:%M"