q, textual queue manager

I wanted a quick, command-line way to handle a list of to-do items and to show me the next item that I want to work on, so I hacked together a quick little program that manages queues for you.

It’s handy for those times where I think of something to do while working on a project, but I am already working on something. With this I can just append it to the end of my queue for that project and forget about it until later.

The code can be gotten from bitbucket, if you are interested.

You can use it like so:

Push items to the top of a queue:

$ q todo push 'do that one thing'
do that one thing
$ q todo push 'do that other thing'
do that other thing

See what’s at the top of a queue:

$ q todo
do that other thing

Pop items from the top of a queue

$ q todo pop
do that one thing

Append items to the end of a queue:

$ q todo append 'do some more things'
do that one thing

The help q prints out if you call it with no parameters:

$ ./q.py 
usage: ./q.py queuename [command [params]]
  commands:
    push       Add one or more lines to the queue
    all        Show all the items in the queue
    append     Add one or more lines to the end of the queue
    pop        Remove the top item from the specified queue and push it onto the .done queue for that file
    next       (default) Return the top item in the queue

Other commands I plan on adding include “rot” to swap the current top item with the next item (or with a numerical parameter to move it even further down).

I’ve been experimenting around with Mercurial, and since that was also written in Python, I was wondering what it would take to rewrite this as a hg plugin. It could be handy to use something like this to manage a todo file. It could add some output to show what todo items were marked as done for each commit and perhaps also do a pre-commit hook where it pulls any new lines starting with “TODO:” and adds them to the todo file.

Tags: , ,

2 Responses to “q, textual queue manager”

  1. Silly Jawa Says:

    Hi Paul,

    From what I can gather in your examples and your supported command names, it seems that you’ve implemented a “stack” [which follows a last in, first out (LIFO) policy] rather than a traditional “queue” [which follows first in, first out (FIFO) rules].

    I made an assumption about q.py (please correct me if I’m wrong) to come to this conclusion: it looks like the output of “./q.py queuename [command [params]]” is the “next” of that structure after the command has been carried out. (The best evidence of this is in the output of the ‘append’ command.)

    Overall, quite a nifty idea. I trust that people will find good use for it.

  2. pib Says:

    Jawa: It’s kind of a hybrid of the two, since with the append command makes it act as a queue. If I added a way to pop off the end of it, it would be a deque, which is like a stack which you can push and pop from either end (double-ended queue).

    Really, I was just going for the more general meaning of the word queue, some sort of in-order list of things. Also, there’s not a single-letter that sounds like “stack” :)

    And yes, after each command it shows you the item at the top of the queue.

Leave a Reply