passmenu2 - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       passmenu2 (1244B)
       ---
            1 #!/usr/bin/env bash
            2 
            3 shopt -s nullglob globstar
            4 
            5 typeit=0
            6 if [[ $1 == "--type" ]]; then
            7         typeit=1
            8         shift
            9 fi
           10 
           11 
           12 STARTDIR=${PASSWORD_STORE_DIR-~/.password-store}
           13 BASEDIR=$STARTDIR
           14 DONE=0
           15 LEVEL=0
           16 PREVSELECTION=""
           17 SELECTION=""
           18 
           19 while [ "$DONE" -eq 0 ] ; do 
           20   password_files=( "$STARTDIR"/* )
           21   password_files=( "${password_files[@]#"$STARTDIR"/}" )
           22   password_files=( "${password_files[@]%.gpg}" )
           23   
           24   if [ "$LEVEL" -ne 0 ] ; then
           25     password_files=(".." "${password_files[@]}") 
           26   fi
           27   entry=$(printf '%s\n' "${password_files[@]}" | dmenu "$@" -l 15)
           28   
           29   echo "entry: $entry"
           30   if [ -z "$entry" ] ; then
           31     DONE=1
           32     exit
           33   fi
           34   
           35   if [ "$entry" != ".." ] ; then
           36     PREVSELECTION=$SELECTION
           37     SELECTION="$SELECTION/$entry"
           38   
           39     # check if another dir
           40     if [ -d "$STARTDIR/$entry" ] ; then
           41       STARTDIR="$STARTDIR/$entry"
           42       LEVEL=$((LEVEL+1))
           43     else
           44       # not a directory so it must be a real password entry
           45   
           46       if [[ $typeit -eq 0 ]]; then
           47         pass show -c "$SELECTION" 2>/dev/null
           48       else
           49         xdotool - <<<"type --clearmodifiers -- $(pass show "$SELECTION" | head -n 1)"
           50       fi
           51       DONE=1
           52     fi
           53   
           54   else
           55     LEVEL=$((LEVEL-1))
           56     SELECTION=$PREVSELECTION
           57     STARTDIR="$BASEDIR/$SELECTION"
           58   fi
           59 done
           60