Trivial tools

There are various trivial command-line tools which I (have had to) create because of various reasons. Below are some of them:

norepeat

I didn't want to write this, but couldn't find any existing cli tool on CPAN or Debian. Since I put reminders on my ~/.bash_profile and I open many many terminals in a day, I needed a way to run some scripts just once a day. It's surprising that I couldn't find a tool to let me do it easily, and I hope someone can correct me on this.

exec-if-env

This began when I wanted to do something like:

if [[ "$OFFLINE" =="" ]]; then do-some-thing-that-needs-internet ...; done

in dist.ini to be run by Dist::Zilla::Plugin::Run. But of course you'll have to write something like this instead for it to work:

bash -c 'if [[ "$OFFLINE" =="" ]]; then do-some-thing-that-needs-internet ...; done'

which will get even more unreadable when you nest it or combine it with another command (like norepeat). And it does not work on Windows without bash. So exec-if-env (and exec-if-not-env) was born. This allows you to simplify your command line, e.g.:

norepeat --period daily -- exec-if-not-env OFFLINE do-some-thing-that-needs-internet 

check-yaml and check-json

Some of my applications use YAML config file, some use JSON. And of course, users invariably write/edit YAML and JSON with syntax errors in them. Especially YAML. I prefer to tell my users about check-yaml and check-json rather than instructing them to type something like:

% perl -MYAML -E'Load(~~<>)' /path/to/some/file.yaml

What are some of the trivial tools you have created?

4 Comments

Test::CPAN::Meta::YAML, Test::CPAN::Meta::JSON??

I copied and pasted some code from Pod::HtmlEasy's man page to create a simple p2h program to test how my pod would look on CPAN. There are other ways, but this one works ok. Manually opening the resulting page is a bummer, but not much of a time waster.

#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;

use Pod::HtmlEasy;

my $filename = shift @ARGV;

my $podhtml = Pod::HtmlEasy->new();
$podhtml->pod2html($filename, output => "$filename.html", parserwarn => 1);

I also used to use a version of regex-test.pl from Learning Perl to test regex's that could take a command line argument of the regex to test against, but that was barely helpful. And mostly resulted in me just guessing over and over until I beat the regex into submission, and it worked the way I wanted it to. But then I found Regexp::Debugger, which is completely amazing. It's rxrx command line program rocks, and provides a step by step debugger for regexes. All of the back tracking is really eye opening and surprising.

After editing various files within a module (all under 'lib'), I check whether or not I should do a full build of a distro with compile.sh:

#!/bin/bash

find lib -name \*.pm -exec perl -Ilib -c {} \;

tt -- talking timer. Takes a /bin/sleep timespec, or a /usr/bin/at timespec, and then a phrase to say via /usr/bin/espeak text-to-speech.

tt '3m 30s' tea is ready
tt -a 18:00 call mom

wup -- wait for a host to go down and come back up, then send a desktop notification. So when I do a shutdown -r now on a remote machine, I can exit the SSH session and wup remotehost and go do something else while the server reboots.

rfc1345 -- search the RFC1345 spec for the digraph needed to type all those funny characters.

rfc1345 pound omega
£  Pd     00a3    POUND SIGN
Ώ  W%     038f    GREEK CAPITAL LETTER OMEGA WITH ACUTE
Ω  W*     03a9    GREEK CAPITAL LETTER OMEGA
ω  w*     03c9    GREEK SMALL LETTER OMEGA
ώ  w%     03ce    GREEK SMALL LETTER OMEGA WITH ACUTE
pageme -- sends an SMS to my phone.

at 14:55 monday 

Leave a comment

About Steven Haryanto

user-pic A programmer (mostly Perl 5 nowadays). My CPAN ID: SHARYANTO. I'm sedusedan on perlmonks. My twitter is stevenharyanto (but I don't tweet much). Follow me on github: sharyanto.