Chris's Wiki :: blog/unix/CalUnfortunateArguments Commentshttps://utcc.utoronto.ca/~cks/space/blog/unix/CalUnfortunateArguments?atomcommentsDWiki2016-07-11T13:29:56ZRecent comments in Chris's Wiki :: blog/unix/CalUnfortunateArguments.By vaclav on /blog/unix/CalUnfortunateArgumentstag:CSpace:blog/unix/CalUnfortunateArguments:5452a6aedd3499317e4c123d18ec837db91d0fc1vaclav<div class="wikitext"><p>gcal 7</p>
</div>2016-07-11T13:29:56ZBy Mike G. on /blog/unix/CalUnfortunateArgumentstag:CSpace:blog/unix/CalUnfortunateArguments:3ac66c77fb31300025f3c25400f5d0df9a246380Mike G.<div class="wikitext"><p>To add to the fun, on the version of cal installed on Linux boxes here, the -m switch makes Monday the first day of the week. So you still get the calendar for 7 AD if you do 'cal -m 7'...</p>
</div>2016-07-05T19:04:43ZBy Ewen McNeill on /blog/unix/CalUnfortunateArgumentstag:CSpace:blog/unix/CalUnfortunateArguments:7da34acb632a5933626cfea88357f4bc84e0f1cfEwen McNeill<div class="wikitext"><p>I think it'd be fair to say that <code>cal</code> violates the Principle of Least Surprise in several ways -- it has an <em>optional</em> (positional) argument which is <em>prepended</em> to the command line, which is very un-unixy. And it changes from "display month" to "display year" mode when given a single (positional) argument. I expect this behaviour dates from well before anyone really thought about UI carefully.</p>
<p>Typically I find that I want to see the whole year calendar, so I ended up making myself a <code>caly</code> command, which displays the current year's calendar, and teaching myself to type that instead. But I do like the <code>dcal</code> idea (even if not the name as much).</p>
<p>The unixy way for cal to operate I think would be to take "-y" and "-m" for year and month, both optional, both in either order, with the defaults if omitted being the current value. And probably to use the "1-12 = month if unqualified, otherwise year if unqualified" heuristic to "do what I mean". (It looks like the MacOS/Linux versions do all of that, except the 1-2 heuristic; and AFAICT adding that heuristic breaks almost nothing in real life.)</p>
<p>Ewen</p>
</div>2016-07-04T23:03:51ZBy James on /blog/unix/CalUnfortunateArgumentstag:CSpace:blog/unix/CalUnfortunateArguments:c469c4b4354fcf074d9e6864d055619a61f8889bJames<div class="wikitext"><p>The argument for "it's near the end of the month" is <code>-3</code>. I pass it by muscle memory default now, it only bites me on OS X (but then I don't use Solaris these days, or *BSD ever).</p>
</div>2016-07-04T15:49:05ZBy Aristotle Pagaltzis on /blog/unix/CalUnfortunateArgumentstag:CSpace:blog/unix/CalUnfortunateArguments:a98ab33f6bd59be7ccf3018564a82e57d8d7ccebAristotle Pagaltzishttp://plasmasturm.org/<div class="wikitext"><p>Funny, Christian, this is my <code>~/bin/dcal</code> (as in “DWIM <code>cal</code>”):</p>
<pre>
#!/bin/bash
v=$(( $1 + 0 ))
y=`date +%Y`
if (( v <= 12 && v >= 1 )) ; then cal $v $y
elif (( v <= ((y % 100)+40) )) ; then cal $(( (y/100) *100 + v ))
elif (( v <= 99 )) ; then cal $(( (y/100-1)*100 + v ))
else cal "$@"
fi
</pre>
<p>I guess the Unix ethos is that if you want user-friendly UI, you <a href="https://daringfireball.net/2004/04/spray_on_usability">sprinkle it on top</a>…</p>
</div>2016-07-03T17:38:01ZBy Christian Neukirchen on /blog/unix/CalUnfortunateArgumentstag:CSpace:blog/unix/CalUnfortunateArguments:3f7a5ea3ac85544a895a6d00ffa1565e7e346415Christian Neukirchenhttp://chneukirchen.org/<div class="wikitext"><p>That's why I have this function. ;)</p>
<pre>
mcal() { cal "$@" $(date +%Y) }
</pre>
</div>2016-07-03T15:32:10ZBy Jinks on /blog/unix/CalUnfortunateArgumentstag:CSpace:blog/unix/CalUnfortunateArguments:4994411ef19350ce11881d22b55e7cffdac7e1c8Jinks<div class="wikitext"><p>I think that there is an argument to be made that cal's behaviour is wrong since it violates the principle of least surprise.</p>
<p>Cal without arguments produces the calendar for the current month, so it's, in my opinion, reasonable to assume that an unqualified argument (for $1 < 12) would do the same but for the supplied month.</p>
<p>Not that it matters now, 30 years later. The behaviour of cal is set in stone just by virtue of "it's always been like that" now.</p>
</div>2016-07-03T13:11:21Z