DEV Community


Posted on

Use pass and rofi to get a fancy password manager

I am using pass as my main password manager. It is completely cli based under version control and gpg2 encrypted. But use pass only in the cli makes no sense, when you have browsers or other applications which are asking for a password. To get a more handy usage of pass and autotype function, we have to be a little bit creative.

rofi is a windows switcher and application launcher which is high configurable. I combined both in one script. To get the auto type feature I am using xdotool which should be standard installed on every Linux machine.

Depend on the rofi.conf you will get a nice password manager, which is full integrated in your system.

pass and rofi in action


shopt -s nullglob globstar

# switch for autotyping
if [[ $1 == "--type" ]]; then

# get all the saved password files
password_files=( "$prefix"/**/*.gpg )
password_files=( "${password_files[@]#"$prefix"/}" )
password_files=( "${password_files[@]%.gpg}" )

# shows a list of all password files and saved the selected one in a variable
password=$(printf '%s\n' "${password_files[@]}" | rofi -dmenu "$@" -theme ~/dotfiles/i3/rofi.rasi)
[[ -n $password ]] || exit

# pass -c copied the password in clipboard. The additional output from pass is piped in to /dev/null 
if [[ $typeit -eq 0 ]]; then
    pass show -c "$password" | head -n1  2>/dev/null
    # If i want to use autotype i save the user name and the password in to a variable 
    # the actual password files are simple text file. 
    # The password has to be on the first line,
    # because if you using `pass -i` the first line will be replaced with a new password

    passw=$(pass show $password | head -n1 )
    uname=$(pass show $password | tail -n1 )
    # xdotool types the username on the active spot (cli or inputfield from a browser)
    xdotool type "$uname"
    # type a TAB (for moving forward in browser input fields)
    xdotool key Tab
    # type the password in the active input
    xdotool type "$passw"
    xdotool key Tab
Enter fullscreen mode Exit fullscreen mode

I'm using i3wm as window manager, so I can easily use short keys to activate my password manager.

bindsym $mod+p mode "password"
mode "password" {
    bindsym p exec "/home/maren/dotfiles/scripts/"
    bindsym t exec "/home/maren/dotfiles/scripts/ --type"

    bindsym Return mode "default"
    bindsym Escape mode "default"
    bindsym $mod+r mode "default"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)