Вы находитесь на странице: 1из 9

3/6/2016

basically tech >>> The many uses of gcal

basically tech
97 The many uses of gcal
Friday 19th October, 2007
gcalis a remarkable console-based

program.

It can be used to print calendar information, much like cal, but with much more flexibility.
It can display holiday information for over 300 different countries and states.
It can display astronomical information such as sunrise, sunset, the current phase of the moon and much more.
It can also be used as a diary or personal reminder.
It can print the current date and time. (No, really! :) )
It can be used to display the start and stop of daylight saving.
I'll be providing examples of how to use gcalin all these ways. Bear in mind that this article just scratches the surface with regard to what
gcalcan actually be used for. You are limited by your imagination!
basic options
holidays
astronomical information
resource files
"low priority" resource file entries
"high priority" resource file entries
tidying up the output
fixed date list title
highlight today's date
remove repeating dates
spacing out entries
add holiday entries
more resource file tips
birthdays, anniversaries, etc
print the time
daylight saving
searching
customisation
useful links

basic options
gcalhas many

options. Here are a few of the basic ones.

$ gcal
October 2007
Su Mo Tu We Th Fr Sa
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

Just like cal, nothing special, however you can also display the week number:
$ gcal -K
October 2007
Su Mo Tu We Th Fr Sa CW
1 2 3 4 5 6 39
7 8 9 10 11 12 13 40
14 15 16 17 18 19 20 41
21 22 23 24 25 26 27 42
28 29 30 31
43

Or, instead of the day of the month, how about the day of the year?
$ gcal -j
October 2007
Sun Mon Tue Wed Thu Fri Sat
274 275 276 277 278 279
280 281 282 283 284 285 286
287 288 289 290 291 292 293
294 295 296 297 298 299 300
301 302 303 304

Or even both at once!


$ gcal -jb
Sun

October 2007
Mon
Tue
Wed
Thu
Fri
Sat
1(274) 2(275) 3(276) 4(277) 5(278) 6(279)

http://www.basicallytech.com/blog/archive/97/The-many-uses-of-gcal/

1/9

3/6/2016

basically tech >>> The many uses of gcal

7(280) 8(281) 9(282) 10(283) 11(284) 12(285) 13(286)


14(287) 15(288) 16(289) 17(290) 18(291) 19(292) 20(293)
21(294) 22(295) 23(296) 24(297) 25(298) 26(299) 27(300)
28(301) 29(302) 30(303) 31(304)
cal -3is a useful option

which displays 3 months at a time, and there is a gcalequivalent:

$ gcal .
2007
September
Su Mo Tu We Th Fr Sa
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

October
Su Mo Tu We Th Fr Sa
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

November
Su Mo Tu We Th Fr Sa
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

You can also use the options used to show week numbers and day of the year too. (Apply the option before the full stop, e.g. gcal -K .)
When displaying years (equivalent to cal -y), you can choose the layout. The default is four rows (blocks) of three months, but you can
change this with the -bflag, e.g:
$ gcal -b 6 2007
2007
January
Su Mo Tu We Th Fr Sa
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

February
Su Mo Tu We Th Fr Sa
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

...
(output trimmed to save space)
...
September
Su Mo Tu We Th Fr Sa
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

October
Su Mo Tu We Th Fr Sa
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

November
Su Mo Tu We Th Fr Sa
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

December
Su Mo Tu We Th Fr Sa
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

holidays
To display the holidays for England, Wales and the Isle of Man for the whole of the current year, use:
$ gcal -q GB_EN -n
Eternal holiday list:
New Year's Day (GB_EN)
St David's Day (GB_EN)
Mother's Day (GB_EN)
Mary's Annunciation Day (GB_EN)
Good Friday (GB_EN)
Beginning of Financial Year (GB_EN)
Easter Sunday (GB_EN)
Easter Monday (GB_EN)
Swallow Day (GB_EN)
St George's Day (GB_EN)
May Day (GB_EN)
Liberation Day (GB_EN)
Bank Holiday (GB_EN)
The Queen's Birthday (GB_EN)
Father's Day (GB_EN)
Tynwald Day (GB_EN)
Grotto Day (GB_EN)
Bank Holiday (GB_EN)
St Edward's Day (GB_EN)
Halloween (GB_EN)
Guy Fawke's Day (GB_EN)
Christmas Eve (GB_EN)
Christmas Day (GB_EN)
http://www.basicallytech.com/blog/archive/97/The-many-uses-of-gcal/

The year 2007 is NO leap year


+ Mon,
- Thu,
- Sun,
- Sun,
+ Fri,
- Sat,
+ Sun,
+ Mon,
- Sun,
- Mon,
+ Mon,
* Wed,
+ Mon,
- Sat,
- Sun,
* Thu,
- Wed,
+ Mon,
- Sat,
- Wed,
- Mon,
- Mon,
+ Tue,

1st Jan 2007 = -290 days


1st Mar 2007 = -231 days
18th Mar 2007 = -214 days
25th Mar 2007 = -207 days
6th Apr 2007 = -195 days
7th Apr 2007 = -194 days
8th Apr 2007 = -193 days
9th Apr 2007 = -192 days
15th Apr 2007 = -186 days
23rd Apr 2007 = -178 days
7th May 2007 = -164 days
9th May 2007 = -162 days
28th May 2007 = -143 days
9th Jun 2007 = -131 days
17th Jun 2007 = -123 days
5th Jul 2007 = -105 days
25th Jul 2007 = -85 days
27th Aug 2007 = -52 days
13th Oct 2007 = -5 days
31st Oct 2007 = +13 days
5th Nov 2007 = +18 days
24th Dec 2007 = +67 days
25th Dec 2007 = +68 days
2/9

3/6/2016

basically tech >>> The many uses of gcal

Boxing Day (GB_EN)


Sylvester/New Year's Eve (GB_EN)

+ Wed, 26th Dec 2007 = +69 days


- Mon, 31st Dec 2007 = +74 days

Bank Holidays are in bold.


If you want to display the holidays for your country, you can find a complete list of available country codes in the online gcaldocumentation.
If that is information overload, you can display a particular month (e.g. October 2007) like so:
$ gcal -q GB_EN -n 10 2007
October 2007
Su Mo Tu We Th Fr Sa
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
Eternal holiday list:
St Edward's Day (GB_EN)
Halloween (GB_EN)

- Sat, 13th Oct 2007 = -5 days


- Wed, 31st Oct 2007 = +13 days

And now let's go ethnic:


$ gcal --chinese-holidays -n
Eternal holiday list:
Chinese New Year's Eve (Chi)
Chinese New Year's Day 4644-0 (Chi)
Cycle 78/24-00 Ding-Hai/Pig (Chi)
Chinese New Year's Day (Chi)
Chinese New Year's Day (Chi)
Chinese New Year's Day (Chi)
Chinese New Year's Day (Chi)
Chinese New Year's Day (Chi)
Chinese New Year's Day (Chi)
Chinese New Year's Day (Chi)
Chinese New Year's Day (Chi)
Chinese New Year's Day (Chi)
Chinese New Year's Day (Chi)
Chinese New Year's Day (Chi)
Chinese New Year's Day (Chi)
Chinese New Year's Day (Chi)
Chinese New Year's Day (Chi)
Festival of Lanterns (Chi)
Lao Tze's Birthday (Chi)
Tomb-Sweeping Day (Chi)
Buddha's Birthday (Chi)
Dragon Boat Festival (Chi)
Star Festival (Chi)
Mid-Autumn Festival (Chi)
Confucius' Birthday (Chi)
Double-9 Day (Chi)
Bodhidharma's Birthday (Chi)
Solstice Day (Chi)

The year 2007 is NO leap year


- Sat,
- Sun,
- Sun,
- Mon,
- Tue,
- Wed,
- Thu,
- Fri,
- Sat,
- Sun,
- Mon,
- Tue,
- Wed,
- Thu,
- Fri,
- Sat,
- Sun,
- Sun,
- Mon,
- Thu,
- Thu,
- Tue,
- Sun,
- Tue,
- Sun,
- Fri,
- Thu,
- Sat,

17th Feb 2007 = -243 days


18th Feb 2007 = -242 days
18th Feb 2007 = -242 days
19th Feb 2007 = -241 days
20th Feb 2007 = -240 days
21st Feb 2007 = -239 days
22nd Feb 2007 = -238 days
23rd Feb 2007 = -237 days
24th Feb 2007 = -236 days
25th Feb 2007 = -235 days
26th Feb 2007 = -234 days
27th Feb 2007 = -233 days
28th Feb 2007 = -232 days
1st Mar 2007 = -231 days
2nd Mar 2007 = -230 days
3rd Mar 2007 = -229 days
4th Mar 2007 = -228 days
4th Mar 2007 = -228 days
2nd Apr 2007 = -199 days
5th Apr 2007 = -196 days
24th May 2007 = -147 days
19th Jun 2007 = -121 days
19th Aug 2007 = -60 days
25th Sep 2007 = -23 days
7th Oct 2007 = -11 days
19th Oct 2007 = +1 day
15th Nov 2007 = +28 days
22nd Dec 2007 = +65 days

Note that you can combine lists, so gcal -q GB_EN --chinese-holidays -nwould output a combined list (in proper date order) of UK
holidays and Chinese festivals.
There are a bewildering amount of calendar options.

astronomical information
gcaleven

offers the ability to check sunrise, sunset, moonrise, moonset, even the current phase of the moon, and more, much, much more.

I'll demonstrate just a couple of these options, otherwise this article will never end. I'll also introduce a vital component of serious gcaluse, a
gcalresource file.
You'll need to know your location in latitude and longitude, plus your height above sea level in meters. You might have to google it. With the
latitude and longitude, I have used degrees with decimal degrees as opposed to degrees, arcminutes, and arcseconds.
The default gcal resource file location is ~/.gcalrc, but this is a little limiting. Instead, create a directory named ~/.gcaland we'll put all our
resource files in there.
After that, create a resource file named ~/.gcal/astronomicaland edit it as follows.
; ~/.gcal/astronomical
;
;my latitude 51.7537N
;my longitude -0.4748E
;my height above sea level 60m (guesstimate)
0 Sunrise is at %25o+51.75-000.47+60
0 Sunset is at %25s+51.75-000.47+60
0 Moon phase %25O
0 %25Z
;

http://www.basicallytech.com/blog/archive/97/The-many-uses-of-gcal/

3/9

3/6/2016

basically tech >>> The many uses of gcal

Save the file and run the following command:


$ gcal --resource-file=$HOME/.gcal/astronomical -H no -ox
Thu, 18th Oct 2007:

(
(
(
(
(
(
(
(
(
(
(

@@@@@@@
@@@@@@@@@@
@@@@@@@@@@@@
@@@@@@@@@@@@@
@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@
@@@@@@@@@@@@@
@@@@@@@@@@@@@
@@@@@@@@@@
@@@@@@@

(
Moon phase 43%25+
Sunrise is at 07:29
Sunset is at 18:01

Within ~/.gcal/astronomical, the lines beginning with a semicolon are comments, and the lines beginning with a 0are actions for gcal. 0
is shorthand for 00000000which stands for "run this action every day of every month of every year", in the format yyyymmdd. The "action" is
the part of the entry which follows the 0; it may be just a text entry to be printed out, such as "check your e-mails", or it may contain more
complex calulations for gcalto run, such as determining when sunrise is.
These functions may or may not be useful to you, however bear in mind that gcalwas not designed as a high precision astronomical
calculation tool.

resource files
For serious use of gcal, you need to use resource files.
Using a resource file to flag dates which repeat is "mostly easy". :) If you have a look at some of the examples below, you'll soon pick up how
to easily set up both unique and repeat events. However, you should be aware that not all resource file entries are equal!
There are different 'levels' of resource file entry, which can be viewed in more detail in the coding scheme tables from the online
documentation. These different levels allow you some flexibility in prioritising resource file entries, depending on how you use gcal.
What these differing means of making resource file entries allow you to do is to make entries which are either printed all the time, or only on
certain occasions. For example, if you have a weekly event, such as a regular meeting, you may not want to be reminded of it every time you
consult your diary. The way you enter the reminder into your resource file combined with the way you use gcalwill allow you to just be
reminded of your regular meeting on the day it occurs, or maybe also the day before. I know this sounds confusing, so let me provide some
examples to explain this further.
"low priority" resource file entries
For want of a better term, I'm going to call these "low priority" resource file entries. In other words, these diary entries will only appear if gcal
is invoked in a certain way, plus you have specify the resource file(s) you are querying (with the -fflag as we'll see later).
Create a new resource file, which we'll call ~/.gcal/low. (This is as good a place as any to note that I've had issues with gcalresource file
names which contain an underscore. Don't use underscores in your gcalresource file names.)
; ~/.gcal/low
;
; comments begin with a semicolon
;
0 Print this message every day of every month of every year (low)
00000000 Something else which happens every day (low)
;
000000Thu Every Thursday (low)
000010Fri Every Friday in October (low)
200700Thu Every Thursday in 2007 (low)
200710Fri Every Friday in October 2007 (low)
;

The syntax is fairly simple. Dates are entered in a YYYYMMDD format, with a zeroed field representing all available years/months/days.
Therefore 00000000represents every day of every month of every year, with a single 0being shorthand for the same.
"high priority" resource file entries
Now we'll create a seperate resource file for "high priority" entries. These diary entries will appear no matter how you invoke gcal, as long as
you specify the resource file(s) concerned. You can effectively query as many resource files as you want.
; ~/.gcal/high
;
0*d1#999 Every day of every year (high)
0*d1Fri#99Fri.7 %25i0000Oct#0000Nov Every Friday in October and November (high)
0*d1Thu#99Thu.7 %25i0000Oct#0000Nov Every Thursday in October and November (high)
000010thu3 3rd Thursday in Oct (high)
20071019 19th October 2007 (high)
;

The syntax here here is slightly more complex. 0*d1#999literally means "days 1-999 of every year" which is effectively, every day of every
year.
0*d1Fri#99Fri.7literally

means "The first Friday to the 99th Friday of every year" which is effectively, every Friday of every year. I'm not
sure about the reasoning behind the .7(forcing every seven days, maybe?), but it is required (you can try it without :) ).
http://www.basicallytech.com/blog/archive/97/The-many-uses-of-gcal/

4/9

3/6/2016

basically tech >>> The many uses of gcal

%25i0000Oct#0000Novqualifies the period acted upon by restricting the start year to any year, and the start month to Oct, and
any year, and the end month to Nov. You can read more about inclusive date periods in the gcalonline documentation.

the end year to

Now we'll print today's diary entries from ~/.gcal/lowand ~/.gcal/high:


$ gcal -c -f /home/rob/.gcal/low+/home/rob/.gcal/high -u --date-format="gb"
Fixed date list:
Thu,
Thu,
Thu,
Thu,
Thu,
Thu,
Thu,

18th Oct 2007: 3rd Thursday in Oct (high)


18th Oct 2007: Every Thursday (low)
18th Oct 2007: Every Thursday in 2007 (low)
18th Oct 2007: Every Thursday in October and November (high)
18th Oct 2007: Every day of every year (high)
18th Oct 2007: Print this message every day of every month of every year (low)
18th Oct 2007: Something else which happens every day (low)

The -cflag makes gcaldisplay the fixed date messages for today.
And now tomorrow's entries (by way of comparison):
$ gcal -ct -f /home/rob/.gcal/low+/home/rob/.gcal/high -u --date-format="gb"
Fixed date list:
Fri,
Fri,
Fri,
Fri,
Fri,
Fri,
Fri,

19th Oct 2007: 19th October 2007 (high)


19th Oct 2007: Every Friday in October (low)
19th Oct 2007: Every Friday in October 2007 (low)
19th Oct 2007: Every Friday in October and November (high)
19th Oct 2007: Every day of every year (high)
19th Oct 2007: Print this message every day of every month of every year (low)
19th Oct 2007: Something else which happens every day (low)

The -ctflag makes gcaldisplay the fixed date messages for tomorrow. You can check for today and tomorrow with the flag -cdt.
Now we'll check a week ahead.
$ gcal -cdl@t7 -f /home/rob/.gcal/low+/home/rob/.gcal/high -u --date-format="gb"
Fixed date list:
Thu,
Thu,
Thu,
Fri,
Fri,
Fri,
Sat,
Sun,
Mon,
Tue,
Wed,
Thu,
Thu,

18th Oct 2007: 3rd Thursday in Oct (high)


18th Oct 2007: Every Thursday in October and November (high)
18th Oct 2007: Every day of every year (high)
19th Oct 2007: 19th October 2007 (high)
19th Oct 2007: Every Friday in October and November (high)
19th Oct 2007: Every day of every year (high)
20th Oct 2007: Every day of every year (high)
21st Oct 2007: Every day of every year (high)
22nd Oct 2007: Every day of every year (high)
23rd Oct 2007: Every day of every year (high)
24th Oct 2007: Every day of every year (high)
25th Oct 2007: Every Thursday in October and November (high)
25th Oct 2007: Every day of every year (high)

The -cdl@txxflag makes gcaldisplay the fixed date messages for today (-d), and a list of the fixed date messages starting from tomorrow
(l@t), and ending xxdays after today's date. There seems to be a limit of 83 days on lists of this sort.
You'll notice that in list mode (l@), where lists of periods are generated, seven days in this case, only the entries from ~/.gcal/highhave been
printed.
While it's possible to force gcalto print sequential single day entries without using list mode (you'd have to use a forloop), it's not really the
way gcalwas intended to be used, and is slower since you would be running multiple instances of gcal. Plus you're removing the option of
prioritising resource file entries, just for the sake of slightly easier resource file syntax.

tidying up the output


fixed date list title
The line which says Fixed date list:can be edited (perhaps replaced with today's date) or removed completely.
To replace Fixed date list:with today's date, you could use the following flag:
--heading-text="%253%25>1*K , %25>02&*D %25U %25Y %254"

To remove Fixed date list:completely, place an xflag after the cflag, something like this:
$ gcal -cxdl@t7 -f /home/rob/.gcal/low+/home/rob/.gcal/high -u --date-format="gb"

You can find information on how to format the --heading-textfield here.


highlight today's date
Notice is that today's entries have the date part "highlighted" in reverse video. It's useful, a bit untidy, but it can be modified to something more
aesthetically pleasing. We'll need to change two settings, the date format, and the highlighting sequence.
The default date format for GB is:
http://www.basicallytech.com/blog/archive/97/The-many-uses-of-gcal/

5/9

3/6/2016

basically tech >>> The many uses of gcal

%25<3#K, %251%25>2&*D%252 %25<3#U %25>04*Y

The parts I have in red, %251and %252determine where the highlighting begins and ends.
We can change the highlighting sequence with the -Hflag. The filed which follows -Hconsists of 4 parts, seperated by colons. These are:
actual_day_start:actual_day_end:holiday_start:holiday_end. I don't feel a particular need to highlight holidays, and I prefer
bold/highlight to reverse video:
-H '^[[1m:^[[0m:^[[0m:^[[0m'

ANSI sequences work fine. Note that ^[represents an ANSI escape sequence. Ctrl-v Escshould create this in bash or vim if you're writing
a script for gcal.
So now if we add the relevant flags to our gcalcommand line, we get something which is becoming increasingly unwieldy:
gcal -cdl@t7 -f /home/rob/.gcal/low+/home/rob/.gcal/high -u --heading-text="%253%25>1*K , %25>02&*D %25U %25Y
%254" --date-format='%251%25<3#K, %25>2&*D %25<3#U %25>04*Y%252' -H '^[[1m:^[[0m:^[[0m:^[[0m'

Scripts are definitely the way to go.


There are three default date format settings. These are: de, us, and gb. Unsurprisingly, the date format can be heavily personalised and you can
read more about the --date-formatflag in the online docs.
remove repeating dates
Next, note how the same date is repeated for each diary entry which occurs on that day. This can be removed so that only one date is printed
by using the -ooption.
spacing out entries
We can also space out entries by grouping dates together with the -gflag.
add holiday entries
If we now add our holiday entries, we should have the beginnings of a useful command-line diary. I need to add the -eflag to enable holiday
output, and -q GB_ENto specify my country code.
$ gcal -cdeol@t7 -f /home/rob/.gcal/low+/home/rob/.gcal/high -u -g -q GB_EN --heading-text="%253%25>1*K ,
%25>02&*D %25U %25Y %254" --date-format='%251%25<3#K, %25>2&*D %25<3#U %25>04*Y%252' -H
'^[[1m:^[[0m:^[[0m:^[[0m'
Thursday, 18th October 2007
Thu, 18th Oct 2007: 3rd Thursday in Oct (high)
Every Thursday in October and November (high)
Every day of every year (high)
Fri, 19th Oct 2007: 19th October 2007 (high)
Every Friday in October and November (high)
Every day of every year (high)
Sat, 20th Oct 2007: Every day of every year (high)
Sun, 21st Oct 2007: Every day of every year (high)
Mon, 22nd Oct 2007: Every day of every year (high)
Tue, 23rd Oct 2007: Every day of every year (high)
Wed, 24th Oct 2007: Every day of every year (high)
Thu, 25th Oct 2007: Every Thursday in October and November (high)
Every day of every year (high)

more resource file tips


~/.gcal/lowand ~/.gcal/highhave served

their purpose now. They aren't particularly intuitive names for resource files. The following
examples will be using two new resource files, ~/.gcal/regular, for regularly repeating events such as birthdays, anniversaries and the like,
and ~/.gcal/diaryfor one-off events such as appointments and other reminders.
In addition, having different levels of resource file entry can be confusing. Thankfully, my life isn't that complex that I can really make use of it,
so for the remaining examples, I'll be using "high" priority examples only. If you're really interested in the different coding schemes for
resource file entries, and which flags applied to gcalwill display them, there is a section in the online gcaldocumentation which explains this
in more detail.
Since you aren't restricted (within reason) as to the number of resource files you can query at any one time, you could create extra resource
files, such as one for work or business-related matters, one (or more) for your getting things done reminders, one for friends, etc. You are
limited by your imagination, and the number of resource files you actually want to maintain.
In the following examples, the command which I'll be running will be:
$ gcal -cdeol@t14 -f /home/rob/.gcal/diary+/home/rob/.gcal/regular -u -g -q GB_EN --heading-text="%251%25>1*K ,
%25>02&*D %25U %25Y %252" --date-format='%251%25<3#K, %25>2&*D %25<3#U %25>04*Y%252' -H
'^[[1m:^[[0m:^[[0m:^[[0m'
http://www.basicallytech.com/blog/archive/97/The-many-uses-of-gcal/

6/9

3/6/2016

basically tech >>> The many uses of gcal

So to recap, we'll now be listing entries


for the next 14 days
from the resource files ~/.gcal/diaryand ~/.gcal/regular
we'll include GB_EN holidays
we'll change the heading text to today's date, format weekday, date month year, which will be highlighted (everything between %251
and %252)
the date format for entries will be weekday(first three chars), date month(first three chars) year:, and the whole date will be highlighted
if it's today only.
(It's hard to see, but there are two spaces either side of %25Uin the --heading-textflag. I found this was required, you may not.)
birthdays, anniversaries, etc
In addition to the usual entry for birthdays, you can add a little extra information. Let's assume our mutual friend Fred Bloggs (good old Fred)
was born in 1964, on October 21st:
; ~/.gcal/regular
;
; birthdays
00001021 Fred's %25>1&*B1964 birthday

(I've found that two spaces are required after the birth year entry. ymmv.)
And I'll get the following output:
Thursday, 18th October 2007
Sun, 21st Oct 2007: Fred's 43rd birthday
Wed, 31st Oct 2007: Halloween (GB_EN)

print the time


If we have to take the bicycle to be repaired at 11am on Friday 19th, it may be useful to print the current time:
; ~/.gcal/diary
;
; 2007
00001019 11:00 Bicycle to be repaired. Time now is %25t

Which produces:
Thursday, 18th October 2007
Fri, 19th Oct 2007: 11:00 Bicycle to be repaired. Time now is 21:57
Sun, 21st Oct 2007: Fred's 43rd birthday
Wed, 31st Oct 2007: Halloween (GB_EN)

daylight saving
Daylight saving is easy to flag up using gcal:
; ~/.gcal/regular
;
; birthdays
00001021 Fred's %25>1&*B1964 birthday
;
; GMT/BST
; BST starts the last Sunday in March
000003Sun9 British Summer Time starts (clocks go forward)
; GMT starts the last Sunday in October
000010Sun9 British Summer Time ends (clocks go back)

which provides:
Thursday, 18th October 2007
Fri, 19th Oct 2007: 11:00 Bicycle to be repaired. Time now is 22:04
Sun, 21st Oct 2007: Fred's 43rd birthday
Sun, 28th Oct 2007: British Summer Time ends (clocks go back)
Wed, 31st Oct 2007: Halloween (GB_EN)

I understand that the EU has standardised it's daylight saving times, so the above should work throughout the EU. Visit Merlyn - Summer Time
- J R Stockton for advice on calculating daylight saving for North America and other countries.

searching
You can also search your resource files for entries. To do so, use the -I <search_pattern>flag. To make the search case-insensitive, also
use the --ignore-caseflag. For instance, if I wanted to search for "bicycle" (how convenient) in the next 14 days' entries:
$ gcal -cdeol@t14 -f /home/rob/.gcal/diary+/home/rob/.gcal/regular -u -g -q GB_EN --heading-text="%251%25>1*K ,
http://www.basicallytech.com/blog/archive/97/The-many-uses-of-gcal/

7/9

3/6/2016

basically tech >>> The many uses of gcal

%25>02&*D %25U %25Y %252" --date-format='%251%25<3#K, %25>2&*D %25<3#U %25>04*Y%252' -H


'^[[1m:^[[0m:^[[0m:^[[0m' -I bicycle --ignore-case
Thursday, 18th October 2007
Fri, 19th Oct 2007: 11:00 Bicycle to be repaired. Time now is 22:16

This search facility will work for holiday entries too, so you could search for "halloween".

customisation
I do like to tinker with my scripts, customising the output (you've got to love sed!), and when I run my personal gcaldiary script using the two
resource files we've created above (~/.gcal/diaryand ~/.gcal/regular), I get the following (I prefer to use a term with a dark
background):
Thursday, 18th October 2007
Tomorrow

11:00 Bicycle to be repaired. Time now is 22:24

Sun 21/10/2007

Fred's 43rd birthday

Sun 28/10/2007

British Summer Time ends (clocks go back)

Wed 31/10/2007

Halloween (GB_EN)

This script is provided under GPLv3. Its current incarnation (it changes every now and again) is available, for those who are interested, here.
It's a little messy but you're welcome to have a look/borrow/use.
Currently, the script is invoked from ~/.bashrcthe first time I open a terminal (i.e. opening subsequent terminals do not run the script), and
each time I check my mail.

I hope this has been a helpful introduction to gcal. It's really just touching the surface of the program, there's so much depth to it. If you have
your own tips, or different ways of using gcal, (particularly in a "getting things done" environment) I'd be interested to hear about them.

Useful links
gcal 3.00 documentation
Merlyn - Summer Time - J R Stockton (used to calculate BST/GMT/DST dates)
Home
command line open source tech tips
Sat 5 Mar 2016
Links
Homepage
Blog front page

Recent entries
125 GCHQ has probably spied on you
Wed 30 Sep 2015
124 UK surveillance worse than anything Orwell could have foreseen
Tue 25 Aug 2015
123 Proposed EU Data Protection amendments taken word for word from US Lobbyists
Tue 12 Feb 2013
122 Refuse to be terrorised
Sun 29 Jul 2012
121 Battle for the Internet
Wed 18 Apr 2012
120 PCI Lawsuit
Tue 17 Jan 2012
119 30 online sources for Linux/Unix documentation
http://www.basicallytech.com/blog/archive/97/The-many-uses-of-gcal/

8/9

3/6/2016

basically tech >>> The many uses of gcal

Mon 9 Jan 2012


118 Lessons from Wikileaks
Tue 7 Dec 2010
117 "Apple has declared war on the tinkerers of the world"
Mon 1 Feb 2010
116 London Stock Exchange moving to a GNU/Linux-based system
Wed 7 Oct 2009
115 London Stock Exchange abandoning Windows
Fri 3 Jul 2009
114 Debian lenny MailScanner woes
Fri 3 Apr 2009
113 The Tech Lab: Bruce Schneier
Sat 21 Mar 2009
112 Linux tips every geek should know
Mon 2 Mar 2009
111 sed and iostat
Sat 22 Nov 2008
Contact details
E-mail: blog@basicallytech.com
Affiliated site
Exotic Trousers
blog software developed by basically tech. This software is still under development.

http://www.basicallytech.com/blog/archive/97/The-many-uses-of-gcal/

9/9

Вам также может понравиться