twittergithub
rss

Openbox Window Manager
http://openbox.org

Since the beginning of the month, I've been using Openbox as my window manager. Going from a full-featured DE (KDE) to a minimalistic WM was a leap, but I like that the OpenBox WM falls in line with the Arch Way and the Unix Philosophy. It's a clean, elegant, simple, easy to understand window manager for X. And it's fast.

Openbox does not come with a panel, a launcher, or much of anything. It doesn't even come with a dialog system for changing the configuration, although there are some GTK GUI tools available if you don't want to play with the ~/.config/openbox/rc.xml (namely obconf and lxappearance).

Openbox does come with a right-click desktop menu system with a wonderful dynamic scriptable menu feature known as "pipe menus" (See the openbox wiki at http://openbox.org/wiki/Help:Menus#Pipe_menus for more information).

The Todo.txt Command Line Interface (CLI)
http://todotxt.com

For the last two months, I've been using todo.txt-cli to track my TODO lists. This is a great command-line tool that's been quick to learn, is easy to understand, and is as functional and feature-rich as I'd expect any linux bash command-line TODO manager to be.

Todo.txt CLI as an Openbox Pipe Menu

Using the recursive bash script below as a pipe menu, todo.txt-cli todo listings, filtering, and completion by click can be integrated right into the desktop.

To use the script as a pipe menu, you'll need to reference it in your menu.xml as a menu item. My entry looks similar to:

<menu id="agenda-todo-menu" label="TODO" execute="PATH_TO_PIPE_MENU_SCRIPT" />

My bash skills and POSIX knowledge are limited, so if there's a better way to accomplish something below, please leave a comment.

This script is also on github at: github.com/davisd/todo.txt-cli-openbox-pipe-menu

#!/bin/bash

#: Title       : todo.txt-cli-openbox-pipe-menu
#: Date Created: Thu Nov 25 12:00:00 CDT 2010
#: Last Edit   : Sun Nov 28 22:00:00 CDT 2010
#: Author      : "David Davis" http://www.davisd.com
#: Version     : 1.00
#: Description : Openbox todo.txt-cli pipe menu
#: Options     : Name of new script file [ filter terms ]


# Set the location to your todo.sh todo-cli.txt script
TODOCLI=~/bin/td

# very simple xml encoder to get rid of special characters
function xml_encode {
    local result=$(echo "$1" | sed 's/"/\&quot;/g')
    echo $result
}

# track whether or not we have incoming args for later
HAS_ARGS=0
if [ $# -ne 0 ]; then
    HAS_ARGS=1
fi

# get any args
ARGS=$*

# get the output of todo-txt.cli
TD_OUTPUT=''
if [ $HAS_ARGS -eq 1 ]; then
    TD_OUTPUT=$($TODOCLI -p ls $*)
else
    TD_OUTPUT=$($TODOCLI -p ls)
fi

echo "<openbox_pipe_menu>"

if [ $HAS_ARGS -eq 1 ]; then
    echo "<separator label=\"$*\" />"
else
    echo "<separator label=\"Tasks\" />"
fi

# create a glob of all task text to search for special words (beginning with @ and +)
ALLTASKTEXT=""
IFS=$'\n'
for TODO in $(echo -e "$TD_OUTPUT");
    do
    TODO=$(xml_encode $TODO)
    TASKID=$(echo "$TODO" | grep -o '^[0-9]*')
    if [ $TASKID ]; then
    echo "<item label=\""$TODO"\">"
        echo "<action name=\"Execute\"><prompt>DO $TODO</prompt><execute>$TODOCLI do $TASKID</execute></action>"
        ALLTASKTEXT="$ALLTASKTEXT $TODO"
    echo "</item>"
    fi
done
unset IFS

words=""
for word in $ALLTASKTEXT; do
    words="$words\n$word"
done

FIRSTFILTERPASS=1
if [ -n "${ARGS:+x}" ]; then
    NONGREP=$ARGS
else
    # TODO: If NONGREP is empty, it causes problems below
    NONGREP='NOM8TCH321'
fi

# sed might be more fitting to use here
for word in $(echo -e "$words" | tr '[A-Z]' '[a-z]' | sort | uniq | grep "@\|\+" | grep -v -F "$(echo -e "$NONGREP" | tr " " "\n")"); do
    if [ $HAS_ARGS -eq 1 ]; then
        word=$(echo "$word" | grep -v -F "$(echo $* | tr " " "\n")")
    fi

    if  [ $word ]; then
        if [ $FIRSTFILTERPASS -eq 1 ]; then
            echo "<separator label=\"Filter\" />"
            FIRSTFILTERPASS=0
        fi
        if [ $HAS_ARGS -eq 1 ]; then
            echo "<menu id=\"td_ls_$*_$word\" label=\"$* $word\" execute=\"$0 $* $word\">"
        else
            echo "<menu id=\"td_ls_$word\" label=\"$word\" execute=\"$0 $word\">"
        fi
        echo "</menu>"
    fi
done

echo "</openbox_pipe_menu>"

Leave a comment!

Comments are moderated. If your comment does not appear immediately, give it a few, it may require authorization. If you're a spam-bot, you may not leave a comment, it is strictly forbidden in the Terms of Service.

You may comment using markdown syntax (link opens in new window).

David Davis