Monitor tasks with AnyBar

I got wind of AnyBar via Miachael Tsai.1 It took me all of five seconds to think of an ideal use case. Long running shell scripts are a common facet of my daily life. Whether it’s a SQL import, an rsync to a remote server, or processing server logs, running something that takes more than my attention span to complete is a pain point. Cycling through terminal windows to see what’s completed isn’t fun and a waste of time.

That’s where anyguard with AnyBar comes in. It’s a two part system, first is a shell function to send commands to the AnyBar process (which ingeniously uses UDP ports for commands), second is a wrapper function which prefixes a script and monitors it’s output. It ends up looking something like this.

AnyBar Menu

The anybar function is taken directly from the AnyBar README.

function anybar () {
    echo -n $1 | nc -4u -w0 localhost ${2:-1738};

The wrapping function is a little longer. First it picks a random port and then opens the AnyBar menu application with that assigned port. A quick ½ second sleep is important because the application takes a little bit of time to boot and start listening for commands. After that it sets the status to orange (waiting for completion) and green or red depending on the exit code.

function anyguard () {
    ANYBAR_PORT=`jot -r 1 1700 1900`;
    ANYBAR_PORT=$ANYBAR_PORT open -n ~/Applications/;
    sleep 0.5;
    anybar orange $ANYBAR_PORT;

    if [[ ret -eq 0 ]]; then
        anybar green $ANYBAR_PORT;
        anybar red $ANYBAR_PORT;
    echo "Finished. Press [ENTER] to exit.";
    read ENTER
    anybar quit $ANYBAR_PORT;
    return $ret;

In practice this works very simply. Place these two functions in your .bashrc or .zshrc file then prefix any command with anyguard. The menubar provides scannable status indicators without having to jump around.

  1. Who picked it up from Dr. Drang↩︎

written April 16th, 2015

April 2015

Can’t find what you’re looking for? Try hitting the home page or viewing all archives.