Text expansion and password manager with Awesome
I have used password managers for a year or two. The main reason for using one is security. Almost every website now requires that we use a login and a password to be identified (and to get a personalized experience). Then, we have two options: use the same password everywhere (not very secure, if one account is compromised, all the others are also compromised), or use a different one for each site. A password manager is an application in which you can index all you websites and their associated credentials, all protected behind a master password (choose a long one!). After trying keepass (and keepassx), I have now settled on pass, which relies on Unix files and gpg to organize and secure passwords. Its major drawback is, like Awesome my window manager, that the name makes it hard to find documentation and info on Google…
What’s great with pass, beyond its functionalities, is that the ecosystem, built by the community: there is the command-line tool, but also a Qt-based software and an Android client. I can then create and save my passwords on one device and find them on another. I should mention that there are famous websites like 1password or dashlane which have similar functionality, but I am not keen on handing my secrets, even encrypted, to yet another entity.
The beauty is that, with Awesome, dmenu, I can fill passwords fields in any
browser or shell in a breeze! passmenu
is a tool shipped in Archlinux with
pass, with calls dmenu and provides a convenient interface to choose the desired
password:
If I have not yet recently typed a password (there’s a 5 minute timeout), I am
prompted to type my gpg passphrase, associated to secure my pass files. By the
way, I wrap passmenu
inside a function to get some consistent theming for
dmenu, like this:
1
2
3
function dmenuhelpers.pass()
awful.util.spawn("passmenu --type " .. dmenuopts)
end
Obviously, it’s good to avoid remembering and typing password, but it’s great when it’s possible to do the same thing with logins. I have then written the following code to get a general text expansion tool for Awesome:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function dmenuhelpers.expandtext()
-- a file with a key:value format
textexpfile = "/home/raph/.textexp"
-- dmenu asks to select one of the keys
service = awful.util.pread("cat "..textexpfile.." | grep -v ^# | cut -d: -f1 | dmenu -l 10 " .. dmenuopts)
linetextexp = awful.util.pread("cat "..textexpfile.." | grep -i -m1 "..service):gsub("\n", "")
textexp = awful.util.pread("echo " .. '"' .. linetextexp .. '"' .. " | cut -d: -f2-"):gsub("\n", "")
if textexp ~= "\n" and textexp ~= "" then
-- I need to have newline in some expansions, they are encoded as "bb"
textexp = string.gsub(textexp, " bb ", "\n")
-- a tooltip to show what was selected
naughty.notify({ text = "service : "..service, width = 400, screen = mouse.screen})
-- the value is typed with xdotool where your focus currently is
selectcommand = "xdotool type --clearmodifiers -- ".. '"' .. textexp .. '"'
awful.util.spawn_with_shell(selectcommand,false)
end
end