aboutsummaryrefslogtreecommitdiffstats
path: root/share/hackvr/examples/calendar/calvr
blob: afef593b42fa78b2ae3f873abeb6438359feaded (plain) (blame)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env bash
#draw a 7x7 grid
#top row gets the day names
#figure out what the first day of the week for that month is
#then looping is easy after that
#use date with format string of day-of-week for an alternate time of the viewing month's first day

### :D atq in my calendar?
# atq files are stored in: /var/spool/cron/atjobs/
# filename format: %1c %5x %8x
# order: queue, job number, time / 60

set -eo pipefail
current_year=$(date +%Y)
current_month=$(date +%m | sed 's/^0//')
current_day=$(date +%d | sed 's/^0//')

year=$current_year
month=$current_month
day=$current_day

### we're testing this weirdness
#year=1752
#month=9
#day=1

cw=30
ch=30

yoff=51
xoff=105
backup=238

WORKING_DIR=~/.local/var/cal
mkdir -p $WORKING_DIR

cd "${WORKING_DIR}"
#git pull

### hack to load in clock widget?
hackvr-clock init | sed 's/_clock_face_digit[^ ]* /_clock_face_ /g'
clock_left=15
printf "_clock_face_hand_hour_ move -%s 0 0\n" $clock_left
printf "_clock_face_hand_minute_ move -%s 0 0\n" $clock_left
printf "_clock_face_hand_second_ move -%s 0 0\n" $clock_left
printf "_clock_face_ move -%s 0 0\n" $clock_left
while true;do
  hackvr-clock set
  sleep 1
done &
###

printf "%s move %s 0 -%s\n" "$USER" "$xoff" "$backup"

refresh="yep"

stdbuf -oL grep -v '^#' | while true;do
  if [ "$refresh" ];then
    unset refresh
#    first_dow="$(date -d $month/1/$year +%w)"

### this doesn't work for august 2020. outputs 4, should output 6
    first_dow=$[$(cal -d "${year}-${month}" | tail -n+3 | head -n1 | cut -d1 -f1 | wc -c) / 3]
    monthname="$(date -d $month/1/2000 +%B)" #year isn't important
    dow=$first_dow
    row=0
    d=1

### current month and its "button"
    printf "_cal_MONTH_ addshape 1 4  %s %s 0  %s %s 0  %s %s 0  %s %s 0\n" \
           $[0]                    $[1*$ch + $yoff] \
           $[(($cw * 7 ) / 2) - 1] $[1*$ch + $yoff] \
           $[(($cw * 7 ) / 2) - 1] $[1*$ch+($ch/2) + $yoff - 1] \
           $[0]                    $[1*$ch+($ch/2) + $yoff - 1]
    printf "%s\n" "${monthname}" | makelabel.sh "_cal_MONTH_" $[$xoff / 3] $[$yoff + $ch + 5] 0

### current year and its "button"
    printf "_cal_YEAR_ addshape 1 4  %s %s 0  %s %s 0  %s %s 0  %s %s 0\n" \
           $[($cw * 7 ) / 2 ]      $[1*$ch + $yoff] \
           $[$cw * 7 - 1]          $[1*$ch + $yoff] \
           $[$cw * 7 - 1]          $[1*$ch+($ch/2) + $yoff - 1] \
           $[($cw * 7 ) / 2 ]      $[1*$ch+($ch/2) + $yoff - 1]
    printf "%s\n" "${year}" | makelabel.sh "_cal_YEAR_" $[$xoff + 5] $[$yoff + $ch + 5] 0

### the <== button
    printf "_cal_prevmonth_ addshape 1 4  %s %s 0  %s %s 0  %s %s 0  %s %s 0\n" \
           $[-$cw] $[1*$ch + $yoff] \
           $[-1]   $[1*$ch + $yoff] \
           $[-1]   $[1*$ch+($ch/2) + $yoff - 1] \
           $[-$cw] $[1*$ch+($ch/2) + $yoff - 1]
    printf "<==\n" | makelabel.sh "_cal_prevmonth_" $[0 - $cw + 1] $[$yoff + $ch + 5] 0

### the ==> button
    printf "_cal_nextmonth_ addshape 1 4  %s %s 0  %s %s 0  %s %s 0  %s %s 0\n" \
           $[$cw * 7]    $[1*$ch + $yoff] \
           $[$cw * 8 -1] $[1*$ch + $yoff] \
           $[$cw * 8 -1] $[1*$ch+($ch/2) + $yoff - 1] \
           $[$cw * 7]    $[1*$ch+($ch/2) + $yoff - 1]
    printf "==>\n" | makelabel.sh "_cal_nextmonth_" $[$cw * 7 + 1] $[$yoff + $ch + 5] 0

    for d in $(cal -d $year-$month | tail -n+3 | tr '\n' ' ' | tr -s ' ');do
#    while [ "$d" -le "$days_in_month" ];do
#      printf "%s %s : %s\n" "$row" "$dow" "$d"
      if [ -f ${WORKING_DIR}/${year}_${month}_${d} ];then
        color=$[4+16]
      else
        color=$[5+16]
      fi
      printf "%s addshape %s 4  %s %s 0  %s %s 0  %s %s 0  %s %s 0\n" \
             "_cal_day_${d}_" "${color}" \
             "$[$dow*$cw]"       "$[-1*$row*$ch + $yoff]" \
             "$[$dow*$cw+$cw-1]" "$[-1*$row*$ch + $yoff]" \
             "$[$dow*$cw+$cw-1]" "$[-1*$row*$ch+$ch-1 + $yoff]" \
             "$[$dow*$cw]"       "$[-1*$row*$ch+$ch-1 + $yoff]"
      printf "%s\n" "${d}" | makelabel.sh "_cal_day_${d}_" "$[$dow*$cw + 1]" "$[-1*$row*$ch + $yoff + 1]" 0
      d=$[$d+1]
      dow=$[$dow + 1]
      if [ $dow = 7 ];then
        dow=0
        row=$[$row + 1]
      fi
    done
    if [ $month = $current_month -a $year = $current_year ];then
      printf "_cal_day_%s_ move 0 0 -2\n" "${current_day}"
    fi
  fi
  if ! read group action target;then
    exit
  fi
  #xmessage "$group $action $target"
  if [ "$action" = "action" ];then
    if [ "$target" = "_cal_nextmonth_" ];then
      month=$[month + 1]
      if [ $month = 13 ];then
        month=1
        year=$[$year + 1]
      fi
      refresh="yep"
    fi
    if [ "$target" = "_cal_prevmonth_" ];then
      month=$[month - 1]
      if [ $month = 0 ];then
        month=12
        year=$[$year - 1]
      fi
      refresh="yep"
    fi
    if [ "$target" = "_cal_MONTH_" ];then
      month="$(xmessage -buttons January:1,February:2,March:3,April:4,May:5,June:6,July:7,August:8,September:9,October:10,November:11,December:12 'pick a month';echo $?)"
      refresh="yep"
    fi
    if [ "$target" = "_cal_YEAR_" ];then
      year="$(seq $[$year - 5] $[$year + 5] | dmenu -p 'enter a year' | tr -cd '0-9' | sed 's/^$/1970/')"
      refresh="yep"
    fi
    if printf "%s\n" "$target" | grep '^_cal_day_' 2>&1 >/dev/null;then
      d="$(printf "%s\n" "$target" | cut -d_ -f4)"
      file=${WORKING_DIR}/${year}_${month}_${d}
      if [ -e "${file}" ];then
        derp=exists
      else
        derp=notexists
      fi
      x-terminal-emulator -e nano "${file}"
      if [ -e "${file}" ];then #if the file exists
        if [ ! -s "${file}" ];then #but the file is empty
          rm "${file}" >&2
          #git rm "${file}" >&2
          #git commit -m '[calvr] removed: ${file}' >&2
        else #the file is NOT empty, so it was changed, or not, might as well try to add and commit.
          echo "# lol wat?"
          #git add "${file}" >&2
          #git commit -m '[calvr] maybe changed: ${file}' >&2 # if nothing changed it won't bother to commit
          #git push # just to make it more magical
        fi
      fi
      if [ -e "${file}" ];then
        merp=exists
      else
        merp=notexists
      fi
      if [ "${derp}" != "${merp}" ];then
        refresh="yep"
      fi
    fi
  fi
  if [ "$action" = "quit" ];then
    exit
  fi
  if [ "$refresh" ];then
    ### I /might/ want to just make all of the calendar parts
    ### start with _cal_* so I can deletegroup _cal_*
    ### instead of nuking the world except the user.
    printf '%s deletegroup _cal_*\n' "$USER"
  fi
done