cal command alternatives

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
torm
Posts: 186
Joined: Sat 07 Mar 2015, 19:56

cal command alternatives

#1 Post by torm »

Edited topic.

Defaults.
____
Currently most Puppys are shipped with BusyBox version of "cal" command,
that unfortunately fails to detect the correct week-start-day for most european
users. There is also no commandline switch to fix that.
Note that BusyBox is a multi-call binary, and "cal" command is just a symlink
to it by default.


Alternatives.
____
Standard util-linux cal command is provided in util-linux package and
makes around 42k size binary ( stripped ) .
Note that cal as a stand-alone program is not listed in PPM, and util-linux package
may appear already installed.
util-linux has somewhat unusual compile method.
Official source for util-linux package: https://mirrors.edge.kernel.org/pub/lin ... nux/v2.33/
____
ccal_4.0 is stated as "any OS" alternative to cal ( MSDOS/FreeBSD/Unix/OS2/.. ).
It has some extras like colored terminal output and appointments.
On the other hand, it is no longer developed ( since 2002? ) and may have some
errors for european locales ( broken year view, etc. )
It may be listed in PPM ( Puppy Package Manager )
____
libcalendar-simple-perl_1.21-1
is configurable and small perl script, that unfortunately
depends on another perl module provided ( mostly ) inside devx.sfs
____
There are some bash scripts that try to mimic the cal command, for example:
http://unix.stackexchange.com/questions ... cal-or-cal
..while those may or not work as expected.



GUI alternatives.
____
gtk2 calendar-widget is a bit heavy, while limited in design
and has little use for external apps as input source.
For example see here: http://murga-linux.com/puppy/viewtopic.php?t=112293
____
gtk1.2 calendar-widget may have problems with locale support ( depending on system )
and needs extra dependencies ( like: gtk1.2 ? ) to compile.
For example of static precompiled bin see here: http://murga-linux.com/puppy/viewtopic. ... 9&start=60
____
xcalendar-4.0 is built on the old X Toolkit and the Athena or Motif
widgets. It may have problems with X11 fonts ( locale specific ) and poor visual
appearance. Also there is no automated locale support by default.


Other alternatives.
____
Programs with large size or multiple external dependencies are not listed here.


Practical use for cal command.
____
Output can be piped to different GUI apps like Conky, GKrellm2, and alike.
Or used in gtkdialog apps as direct or edited input for calendar.
Or just.. a fix for broken command?


Summary.
____
The "usual" util-linux cal command is the most correct and complete.
Then again, for some users tricky to install or compile.
It can be the best solution for those who expect full features of cal command
for personal use, while one may need all different variations of precompiled
executable file at hand ( 32/64 deb/slack/whatnot.. ) if it is shared as dependency or
direct input for some other program that is shared as pet package.
NB!
If You know how to compile util-linux cal as stand-alone program ( with: make, make install.. )
outside util-linux package, then please
share it here and include a stand-alone source.
Note..
One may download util-linux without installing it - from PPM, then extract cal from it.
-
ccal_4.0 is licensed as Public Domain package in readme.cal file, and there is MIT-style license in
cal.c file top, hmm... ?
Fuzzy license, help me if you can. For now I'll keep it as it is.
Not perfect, not lightweight, while it should compile on most puppy versions without problems.
I think I managed to trim it down to very basic one-month-view calendar with less than 10kb in size.
Fixed some issues, added automated locale support, etc.
It used to be posted here under name of "kale" before, as source code tar.gz.
That was a little bit funny name in some languages, so I think "pmonth" may fit better.
Last edited by torm on Sat 24 Nov 2018, 00:45, edited 1 time in total.

User avatar
torm
Posts: 186
Joined: Sat 07 Mar 2015, 19:56

#2 Post by torm »

pmonth, pmonth_clear.

pmonth is very simple terminal application that displays current month
calendar with current date marked.
Current date is marked with < >
Output can be piped to different GUI apps like Conky, GKrellm2, and alike.

pmonth_clear works the same, however without markings around the current date.
So it may be more suitable for scripts that use sed, etc.

pmonth and pmonth_clear are based on ccal_4.0 program, while take no commandline options
or settings or any other external data.
Week-start-day and locale detection are automated.

To compile, strip and install, open terminal in source directories, and type:

make
make install


Notes.
Default install path is /root/my-applications/bin, to change that - edit Makefile.

License.
pmonth and pmonth_clear are placed into the Public Domain.
pmonth.c and pmonth_clear.c files have the initial MIT-style disclaimers at the top,
from the original cal.c file.
Attachments
pmonth.tar.gz
pmonth c source
(3.41 KiB) Downloaded 167 times
pmonth_clear.tar.gz
pmonth_clear c source
(3.31 KiB) Downloaded 173 times
pmonth-and-pmonth_clear.jpg
screenshot from terminal window, note the difference in marks around the current date..
(75.61 KiB) Downloaded 577 times

User avatar
torm
Posts: 186
Joined: Sat 07 Mar 2015, 19:56

#3 Post by torm »

pmonth_gtk2

pmonth_gtk2 is a simple GTK-2 frontend for cal, BusyBox cal or pmonth_clear commands.
It can be updated, started and closed from run_pmonth_gtk2 script.
By default, the script will toggle pmonth_gtk2 on and off, depending on the current state.

Details.
To change the displayed text details or input commands - edit the run_pmonth_gtk2.sh script.

Look.
Transparent and semi-transparent backgrounds for calbg.png file are supported.
Font and color of month name and year number are set in run_pmonth_gtk2.sh script,
also the color of current date.
pmonth_gtk2.rc file in /root/my-applications/pmonth-gtk2/data folder is a
custom theme file for pmonth_gtk2 program only, and can set other look details.
The part in pmonth_gtk2.rc file beginning:
engine "murrine"
{
textstyle = 1
text_shade = 0.01
}
should apply a subtle shadow below dates,
while it can be commented out, if you don't have "Murrine" theme engine for GTK-2 installed.

Defaults.
pmonth_gtk2 is positioned at lower-right corner of display.
Size is 252x402 pixels.
Automatic timeout is 30 seconds, there is a "close" button at the top edge,
and the program will close if window has lost the focus.
Default install path is /root/my-applications/pmonth-gtk2 folder.

Font.
"Droid Sans Mono" TTF font used on screenshot is included in source package but
will not be installed by default, as it my be already installed in some puppy versions.
Default font folders are in /usr/share/fonts/.. - please drop it there, if it isn't already.
"Droid Sans Mono" font is licensed under Apache License v2.0

Notes.
Note the difference for executable file and the folder name: pmonth_gtk2 and pmonth-gtk2.
pmonth_gtk2 uses some code from "navig8or" menu program by Oliver Schweisfurth.


License.
GPLv2 or, at Your option, any later version of that license.

To compile, strip and install, open terminal in source directory, and type:
make
make install

You can run the program with:
run_pmonth_gtk2
Attachments
pmonth_gtk2.tar.gz
pmonth_gtk2 c source and data
(83.24 KiB) Downloaded 188 times
pmonth_gtk2-screenshot.jpg
screenshot
(55.55 KiB) Downloaded 582 times

User avatar
torm
Posts: 186
Joined: Sat 07 Mar 2015, 19:56

#4 Post by torm »

Side-notes about pmonth_gtk2.

As far as the input for pmonth_gtk2 is prior edited with run_pmonth_gtk2 script,
You could - for example, make the this input more interesting.

In no particular order:
- make header ( month name and year number ) use some other font, size, angle and/or color
- add more space between header and calendar grid
- use different calbg.png backgrounds, depending on month number,
by replacing initial file with link to one of 12 different files - then replace the link as/if needed
- use more interesting design for calbg.png file ( no compositing manager is used )
- insert more/other information from external files/commands
- ...

At the end of the day, use whatever You can pull out of a bash script. :)
If it does not drag in heavy external dependencies and works as good for other locales
-then please share it here.

It needs some testing first, while I hope that
in the long run, pmonth/pmonth_clear/pmonth_gtk2 could be
shared as 32/64 bit pet files for wider public in correct forum sections.
As stand-alone, or as part of another program.

There is pmonth_plus somewhere on todo list, with some extra/optional features,
once some theoretical uses are figured out to start with.
Don't get me wrong here, I'm not a developer - just a regular but offline user,
so it is sometimes faster to edit some script or source than to
go ( well, walk.. ) online and start searching for something
__

To tell the truth, these days I tend to forget what and where I have uploaded
and that is - even if I have the time to get there. So if anyone would volunteer
to maintain, update, etc the packages - I'd be glad to hand it over.
No rush, whenever it makes to somewhat stable and more tested state, then just
start new topic in desktop/utilities/.. section, simple as that.
Just be prepared to answer any user-side questions and comments in
reasonable time .

For now, have a nice day :wink:

User avatar
torm
Posts: 186
Joined: Sat 07 Mar 2015, 19:56

#5 Post by torm »

Edit: configurable version posted later..
Last edited by torm on Thu 02 Jul 2020, 15:38, edited 1 time in total.

User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

#6 Post by rufwoof »

A bash script to take the busybox cal and print that out with the first column shifted to the end (with the dates shifted up one line, except if Sunday was the 1st) would suffice.
[size=75]( ͡° ͜ʖ ͡°) :wq[/size]
[url=http://murga-linux.com/puppy/viewtopic.php?p=1028256#1028256][size=75]Fatdog multi-session usb[/url][/size]
[size=75][url=https://hashbang.sh]echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh[/url][/size]

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#7 Post by MochiMoppel »

@rufwoof: Sunday 1st makes no difference. All last values have to be shifted up. Please post sample code if you know how to do it.

Code: Select all

# cal 7 2018 | sed -r 's/(...)(.*)/\2 \1/'
  July 2018    
Mo Tu We Th Fr Sa Su 
 2  3  4  5  6  7  1 
 9 10 11 12 13 14  8 
16 17 18 19 20 21 15 
23 24 25 26 27 28 22 
30 31 29 

User avatar
torm
Posts: 186
Joined: Sat 07 Mar 2015, 19:56

#8 Post by torm »

Oh..
There used to be a script for that use in pWidgets package, that worked - sometimes
.. and failed, every now and then..

Below is a screenshot from both BusyBox and util-linux cal command output,
where util-linux bin is renamed to "util-linux_cal".
The actual output will be different on systems with different locale
than mine, including week-start-day and abbr. weekday names.
util-linux cal command output on the screenshot is correct for my locale, while
the BusyBox output is "somewhat strange", if you look at the details..

So .. :?
Attachments
busybox_vs_util-linux.jpg
output from BusyBox cal and util-linux cal commands
(70.18 KiB) Downloaded 451 times

User avatar
puppy_apprentice
Posts: 299
Joined: Tue 07 Feb 2012, 20:32

#9 Post by puppy_apprentice »

MochiMoppel wrote:Please post sample code if you know how to do it.
Ugly code. But you find an idea and could try to make better one:

Code: Select all

n=($(cal | head -2 | tail -1 | tr ' ' '\n'));
echo " "${n[1]}" "${n[2]}" "${n[3]}" "${n[4]}" "${n[5]}" "${n[6]}" "${n[0]}
c=$(cal | tail -n +3)
a=$(echo ${c//   / . })
i=0
j=0
for l in $a
do
  if [ "$l" == "." ]
  then
    j=$((j+1))
  fi
  if [ "$l" == "1" ]
  then
    week="                  $week"
  fi
  if [ $((i-j)) -lt 9 ]
  then
    week="$week  $l"
  else
    week="$week $l"
  fi
  if [ $((i%7)) -eq 0 ]
  then
    week=$week"\n"
  fi
  i=$((i+1))
done
echo -e "$week" | tr '.' ' ' | grep -w -B7 -A7 --color=always "$(date +%e)"
Attachments
suncal.jpg
(30.9 KiB) Downloaded 426 times

User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

#10 Post by rufwoof »

MochiMoppel wrote:All last values have to be shifted up. Please post sample code if you know how to do it.
Laborious example of how to open/use two file descriptors

Code: Select all

#!/bin/bash

# pass me a month and year i.e. 7 2018

IFS=

# create the two temp files
t1=`mktemp`
t2=`mktemp`

# Load the files
cal $1 $2 | sed -r 's/(...)(.*)/\1/' >$t1  # Sunday list
cal $1 $2 | sed -r 's/(...)(.*)/\2/' >$t2  # Rest

# open the two files
exec 7<$t1
exec 8<$t2

read month <&8
read empty <&7
echo "    $month"

read weekdays1 <&8
read weekdays2 <&7
echo "$weekdays1" "$weekdays2"

read dates2 <&7
tst=`echo ${dates2} | sed 's/ //g'`
if [ ! -z $tst ]; then
	echo "                 " "$dates2"
fi

for i in 1 2 3 4 5 6
do
   read dates1 <&8
   read dates2 <&7
   tst="$dates1 $dates2"
   tst=`echo ${tst} | sed 's/ //g'`
   if [ ! -z $tst ]; then
	      echo "$dates1" "$dates2"
   fi
done

# close the files
exec 7</dev/null
exec 8</dev/null

# clean up
rm $t1
rm $t2
Last edited by rufwoof on Sat 01 Dec 2018, 13:10, edited 6 times in total.

Burunduk
Posts: 80
Joined: Sun 21 Aug 2011, 21:44

#11 Post by Burunduk »

The actual output will be different on systems with different locale
My busybox cal always outputs English names no matter what.

---

As the busybox utilities are all I have on my phone, I wrote a script that adds support for -s and -m options to busybox cal. It only shifts the names of days though, numbers are taken from a different year where all the Mondays are Sundays. It works with the years of the current and previous century for simplicity.

Code: Select all

#!/bin/busybox sh
# Wrapper for busybox cal command. Adds support for -s and -m options.

# This is intended to be a function
#local sunday opt o m y

# The default is Monday if $sunday is empty
sunday=default

opt=

while getopts :SMsmyj o; do

        case $o in
            S|s)  sunday=set
                  continue
                  ;;
            M|m)  sunday=${sunday#default}    # only change the default setting
                  continue
                  ;;
            j)    sunday=set
                  ;;
            \?)   cal --help
                  exit 1
                  ;;
        esac

        opt=${opt:--}$o  # save options from shifting
done

shift $(( $OPTIND - 1 ))

case $# in
    0)  y=`date +%Y`
        m=`date +%m`
        ;;
    1)  y="$1"
        m=
        ;;
    2)  y="$2"
        m="$1"
        ;;
    *)  cal --help
        exit 1
        ;;
esac

y="${y%%[^0-9]*}"    # not necessary but this will become a part of a sed script

[[ "$y" -le 1912 || "$y" -gt 2099 ]] && sunday=set


if [[ ! $sunday ]]; then

    cal $opt $m $((y - 12)) | sed -r '
        1 s/[0-9]{4}/'$y'/
        /^[[:alpha:]]./ s/([[:alpha:]].) (.{17})/\2 \1/g 
    '
else
    cal $opt "$@"
fi

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#12 Post by MochiMoppel »

torm wrote:util-linux cal command output on the screenshot is correct for my locale, while
the BusyBox output is "somewhat strange", if you look at the details..
And what is your locale?
If busybox cal fails to display weekday abbreviations then I would consider this to be a serious bug. Would make no sense to start any reformatting acrobatic before this issue is solved.

On the other hand I have found no other reports regarding this issue. Strange indeed.

User avatar
tallboy
Posts: 1760
Joined: Tue 21 Sep 2010, 21:56
Location: Drøbak, Norway

#13 Post by tallboy »

Ancient Puppy:
/root/.packages/builtin_files/minixcal
In /root/.jwm-tray:

Code: Select all

<Clock format="%H:%M:%S">minixcal</Clock>
Activate by click on clock.
True freedom is a live Puppy on a multisession CD/DVD.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#14 Post by musher0 »

torm wrote:(...)
Summary.
____
The "usual" util-linux cal command is the most correct and complete.
Then again, for some users tricky to install or compile.
It can be the best solution for those who expect full features of cal command
for personal use, while one may need all different variations of precompiled
executable file at hand ( 32/64 deb/slack/whatnot.. ) if it is shared as dependency or
direct input for some other program that is shared as pet package.
NB!
If You know how to compile util-linux cal as stand-alone program ( with: make, make install.. )
outside util-linux package, then please
share it here and include a stand-alone source.
Note..
One may download util-linux without installing it - from PPM, then extract cal from it.(...)
Hello torm and all.

Concerning the full cal, please see here. I've attached my
compilation of it for xenialPup-706 (32-bit).

Concerning locales, it probably has no bearing on this discussion, but I
thought I would mention it. There is a new kid in town, called dateutils,
to ease doing date sorts, backward and forward projections, and a
couple of other things. It has an independent locale file located at
/usr/share/dateutils/locale to which one can add his/her own locale if
need be.

Both work fine on my Pup. YMVV.

Finally, perhaps I'm way off, but shouldn't there be a mention of calcurse
on this thread?
Image

BFN.
Attachments
full-cal.zip
Unzip in /usr/bin and make file cal-2.33 executable. Contains a &quot;cal&quot;
symlink for convenience. (Please note this executable is 32-bit only.)
(56.49 KiB) Downloaded 131 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#15 Post by MochiMoppel »

@ puppy_apprentice: Simply works :lol:
@ rufwoof: cal chokes on $1 $2. Works when I place IFS='|' after the cal commands
@ Burunduk: Looks like a winner. "Stealing" and relabelling a suitable calendar is a clever idea. The only one in the pack that supports yearly display
Many thanks to all for the interesting suggestions.

Code: Select all

# burunduk_test -m 7 2018
     July 2018
Mo Tu We Th Fr Sa Su
                   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

# burunduk_test -m 2018
                              2018                              

      January               February               March        
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  6  7            1  2  3  4            1  2  3  4
 8  9 10 11 12 13 14   5  6  7  8  9 10 11   5  6  7  8  9 10 11
15 16 17 18 19 20 21  12 13 14 15 16 17 18  12 13 14 15 16 17 18
22 23 24 25 26 27 28  19 20 21 22 23 24 25  19 20 21 22 23 24 25
29 30 31              26 27 28              26 27 28 29 30 31
                                                                               
       April                  May                   June        
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
                   1      1  2  3  4  5  6               1  2  3
 2  3  4  5  6  7  8   7  8  9 10 11 12 13   4  5  6  7  8  9 10
 9 10 11 12 13 14 15  14 15 16 17 18 19 20  11 12 13 14 15 16 17
16 17 18 19 20 21 22  21 22 23 24 25 26 27  18 19 20 21 22 23 24
23 24 25 26 27 28 29  28 29 30 31           25 26 27 28 29 30
30
        July                 August              September      
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
                   1         1  2  3  4  5                  1  2
 2  3  4  5  6  7  8   6  7  8  9 10 11 12   3  4  5  6  7  8  9
 9 10 11 12 13 14 15  13 14 15 16 17 18 19  10 11 12 13 14 15 16
16 17 18 19 20 21 22  20 21 22 23 24 25 26  17 18 19 20 21 22 23
23 24 25 26 27 28 29  27 28 29 30 31        24 25 26 27 28 29 30
30 31
      October               November              December      
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  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

User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

#16 Post by rufwoof »

MochiMoppel wrote:@ rufwoof: cal chokes on $1 $2. Works when I place IFS='|' after the cal commands
Thanks. That IFS setting is unneccessary so I've edit that post to just IFS=
[size=75]( ͡° ͜ʖ ͡°) :wq[/size]
[url=http://murga-linux.com/puppy/viewtopic.php?p=1028256#1028256][size=75]Fatdog multi-session usb[/url][/size]
[size=75][url=https://hashbang.sh]echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh[/url][/size]

User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

#17 Post by rufwoof »

musher0 wrote:Finally, perhaps I'm way off, but shouldn't there be a mention of calcurse
on this thread?
I do mostly use calcurse myself, but also don't forget osmo
[size=75]( ͡° ͜ʖ ͡°) :wq[/size]
[url=http://murga-linux.com/puppy/viewtopic.php?p=1028256#1028256][size=75]Fatdog multi-session usb[/url][/size]
[size=75][url=https://hashbang.sh]echo url|sed -e 's/^/(c/' -e 's/$/ hashbang.sh)/'|sh[/url][/size]

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#18 Post by musher0 »

Osmo? Yerk! :twisted:
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#19 Post by MochiMoppel »

Here is my attempt. Not better than anything presented so far, hopefully not much worse. I tried to implement the idea to cut the first column, add it to the right and then shift it one notch up.
It can easily be made portable (executable with busybox ash) by redirecting SUND and REST to temp files and then reading these files with paste. I just don't like tmp files :cry:

Code: Select all

 #!/bin/bash
## Usage: scriptname [month [year]]
## Defaults to current month year if no parameters passed
MNTH=${1:-$(date +%m)}
YEAR=${2:-$(date +%Y)}
CLDR=$(cal $MNTH $YEAR)
BODY=$(echo "$CLDR" | tail +3)
HEAD=$(echo "$CLDR" | head -2 | sed -r '2s/(...)(.*)/\2 \1/')
EMTY='                     '
BODY=$EMTY$'\n'$BODY
BODY=$(echo "$BODY" | sed  -r "s/.*/&$EMTY/ ; s/(.{21}).*/\1/")
SUND=$(echo "$BODY" | grep -o ^... | tail +2)
REST=$(echo "$BODY" | grep -o ..................$)
BODY=$(paste -d '' <(echo -n "$REST" ) <(echo -n "$SUND" )  )
BODY=$(echo "$BODY" | sed -r "s/ *$//; /^ *$/d")
echo "$HEAD"$'\n'"$BODY"

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#20 Post by musher0 »

Hi MM.

Thanks.

The script name is... ?

Right up my alley, too. I love gory variable names, such as Body, Head.
Plus you're inflicting all sorts of operations on them. Miam.
(Blame that dark humor on the Kashoggi affair...)

Never mind the script name. I decided to call it "gory-cal.sh" :twisted:

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

Post Reply