-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwpc.sh
152 lines (124 loc) · 3.79 KB
/
wpc.sh
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
#! /bin/bash
ARG0=$(basename $0 .sh)
ARG0DIR=$(dirname $0)
[ $ARG0DIR == "." ] && ARG0DIR=$PWD
source "$ARG0DIR/global"
help() {
usage
echo
echo Options:
echo $'\t'-v .. Version
echo $'\t'-y .. Year eg: 2012
echo $'\t'-m .. Month eg: 02
echo $'\t'-d .. Day eg: 01
echo $'\t'-H .. Calendar header default format eg: \"May - 2012\"
echo $'\t'-o .. Output file
echo $'\t'-c .. Calendar Output file
echo $'\t'-O .. Same as -o, but opens the result after creation
echo $'\t'-S .. Print the calendar directly on to the background
echo
echo $'\t'-h .. Help
exit 0;
}
# the calendar is printed on the sticky note.
# If set to "0" it will be printed directly to the background
STICKYCAL="1"
# This variable has to be set to a file, that will be opened. for debugging only
OPENRESULT=
while getopts vhSc:o:O:H:y:m:d: flag
do
case "$flag" in
(y) YEAR="$OPTARG";;
(m) MONTH="$OPTARG";;
(d) DAY="$OPTARG";;
(H) HEADER="$OPTARG";;
(o) OUTFILE="$OPTARG";;
(c) CALMARK="$OPTARG";;
(O) OUTFILE="$OPTARG"
OPENRESULT="$OUTFILE"
;;
(S) STICKYCAL="0";;
(h) help; exit 0;;
(v) version; exit 0;;
(*) echo
help;;
esac
done
shift $(expr $OPTIND - 1)
createCalText() {
# the output file will be set in "global" or from command line.
outfile=${OUTFILE:-$RESULT}
# date can be set with command line
# see help for more info
year=${YEAR:-`date "+%Y"`}
month=${MONTH:-`date "+%m"`}
day=${DAY:-`date "+%d"`}
# get calendar data file. fileName format: YYYY-MM.txt
# MM must have leading 0's eg: 01
cBodyTxt=`cat $DTXT/$year-$month.txt`
#echo "cal-file: "$DTXT$year"-"$month".txt"
# header may be set from command line -H parameter. Mainly for testing
# header format eg: May - 2012
cHeaderTxt=${HEADER:-`date "+%b - %Y" --date=$year"/"$month"/"$day`}
# dow: day of week .. 1 is Monday
# week: calendar week .. 1..53
# needs to be created with --date because of command line
dow=`date "+%u" --date=$year"/"$month"/"$day`
week=`date "+%V" --date=$year"/"$month"/"$day`
# first week of the actual month. needed for day marker line calculation.
fw=`date "+%V" --date=$year"/"$month"/01"`
#echo "fw: "$fw
#echo "week: "$week
# due to the format of the calendar there has to be some corrections
# to calclulate the right row/line for the actual day indicator
if [ $fw -ge "52" ] && [ $week -ge "52" ]
then
week="0"
elif [ $fw -ge "52" ]
then
local a=a
# no correction needed
else
# numbers with leading zeros are octal!
# 10#$week ... forces week to be base 10
week=$((10#$week - 10#$fw))
fi
# echo "fw: "$fw
# echo "week: "$week
# create the calendar text
convert -size ${AREA} xc:transparent -font $TXT_FONT \
-pointsize 22 -fill "$TXT_COLOR" -gravity NorthWest -draw "text 45,70 '${cHeaderTxt}'" \
-pointsize 18 -fill "$TXT_COLOR" -draw "text 45,120 '${cBodyTxt}'" $CALTXT
}
createDayMarker() {
# positions are relative to the stiky note AREA
iposx="34"
iposy="158"
dx="55"
dy="22"
xx=$(( iposx + dx * dow))
yy=$(( iposy + dy * week))
#echo $xx, $yy
# TODO find better day markers
# actual day marker (??). Replace the ? with spaces.
#dm="» «"
dm="( )"
#convert -size ${AREA} xc:transparent -font $MARKER_FONT \
convert $CALTXT -font $MARKER_FONT \
-pointsize 18 -fill "$MARKER_COLOR" -draw "text $xx,$yy '$dm'" $CALMARK
}
createCalText
createDayMarker
if [ $STICKYCAL ]
then
"$ARG0DIR/wpc-note.sh" -o $CALMARK
fi
# draw the calendar top right to the background
convert $WPBG -gravity NorthEast -draw "image over 0,0 0,0 '$CALMARK'" "$outfile"
#convert $WPBG -gravity NorthEast -draw "image over 0,0 0,0 test/stickyNote.png" ${outfile}
# gsettings is done by the calling script now
# gsettings set org.gnome.desktop.background picture-uri "file:///media/Daten/Git/x.calendar/"$RESULT
if [ ${#OPENRESULT} -ne 0 ]
then
open $OPENRESULT
fi