Three Command-Line Utilities
So, November is NaNoWriMo ("National Novel Writing Month"), and I was hoping to get some serious writing done (instead of coding), but I kept being distracted with coding and random writing in various Internet forums. Well, hopefully this blog post will compensate a little for that.
In this post, I'd like to cover three command-line utilities - two of them new and were written by me, and one of them somewhat older, but also written in Perl.
The first utility is GNU Parallel, which allows one to run several command-line jobs in parallel, using forking and/or ssh remote logins. I used it to speed up some processing I've been doing on my computer. For more information and some examples of usage, see my post about it to the linux-elitists mailing list, and also read Thomas Sattler's response which provides some further insights.
The second utility is countdown, which is similar to the UNIX command-line sleep command, but displays the remaining time on the console. I wrote a prototype for it in Perl 6, only to discover it consumed far too many resources. The second prototype, as a Perl 5 program consumed close to zero resources of my computer. Yesterday, I converted it to a modulino (a Perl application implemented as a module) and uploaded several versions to the CPAN.
The third utility is something I have placed in my ~/.bashrc file in order to implement reminders when the shell starts. The code for it is:
reminder_file="$HOME/.local/share/shlomif/reminder/reminder.txt" if [ -s "$reminder_file" ] ; then perl -Mstrict -Mwarnings -MTerm::ANSIColor -E 'my $x = colored("===", "bold red"); say "$x Reminders $x"' cat "$reminder_file" fi Cancel_reminder() { rm "$reminder_file" }
I wrote it because I wasn't prompted in time by Thunderbird+Lightning due to a strange bug, and because I had to ditch KOrganizer because it consumed too many resources here. This displays the Reminders whenever you start a new shell, which happens quite often with me, so it's OK. I use cron jobs to append stuff into "$reminder_file", and the Perl code displays a header in colour.
That's it for today. App-Countdown is one step closer for the count-up (pun intended) towards the coveted 100 distributions under "SHLOMIF" on CPAN, so that's another plus.
I also run todo reminder script during shell startup :) Except that I limit it to run once a day to prevent me from ignoring it due to seeing it too much (I start many many shell sessions a day). The once-daily wrapper, or its more generic form, could perhaps be an idea for the next command-line utility.
Tried App::Countdown just now. Is there a reason it needs to be OO, BTW, because I can imagine the script being simpler without any OO. Also, to be a more proper Unix command-line utility, it perhaps needs a --help/-h and --version/-v. A shorter error message (instead of a stack trace) would be nice. As also accepting (and displaying) duration in the form of 5m, 1.5h, 0.5d (like sleep does).
You can use remind utility http://www.linuxjournal.com/article/3529
Hi Steven, thanks for your comment.
I made App::Countdown object oriented, because I'm making almost all of my code object oriented, because I don't know when it will outgrow its original design, and then I may have to break interfaces. Anyway, this should not affect the command line interface in any way.
You are right that it needs --help and --version flags - I'll add them in a future version. I was also aware of implementing a "2m" or "2.3h" notation similar to sleep, but was anxious to get something released, and so decided to postpone implementing it for later on, because they were of little immediate use for me.
So expect some future releases of it.
Hi Alexey,
reminder looks interesting. I have packaged it for Mageia (= Linux distribution) already and will take a further look. Its tk interface - "tkreminder" appears to be confusing, but maybe I can figure out the command line stuff.
My shell reminders thingy was easy to write, and scratched an itch, but reminder may prove as a more flexible solution.
Hi Steven,
OK, the new release of App-Countdown, supports timeouts such as 2m or 1.5h or whatever (in input - not in output yet - I have yet to determine if and when I should display the minutes and hours etc. - maybe a command line option and/or environment variable and/or configuration file). I also added a --help and --version flags.
Thanks for your input again.