Working with calendars in the shell
calendar
With calendar
, which most distributions preinstall with the bsdmainutils package, you can output the current date's events in the terminal. If you set the command without further options, you will see a long list of mostly irrelevant information. You can restrict the query to the UK, for example, by calling calendar
with the -f
parameter and an appropriate event file, as shown in Figure 6. Such files can be found in /usr/share/calendar/en_UK/
on most distributions.
You can enter your own additional calendar data in your personal .calendar
file. For example, on Debian and Ubuntu, copy the /usr/share/calendar/en_UK/calender.all
file to $HOME/.calendar
. Below the #include
statements, enter your own anniversaries and events (in Listing 5, the entries for January 6 and 7). Each record begins with the month number, and you separate the following day with a slash. You use the tab key as a field separator between the date and the entry text.
Listing 5
Personal Calendar Entries
/* * UK Calendar */ #ifndef _en_UK_all_ #define _en_UK_all_ #include <en_UK/calendar.holiday> #include <en_UK/calendar.history> #include <en_UK/calendar.christian> #include <en_UK/calendar.literature> #include <en_UK/calendar.music> #include <en_UK/calendar.science> 01/06 Annivery of First ascent Blaabjerg north face 01/07 Birthday mother in law #endif /* !_de_DE_all_ */
Taking a brief look at the calendar.christian
file, you can see how calendar
calculates the dependent holidays based on Easter Sunday. This function can be used to create your own calendars.
Table 2 contains some important options for using the program. You can save the call along with your preferred options as an alias in the shell's personal or system-wide configuration file.
Table 2
calendar Options
Action |
Option |
Specify the configuration file |
|
Output the weekday |
|
Number of days to show (future) |
|
Number of days to show (past) |
|
Show specific day |
|
1 -l0 restricts output to today |
Figure 7 shows some examples, where all commands refer to the user's personal calendar file. If you do not specify your personal file, Calendar resorts to the system-wide variant.
Calendars with pcal
The pcal
program [6], which can be found in the repositories of all the popular distributions, creates a calendar in PostScript or HTML format. Because of the extensive options and the granularity of the calendar data, working with it seems complicated at first. The tool's most important options are summarized in Table 3. The program's man page could certainly be a tad more user-friendly.
Table 3
pcal Options
Action |
Option |
Example |
Specify calendar config file |
|
|
Select language |
|
|
European date format |
|
– |
Paper format |
|
|
Empties fields for days not in the month |
|
– |
First weekday |
|
|
Show moon phase daily |
|
– |
Show moon phases |
|
Full moon, half moon, new moon |
Font |
|
Helvetica, 12 point |
Output file |
|
– |
Calendar month |
|
– |
Calendar year |
|
– |
Annual calendar on one page |
|
– |
Color black for specified day |
|
Saturday ( |
Deviating color |
|
Red on light beige for Sundays and holidays: |
You store the configuration of the desired calendar in a separate file, named .pcal
in our example. In the file, you define a calendar year with its holidays. Listing 6 shows an example for Germany with special regional holidays for Bavaria.
Listing 6
Personal .pcal file
01 # Week number on Monday 02 all Monday in all week %w 03 04 Easter # +/- is computed relative to Easter 05 # * by date = holiday 06 Monday after Easter* Easter Monday 07 Good_Friday* Good Friday 08 49th day after Easter* Whit Sunday 09 50th day after Easter* Whit Monday 10 39th day after Easter* Ascension Day 11 60th day after Easter* Corpus Christi 12 # none * = not a holiday 13 48th day before Easter Shrove Monday 14 46th day before Easter Ash Wednesday 15 7th day before Easter Palm Sunday 16 17 01. 01.* New Year 18 06. 01.* Epiphany 19 01. 05.* Labor Day 20 08. 08.* Peace Festival (Augsburg) 21 15. 08.* Assumption 22 03. 10.* German Unification Day 23 01. 11.* All Hallows 24 24. 12. Christmas Eve 25 25. 12.* 1st Day of Christmas 26 26. 12.* Boxing Day 27 31. 12. New Year's Eve 28 29 sun on_or_before 24. 12. 4th Sunday in Advent 30 sun on_or_before 17.12. 3rd Sunday in Advent 31 sun on_or_before 10.12. 2nd Sunday in Advent 32 sun on_or_before 3.12. 1st Sunday in Advent
Some special rules apply here. There are different specifications for the specific day. With all <day>
, you designate a day for which you want special highlighting. Listing 6, line 1, displays the word "Week" and the consecutive week number every Monday. Line 17 shows New Year's Day as a public holiday. There must be a space between the day and month entries.
To display a day as a public holiday, add an asterisk (*
) followed by the desired text. Many holidays are a fixed number of days before or after Easter (see Listing 6, lines 4-15). Other holidays work like New Year's Day: You specify the holiday with a fixed date, including an asterisk if it's a public holiday.
Christmas can be complicated because December 24 can also be the fourth Sunday in Advent (e.g., in 2023). You need to use on_or_before
here. This allows December 24 to be the fourth Sunday in Advent if it happens to be on a Sunday. You can then define the dates of the remaining Sundays in Advent (see lines 29-32 of Listing 6).
Nonstandard characters can cause problems here. Modern distributions use UTF-8 encoding, but pcal
insists on ISO-8859-15.
By default, pcal
outputs Sundays and holidays in gray, which usually makes these days more prominent in black and white prints. You can create an overview calendar with Sundays and holidays printed in red and the moon phases, using the code in Listing 7. Figure 8 shows the results.
Listing 7
Annual Calendar
$ pcal -f .pcal -a en -E -P a4 \ -B -F 0 -M -g sun \ -s 1.0:0.0:0.0/1.0:1.0:0.8 \ -b sat -n Helvetica/10 -w \ -o Calendar.ps 2021
You can create a monthly calendar without the -w
option; instead, you specify the month before the year (Listing 8). The result is shown in Figure 9. You can process the resulting PostScript file to create a complete calendar page by adding a photo, for example, using Inkscape.
Listing 8
Monthly Calendar
$ pcal -f .pcal -a en -E -P a4 \ -B -F 0 -M -g sun \ -s 1.0:0.0:0.0/1.0:1.0:0.8 \ -b sat -n Helvetica/10 \ -o January-2021.ps 01 2021
Appointment Management
A small but good command-line program named calcurse
, which you will find in the repositories of all the popular distributions, lets you manage general tasks and tasks with deadlines. The simple interface is more or less self-explanatory. If you have worked with Nano before, you will get along with the menu control used in calcurse
right away. You can jump between the Appointments, Calendar, and To do fields by pressing the tab key; you use the arrow keys to reach targets in your appointments and calendar. Figure 10 shows the full screen.
To enter a new appointment, press A and enter the start time, the end time, and the description text (Figure 11). Pressing Enter saves the new appointment (Figure 12). Press Ctrl+T to create a new task (Figure 13). Start by entering the task text, then press Enter, and then set a priority. This affects the order in which tasks are displayed. Figure 14 shows the appointment and task entries.
Pressing O takes you to more commands and the settings. You can export the calendar entries in the ICAL or PCAL format or import data in these formats. If you call calcurse
with the -a
option, it displays all appointments for the current date on-screen (Figure 15).
« Previous 1 2 3 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.