23rd September 2006

Posted in

Blog :: Ubuntu and pwsafe

I mentioned before that I'm trying to move to more keyboard/console based tools to improve my efficiency. Pwsafe is one of these tools. It's a command line username/password database that lets me tab to my console open in my second window, type `pwsafe -p foo`, type my master password, and have the password that corresponds to the account 'foo' in my clipboard for pasting into whatever other app I'm using (webbrowser, ftp client, ssh shell, etc) without breaking my flow or even looking at my second monitor.

This worked until I switched to Ubuntu, that is. Under Dapper Drake, the pwsafe binary is broken. Despite having references to it in the man page and --help, the X clipboard functionality is broken and the best you can do is print the requested password to the console.

Now this is just not as good; the whole point of using pwsafe was that I didn't have to look away or take my hands off the keyboard. Now I have to use the mouse to select the text printed out and right click and select "Copy" from a popup menu. By the time I've done all that I might as well go and read slashdot instead! I've lost the flow.

Apparently setting an option and recompiling fixes the bug, but my attempts at `apt-get source` have been segfaulting lately, so I just thought I had to live with it. Fortunately, unix's `small tools` philosophy comes to the rescue. Xclip is a program that accepts input and copies it to the clipboard. After mucking about unsucessfully with alias for a while I wrote the following 4 lines of python code (Granted that I didn't need python for this: bash would have been fine... But I'm on a python kick lately (more to come on this) so no task is too small..)

#!/usr/bin/python
import os,sys
c = """pwsafe -q -p %s | tr -d "\\n" | xclip -selection clipboard""" % sys.argv[1]
os.system(c)

I named the script pw and dropped it in in my ~/bin. Now the invocation of 'pw foo' has the desired effect: I get the password in my clipboard again. Ahh efficiency!

Posted on September 23rd 2006, 11:34 PM