#!/bin/sh # Clear out any arguments sent. set -- # Make new shell keywords that loop over the built-in shell argument array as # if it were a dictionary, where $1 is the key and $2 is the value. This is # done in it's own shell, which does not modify the host's argument array. # # Example usage: # # set -- foo bar baz qux # dict # echo "dict[$1] = $2" # tcid # alias dict='until [ $# = 0 ]; do' alias tcid='shift 2; done' export arg gra # List the available password entries in newline format, # and select one using mew(1). pash list | mew | while read -r entry; do # After a password entry name was selected from mew(1), check if the # sent password entry is an entry and ends with '!' which is used as # a indicator to print specific properties from the entry rather than # just the password. # If no entry (empty string) was given, it will be discarded. case "$entry" in '') ;; *\!) # List out the properties of the entry # which is in the format password\nk:v... # Remove the trailing ! mark from the entry's name. pash show "${entry%!}" | { # Assign the password entries properties to # the shell argument array in dictionary form: # $1 -> password|key # $2 -> value # ... # The password property is not in k: v format # and is on it's own, in the first line, # as seen in the format. while IFS=': ' read -r k v; do case "$v" in '') set -- "$@" password "$k" ;; *) set -- "$@" "$k" "$v" ;; esac; done # Print out only the keys in the password entry # dictionary. dict echo "$1" tcid | mew | { # The sent entry name selected in mew # will then be used to search the # password entry dictionary for the # entrys associated key/value pair. # Once found, the keys corresponding # value will be printed. while read -r prop; do dict ! [ "$1" = "$prop" ] || echo "$2" tcid; done } } ;; # If Password entry given has no marker to do special behavior, # simply print the password value of the entry - the first line, # avoiding processing the routine of converting a password # entrys properties to a dictionary. *) pash show "$entry" | head -1 ;; esac # After the a password entrys property - whether it be the password or # a specific one - has been printed, copy it to the clipboard. # # wl-copy(1) has a special flag to only serve the paste # request and exit immediately, being -o. done | wl-copy -o