Hacker News new | comments | show | ask | jobs | submit login
Cal – Display a Calendar in Your Terminal (adriansieber.com)
160 points by adius on May 11, 2016 | hide | past | web | favorite | 92 comments



Just don't try to use two digit format for years:

    ~ $ cal 5 16
           May 16
    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
    ~ $ cal 5 2016
          May 2016
    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


I lost a hundred bucks to this behavior.

http://alangrow.com/blog/how-i-lost-100-and-blamed-cal


If you need a month in the current year, or the entire current year, that's easy:

    $ cal may
          May 2016
    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

    $ cal -y
                                  2016

          January               February               March
    Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
                    1  2      1  2  3  4  5  6         1  2  3  4  5
     3  4  5  6  7  8  9   7  8  9 10 11 12 13   6  7  8  9 10 11 12
    10 11 12 13 14 15 16  14 15 16 17 18 19 20  13 14 15 16 17 18 19
    17 18 19 20 21 22 23  21 22 23 24 25 26 27  20 21 22 23 24 25 26
    24 25 26 27 28 29 30  28 29                 27 28 29 30 31
    31

    [...]


How did you not notice calendar on the flight booking site? I've never used one that took a date string without showing a clickable calendar.


This was aa.com circa 2008, back when datepicker widgets were the hot new thing and calendars in popup windows ruled the earth.

Call me old-fashioned but I like keyboards (still)?


archive.org shows a date picker going back as far as 2002, but it is easy to pick a date from the drop down.


The dropdown doesn't help you with "fourth Thursday in November" though, and the calendar button launches a popup window that doesn't work. On archive.org at least -- may have worked at the time, but I disable popups, so...

Pretty sure my thought process was: need a Thanksgiving flight -> when is Thanksgiving this year? -> run cal(1) -> let's book.


Well, it's displaying the calendar for May of the year 16, not the year 2016. I guess it could require you to enter 0016, but I think the given behavior is reasonable.


$5 that says you can't find anyone in IxD that would see that as reasonable.


I agree with you, but cal could be formatting the date as %04d to make it clearer.


Well it doesn't matter, they're wrong.


I think better UX would be show me the closest one to today, which is 2016


For command line utilities I'll take correctness over usability any day.


You're right, correctness is important. And also wrong by thinking usability gets in the way of correctness

Usability helps with being correct

Vast majority of uses of cal apply to dates > 1900 (and I'd say a significant amount is > 2000)

'cal 16' should require a flag saying "Yes, I know what I'm doing, this is the actual year" and/or print the corresponding year for this century (being explicit, when printing, to which year it refers to)


> Vast majority of uses of cal apply to dates > 1900 (and I'd say a significant amount is > 2000)

According to what? Your use?

> 'cal 16' should require a flag saying "Yes, I know what I'm doing, this is the actual year" and/or print the corresponding year for this century (being explicit, when printing, to which year it refers to)

The command wants a year number as input. '16 is an ambiguous abbreviation that gains meaning only within context. As the command can't ask you what you meant, the default behaviour is sane.


Yes, 'cal 16' is ambiguous (is it 0016, 1916, 2016? Different software may return different answers).

Without an explicit flag that should be used in a script, the dwim behavior (2016) seems more appropriate for the interactive use.


cal 16 unambiguously refers to 16 a.d. Don't forget that we include an apostrophe before a shortened year.


> According to what? Your use?

Do you know anyone or any use case that requires calculations of years between 0-99 and uses cal?

Yes, it is quite obvious that most uses is for years > 1900, you're free to do a study yourself if that's what you want.

> As the command can't ask you what you meant, the default behaviour is sane.

Not from an usability point of view.


Agreed, this is great engineering and design. As expected, it does exactly what you tell it to.


It's showing you the one you asked for.


Even better UX is to show what you've requested, which is 16.


The western calendar didn't even exist until the 1500s, so asking for the calendar in 16AD is sort of contrived.


According to wikipedia, cal was in First Edition Unix, back in 1971. You can assume it's been used in scripts and it would be hard to change default behavior now, or any time in the last 30 years for that matter.

I've used it myself in scripts to find Julian day numbers, to count days-within-months, etc. -- for old science data -- before there were more robust ways to do this stuff.

It's hard to insert DWIM behaviors into old command-line utilities, because "what I mean" is not clear.


The closest 16 to today is 16.


Or, always show the year as four digits with leading zeros. Seeing "May 0016" gives you an indication that it just might not be this year.


That will cause problems in less than 8 thousand years.


It will anyway.

  cal: year `10000' not in range 1..9999


Surely the correct thing would be a config setting to warn you if you're displaying a year in the past (or a year before one that you specify - e.g. 100). Meh, even `cal 8` displays the year prominently at the top.


...said nobody before the Y2K bug...


Another useful command line service I use almost daily (using a rather wide terminal):

  $ curl wttr.in/94035
My most frequently used option for cal on GNU/Linux is "-3". It shows the current, previous, and next month with the current day highlighted, which are usually all the information I need.

  $ cal -3

         April 2016             May 2016              June 2016  
    Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa

                    1  2   1  2  3  4  5  6  7            1  2  3  4

     3  4  5  6  7  8  9   8  9 10 11 12 13 14   5  6  7  8  9 10 11

    10 11 12 13 14 15 16  15 16 17 18 19 20 21  12 13 14 15 16 17 18

    17 18 19 20 21 22 23  22 23 24 25 26 27 28  19 20 21 22 23 24 25

    24 25 26 27 28 29 30  29 30 31              26 27 28 29 30


wttr doesn't seem to like putty+windows very much: http://i.imgur.com/45KSLFx.png


This has to do with your character set. See Window->Translation->Remote char set. Change it to UTF-8 or the one that is on your system.


It was in UTF-8.

Part of the problem seems to be GNU Screen-- if I switch tabs, then switch back, the redraw seems to clobber some formatting characters.

EDIT: LC_CTYPE wasn't set for that user, but setting it didn't fix anything. So, who knows.


wttr.in looks awesome! I'm not going to complain about it, but it is a little funny that shows a big yellow sun under "Night".


A really fun detail in cal:

    ~$ cal 9 1752
       September 1752
    Su Mo Tu We Th Fr Sa
           1  2 14 15 16
    17 18 19 20 21 22 23
    24 25 26 27 28 29 30



A bit of trivia [1] linked from that discussion about Julian calendar still in use.

[1] https://en.wikipedia.org/wiki/Mount_Athos#Date_and_time_reck...


That feature already was in 6th edition UNIX, in 1975: http://man.cat-v.org/unix-6th/6/cal.

I don't think the 5th edition had cal.


FTA: I’d be really excited to hear all the use cases for gcal one can come up with. Seems really suited for a TODO list manager or to never forget a birthday again.

  $ man calendar
  CALENDAR(1)                 General Commands Manual                CALENDAR(1)

  NAME
     calendar - reminder service

  SYNOPSIS
     calendar [-abw] [-A num] [-B num] [-f calendarfile] [-t [[[cc]yy]mm]dd]

  DESCRIPTION
     The calendar utility checks the current directory or the directory
     specified by the CALENDAR_DIR environment variable for a file named
     calendar and displays lines that begin with either today's date or
     tomorrow's.  On Fridays, events on Friday through Monday are displayed.

  [...]


Geez, I had no idea about `calendar`. This is pretty nifty!


Cool, good to know! Maybe I'll write a future command line monday post about this. Sounds really helpful!


On OSX at least, if you run it as CAL instead of cal you get a sideways calendar:

    mcphage:~ $ CAL
        May 2016
    Mo     2  9 16 23 30
    Tu     3 10 17 24 31
    We     4 11 18 25
    Th     5 12 19 26
    Fr     6 13 20 27
    Sa     7 14 21 28
    Su  1  8 15 22 29


That is insane. The case-insensitive filesystem means the same binary runs, but the binary has a switch on the case of its own name.


A lot of apps pay attention to the name you run them as—for instance, making sure the correct name is reported when you list the command line switches. But this is definitely the most extreme case I'm aware of.


AKA ncal.


Yup, FreeBSD has cal and ncal. Latter has additional options for printing week numbers, date of Easter, etc., though I find it kind of hard to get used to transposed row/col output.


I love this original responsive and flat UI calendar and use it all the time.


Good ol cal! Circa 1998 my first homebrew web ui date picker input was just cal output redressed with html links ... And we were thankful for what we had!


Huh, despite being the "GNU" calendar program, gcal is in fact generally named gcal on GNU/Linux. On my Debian GNU/Linux machine, /usr/bin/cal is from bsdmainutils, and gcal is in its own package (as with Homebrew).


gcal highlighting the current date and '.' are nice features for me.

    $ brew info gcal
    gcal: stable 4 (bottled)
    Program for calculating and printing calendars
    https://www.gnu.org/software/gcal/
    /usr/local/Cellar/gcal/4 (81 files, 2.8M) *
      Poured from bottle on 2016-01-13 at 17:03:09
    From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/gcal.rb
    ==> Dependencies
    Build: xz

                                       2016


            April                      May                       June
      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa      Su Mo Tu We Th Fr Sa
                      1  2       1  2  3  4  5  6  7                1  2  3  4
       3  4  5  6  7  8  9       8  9 10<11>12 13 14       5  6  7  8  9 10 11
      10 11 12 13 14 15 16      15 16 17 18 19 20 21      12 13 14 15 16 17 18
      17 18 19 20 21 22 23      22 23 24 25 26 27 28      19 20 21 22 23 24 25
      24 25 26 27 28 29 30      29 30 31                  26 27 28 29 30


I once used cal as input to another program in the old days when there weren't many calendar APIs in C yet.

The program produced TeX output so I could print a nice wall calendar (complete with tasks and birthdays).

Was kind of klunky, but it worked.


also noteworthy: khal [0], a CLI calendar program which syncs to CalDAV servers with vdirsyncer [1].

[0] https://github.com/pimutils/khal

[1] https://github.com/pimutils/vdirsyncer


No GoT joke on khal Github!


I use 'cal' on a daily basis. I don't find any other calendar programs to be as convenient and simple to use.


I love cal, but M-x calendar is pretty awesome too.


M-x calendar is my go-to cal substitute on platforms that lack cal (coughWindowscough). Though, now that Windows 10 has a Linux subsystem, I might just use cal everywhere.


"cal" is the only calendar on my OS, who needs that other bloat.

Try:

  cal -m
I even have it aliased to "calm" :-)


The output is the same as just "cal" for me, so I had to see what it's about: It puts Monday as the first day of the week. I guess that is because I use the German date locale. Seems that the US uses Sunday as the first day of the week in calendars and such, but does it make any difference beyond those? Don't people "feel" that Monday is the first day of the week because the weekend is over and they have to get back to work?


Prior HN discussion about the reason for the first day of the week:

https://news.ycombinator.com/item?id=11360648


Interesting, thanks.


On OS X:

  cal: option requires an argument -- m
  usage: cal [-jy] [[month] year]
         cal [-j] [-m month] [year]
         ncal [-Jjpwy] [-s country_code] [[month] year]
         ncal [-Jeo] [year]


I feel Sunday is the start of the week because that's what I've been seeing on calendars my whole life. I do bundle Mon-Fri and Sat-Sun into "weekdays" and "weekend" in my head, but when I visualize a week in my head, it always starts on Sunday.


Just updated the post and added a section on how to set Monday as the first day of the week.


> Don't people "feel" that Monday is the first day of the week because the weekend is over and they have to get back to work?

No, I feel that Sunday is the day of rest I start my week with, then I do some work, and finally I rest again: in that way my day is a microcosm of my week (and one might think that in a more primitive society my year would be a macrocosm, as I did more work spring-summer than during the winter).

I personally detest calendars which display Monday as the first day of the week, and am genuinely curious why ISO chose that.


I personally detest calendars which display Sunday as the first day of the week, since it's incorrect according to one of the earliest memories I have -- my mum teaching my this rhyme:

  Solomon Grundy,
  Born on a Monday,
  Christened on Tuesday,
  Married on Wednesday,
  Took ill on Thursday,
  Grew worse on Friday,
  Died on Saturday,
  Buried on Sunday,
  That was the end,
  Of Solomon Grundy.
Also, Saturday and Sunday are the weekend, not the week-edges.

--

There's a bug in cal -- the man page says "-M" makes the week start on Monday, but my version doesn't accepthe argument.

I find it quite confusing when calendars mess this up. I once booked a flight on the wrong day, because I somehow switched to the American localization of the airline's website part-way through the booking process.


> Also, Saturday and Sunday are the weekend, not the week-edges.

You might be interested to know that in Israel the work week starts on Sunday, not Monday. Friday and Saturday are the weekend.

That might just be a factoid, except that the Jewish Sabbath was the origin of the weekend concept. It changed in countries with a strong Christian influence so that Monday because the first day.

It never changed in the US because the Jewish workweek had a stronger influence there than the Christian one.

> I personally detest calendars which display Sunday as the first day of the week

And I personally find calendars that start on Monday quite bizarre since it's obviously incorrect historically.


> I personally detest calendars which display Monday as the first day of the week, and am genuinely curious why ISO chose that.

I think ISO chose it because there was considerable difference between countries as to what the first day of the week in usual calendar presentation was when ISO 8601 was being considered, they needed something consistent, and it just happened to shake out to Monday.


Looking at https://en.wikipedia.org/wiki/Names_of_the_days_of_the_week#..., it appears that almost every language which numbers the days of the week starts on Sunday, with the exception of some Slavic languages (which use Monday) and Swahili (which uses Saturday).


The Chinese language family is a pretty big one, at least in terms of population. They all start numbering with Day One as Monday.


>and am genuinely curious why ISO chose that.

Because ISO is all about business, and Monday is the start of the business/banking etc week.


Why ISO 8601 has Monday as day #1 and Sunday as day #7 is explained in the standard itself, in Annex A (on page 25 in ISO 8601:2004).


Tried setting it to Swedish locale but either I did it wrong or it didn't do anything :)


try it with 'ncal' and a capital 'M'

     ncal -M [year]


FreeBSD (17 ~): ncal -M 2016 ncal: illegal option -- M Usage: cal [general options] [-hjy] [[month] year] cal [general options] [-hj] [-m month] [year] ncal [general options] [-hJjpwy] [-s country_code] [[month] year] ncal [general options] [-hJeo] [year] General options: [-NC3] [-A months] [-B months] For debug the highlighting: [-H yyyy-mm-dd] [-d yyyy-mm]


The -M and -S options are extensions that are patched into the Debian ports of the FreeBSD ncal command. They have not been contributed back to the original, and some of the weekday calculations (that involve querying what the current locale's idea of the first day of the week is using the SUS2 nl_langinfo() library function) are tied to GNU libc.

* http://anonscm.debian.org/cgit/bsdmainutils/bsdmainutils.git...

* http://anonscm.debian.org/cgit/bsdmainutils/bsdmainutils.git...


You can check out the follow up post at http://adriansieber.com/fold-wrap-lines-to-fit-in-specified-... =)


love Cal, call a script to use it in my .bashrc to show current date, user, day/time, logins and filesystem status.

    clear
    cal
    echo "Hey \033[1m$USER\033[0m it's \033[1m`date '+%A %d %B @ %T'`\033[0m" | 
          tr '[A-Z]' '[a-z]' 
    echo "logins:\c" ; who | wc -l
    df -h


Note that output from .bashrc stuffs up rsync and scp, in case you use them.

Enclose the lot in { .... } >&2

to send output to stderr instead.

Or only output if the session is interactive, with isatty or if PS1 is set or $- contains 'i'.


"Note that output from .bashrc stuffs up rsync and scp, in case you use them. Enclose the lot in { .... } >&2"

I call a shell script from my .bashrc so does this have the same effect? I'll take this advice and wrap the script. I don't use scp or rsync but possible could at some time, thanks @emmelaich.


cal is great, but I never remember it exists. I always (OSX) go up to the menubar datetime, get annoyed that there's no kind of simple calendar underneath it (just wrap cal!), then go hunting for Google Calendar. I guess I just don't think of that kind of program as a built-in command-line one.


I feel you, having used Linux (and I guess Windows) a lot longer than OSX this gets me every time, and every time I wonder why such a simple and useful feature was omitted.


iStat Menus can add a calendar under the clock.


Killer feature of gcal for me is that by default it highlights the current day. Didn't know about `gcal .`, which is very convenient to know; I used to do `gcal 2016` if I needed to see prev/next months.


I always learn about these stuff, think about using them all the time, then I totally forget until someone posts it again on HN.


no mention of "cal -y" which should have been the default most common use option IMHO.


if you really want to go nuts -

https://en.wikipedia.org/wiki/Util-linux

read all the pages, explore all the man pages, then experiment and learn.


I use cal almost every day. Way faster than phone or web page calendars.


Wow. Had no idea that existed. Looking forward to more tidbits


take a walk through /usr/share/doc

or go to the source: https://github.com/karelzak/util-linux


ncal is an interesting take on a calendar


gcal -n --astronomical-holidays


Just updated the post and added this as another useful flag =)




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: