Search code examples
shellscriptingpasswordsxdotooldmenu

Display passwords from pass (the standard unix password manager) in dmenu-mac, by executing a shell script


I'd like to have all the passwords, that are stored in gnu-pass (the standard unix password manager), to be displayed in dmenu-mac via a shell script.

The shell script is working, only for the Directory/file example.

Examples:

  1. Social/[email protected] (one directory) Works fine
  2. [email protected] (without directory) Does not work
  3. Social/Personal/[email protected] (more than one directory) Does not work

The following modified script that satisfies the first example, is taken from https://git.zx2c4.com/password-store/tree/contrib/dmenu/passmenu


#!/usr/bin/env bash

typeit=0
if [[ $1 == "--type" ]]; then
    typeit=1
    shift
fi

if [[ -n $DISPLAY ]]; then
    dmenu=/opt/homebrew/bin/dmenu-mac
    xdotool="xdotool type --clearmodifiers --file -"
else
    echo "Error: No Wayland or X11 display detected" >&2
    exit 1
fi

prefix=${PASSWORD_STORE_DIR-~/.password-store}
password_files=( "$prefix"/**/*.gpg )
password_files=( "${password_files[@]#"$prefix"/}" )
password_files=( "${password_files[@]%.gpg}" )

password=$(printf '%s\n' "${password_files[@]}" | "$dmenu" "$@")

[[ -n $password ]] || exit

if [[ $typeit -eq 0 ]]; then
    pass show -c "$password" 2>/dev/null
else
    pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } | $xdotool
fi

Do modify the above script to satisfy all three examples.

My system: Apple M1 Pro Ventura 13.0.1

Thank you in advance.


Solution

  • I used the rewrite gopass instead of pass.

    My problem with the script is that I only got 22 passwords displayed.

    I could solve it by replacing bash by zsh in the first line. Where exactly this bug is I have not traced.