pmenu

· kitten's pastes · raw

expires: 09 Nov, 2024

 1#!/bin/sh
 2
 3# Clear out any arguments sent.
 4set --
 5
 6# Make new shell keywords that loop over the built-in shell argument array as
 7# if it were a dictionary, where $1 is the key and $2 is the value. This is
 8# done in it's own shell, which does not modify the  host's argument array.
 9#
10# Example usage:
11#
12#     set -- foo bar baz qux
13#     dict
14#        echo "dict[$1] = $2"
15#     tcid
16#
17alias dict='until [ $# = 0 ]; do'
18alias tcid='shift 2; done'
19export arg gra
20
21# List the available password entries in newline format,
22# and select one using mew(1).
23pash list | mew | while read -r entry; do
24	# After a password entry name was selected from mew(1), check if the
25	# sent password entry is an entry and ends with '!' which is used as
26	# a indicator to print specific properties from the entry rather than
27	# just the password.
28	# If no entry (empty string) was given, it will be discarded.
29	case "$entry" in
30		'') ;;
31		*\!)
32			# List out the properties of the entry
33			# which is in the format password\nk:v...
34			# Remove the trailing ! mark from the entry's name.
35			pash show "${entry%!}" | {
36				# Assign the password entries properties to 
37				# the shell argument array in dictionary form:
38				#   $1 -> password|key
39				#   $2 -> value
40				#   ...
41				# The password property is not in k: v format
42				# and is on it's own, in the first line,
43				# as seen in the format.
44				while IFS=': ' read -r k v; do case "$v" in
45					'') set -- "$@" password "$k" ;;
46					*) set -- "$@" "$k" "$v" ;;
47				esac; done
48
49				# Print out only the keys in the password entry
50				# dictionary.
51				dict
52					echo "$1"
53				tcid | mew | {
54					# The sent entry name selected in mew
55					# will then be used to search the
56					# password entry dictionary for the
57					# entrys associated key/value pair.
58					# Once found, the keys corresponding 
59					# value will be printed.
60					while read -r prop; do dict
61						! [ "$1" = "$prop" ] || echo "$2"
62					tcid; done
63				}
64			}
65		;;
66		# If Password entry given has no marker to do special behavior,
67		# simply print the password value of the entry - the first line,
68		# avoiding processing the routine of converting a password
69		# entrys properties to a dictionary.
70		*)
71			pash show "$entry" | head -1
72		;;
73	esac
74	# After the a password entrys property - whether it be the password or
75	# a specific one - has been printed, copy it to the clipboard.
76	#
77	# wl-copy(1) has a special flag to only serve the paste
78	# request and exit immediately, being -o.
79done | wl-copy -o