Hacker News new | ask | show | jobs
by ginko 1458 days ago
I hacked up my own little bash script[1] to show the next 3 months with ncal like this:

  $ mcal
          June 2022          
   w| Mo Tu We Th Fr Sa Su   
  22|        1  2  3  4  5   
  23|  6  7  8  9 10 11 12   
  24| 13 14 15 16 17 18 19   
  25| 20 21 22 23 24 25 26   
  26| 27 28 29 30            
                           
          July 2022          
   w| Mo Tu We Th Fr Sa Su   
  26|              1  2  3   
  27|  4  5  6  7  8  9 10   
  28| 11 12 13 14 15 16 17   
  29| 18 19 20 21 22 23 24   
  30| 25 26 27 28 29 30 31   
                           
         August 2022         
   w| Mo Tu We Th Fr Sa Su   
  31|  1  2  3  4  5  6  7   
  32|  8  9 10 11 12 13 14   
  33| 15 16 17 18 19 20 21   
  34| 22 23 24 25 26 27 28   
  35| 29 30 31
[1] https://pastebin.com/BNWynUZT
8 comments

there's also `cal`, in the util-linux package.

    cal -3



     May 2022              June 2022             July 2022     
  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
   1  2  3  4  5  6  7            1  2  3  4                  1  2
   8  9 10 11 12 13 14   5  6  7  8  9 10 11   3  4  5  6  7  8  9
  15 16 17 18 19 20 21  12 13 14 15 16 17 18  10 11 12 13 14 15 16
  22 23 24 25 26 27 28  19 20 21 22 23 24 25  17 18 19 20 21 22 23
  29 30 31              26 27 28 29 30        24 25 26 27 28 29 30
                                              31
`cal -n 3` to be precise, since ginko said "next three months"
I remember, in School, our professor asked us to write "cal" command in C in early CS classes. I was a good exercise for us to build interest in programming.
Not being aware of ncal, but based on long experience of bash, I anticipated a fiendish and impenetrable 300 line monster full of arcana to crank this out from first principles. So this was a very elegant surprise :)
`ncal -A2` will do the same, but show the months horizontally.
I see there's a -v flag for vertical layout which matches horizontal listing better.
The -v flag didn't work in my WSL.

This worked:

   $ ncal -b -M -A2
       June 2022             July 2022            August 2022
   Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
          1  2  3  4  5               1  2  3   1  2  3  4  5  6  7
    6  7  8  9 10 11 12   4  5  6  7  8  9 10   8  9 10 11 12 13 14
   13 14 15 16 17 18 19  11 12 13 14 15 16 17  15 16 17 18 19 20 21
   20 21 22 23 24 25 26  18 19 20 21 22 23 24  22 23 24 25 26 27 28
   27 28 29 30           25 26 27 28 29 30 31  29 30 31
-v didn't work on 12.1.7+nmu3ubuntu1 and -M does nothing seemingly. `ncal -b -A2` looks very good.
-M sets the first day of the week to Monday. If in your locale the weeks already begin on Monday you are not going to see much difference on the output.
Ah, my bad. I'm on Arch and it packages cal, not ncal. Wasn't familiar with it and it looks like the flags are different. Because why not...
Using cal from util-linux; if you are okay with horizontal:

    cal -w -n3
If you must have vertical:

    cal  -w today; cal -w '+1 month'; cal -w '+2 month'
Output:

           June 2022       
       Mo Tu We Th Fr Sa Su
    22        1  2  3  4  5
    23  6  7  8  9 10 11 12
    24 13 14 15 16 17 18 19
    25 20 21 22 23 24 25 26
    26 27 28 29 30         
                           
           July 2022       
       Mo Tu We Th Fr Sa Su
    26              1  2  3
    27  4  5  6  7  8  9 10
    28 11 12 13 14 15 16 17
    29 18 19 20 21 22 23 24
    30 25 26 27 28 29 30 31
                           
          August 2022      
       Mo Tu We Th Fr Sa Su
    31  1  2  3  4  5  6  7
    32  8  9 10 11 12 13 14
    33 15 16 17 18 19 20 21
    34 22 23 24 25 26 27 28
    35 29 30 31
Every year, I use `cal` to generate the calendar like this for the year, paste that into word and do some minor formatting (dim weekends and holidays, bold paydays) and print it and put it on my office wall. I reference it all the time just to re-orient myself to where I am in the month/year, etc.
On MacOS:

   $ LANG=C cal -3
      May 2022             June 2022             July 2022        
    Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  
     1  2  3  4  5  6  7            1  2  3  4                  1  2  
     8  9 10 11 12 13 14   5  6  7  8  9 10 11   3  4  5  6  7  8  9  
    15 16 17 18 19 20 21  12 13 14 15 16 17 18  10 11 12 13 14 15 16  
    22 23 24 25 26 27 28  19 20 21 22 23 24 25  17 18 19 20 21 22 23  
    29 30 31              26 27 28 29 30        24 25 26 27 28 29 30  
                                                31
Well, cal -3 shows the previous and next month, but I wanted this month and the next two months. I also wanted them arranged vertically and with week numbers. (And with weeks starting on Monday)
Neat! I was thinking of hacking something for org-mode (to support creating events and gcal sync) but this is definitely good for quick lookup.
If you're interested, I can share my khal config with you. It also displays 3 months, and syncs (via vdirsyncer) with Nextcloud to show my personal and work calendar events, all right there in the terminal.
Not the person you replied to, but I'm interested and would like more info on your setup.
In general, I use vdirsync to sync my contacts and calendars locally, keeping the remote system's values to resolve conflicts as I intend to only read the values from the CLI. Vdirsync uses an application-agnostic format, so I could in theory read from any application that supports standard file formats:

    $ cat ~/.vdirsyncer/config

    [general]
    status_path = "~/.vdirsyncer/status/"

    # Contacts

    [storage contacts_personal_local]
    type = "filesystem"
    path = "~/.vdirsyncer/contacts/"
    fileext = ".vcf"

    [storage contacts_personal_remote]
    type = "carddav"
    url = "https://example.com/remote.php/carddav/"
    username = "bloodninja"
    password = "hunter2"

    [pair contacts_personal]
    a = "contacts_personal_local"
    b = "contacts_personal_remote"
    collections = ["from a", "from b"]
    conflict_resolution = "b wins"

    # Calendars

    [storage calendar_personal_local]
    type = "filesystem"
    path = "~/.vdirsyncer/calendars/"
    fileext = ".ics"

    [storage calendar_personal_remote]
    type = "caldav"
    url = "https://example.com/remote.php/caldav/"
    username = "bloodninja"
    password = "hunter2"

    [pair calendars_personal]
    a = "calendar_personal_local"
    b = "calendar_personal_remote"
    collections = ["from a", "from b"]
    conflict_resolution = "b wins"
    metadata = ["color"]

Then I set up khal to read from the directory that vdirsync stores data in, and display three months with events and use the ISO-8601 date format:

    $ cat ~/.config/khal/config
    [calendars]

    [[personal]]
    path = ~/.vdirsyncer/calendars/*
    type = discover



    [default]
    default_calendar = personal
    highlight_event_days = True
    timedelta = 45d

    [locale]
    firstweekday = 6
    timeformat = %H:%M
    dateformat = %Y-%m-%d
    longdateformat = %Y-%m-%d
    datetimeformat = %Y-%m-%d %H:%M
    longdatetimeformat = %Y-%m-%d %H:%M
    default_timezone = Asia/Jerusalem
    unicode_symbols = False

    [highlight_days]
    color = light green
    method = fg
If you have any questions or suggestions I'll be watching this thread.