aboutsummaryrefslogtreecommitdiffhomepage
path: root/X11/rofi/pass.get
blob: b6560b036f883a7cf172a21d054b10937a59940f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /bin/sh

OPTIONS_NEW=( 'NO' 'YES' 'YES, and edit it' )

# Generate a new password
if [ -n "${ROFI_DATA}" ]; then
	[ "$1" == "${OPTIONS_NEW[1]}" ] && \
		coproc ( 
			export POST=false
			pass generate ${ROFI_DATA} --clip
			rofi -e "Generate and Copied: ${ROFI_DATA}" 
		)

	[ "$1" == "${OPTIONS_NEW[2]}" ]  && \
		coproc (
			export POST=false
			pass generate ${ROFI_DATA} --clip
			rofi-sensible-terminal -e pass edit ${ROFI_DATA}; \
		)

	exit 0
fi

# Give rofi available passwords and exit
if [ $# -eq 0 ]; then
	# Specify rofi prompt as 'Get'
	echo -e "\0prompt\x1fGet"

	find ~/.password-store -name '*gpg' -printf %P\\n | \
	sed 's/.gpg$//'

	exit 0
fi

# Test password exists or not
RESULT="$(pass $1)"
if [ -n "$RESULT" ]; then
	# Copy the given password into clipboard
	echo "$RESULT" | head -1 | tr -d '\n' | xsel -i -t 30000

	# And show extra message
	EXTRA="$(echo; echo; echo "$RESULT" | sed '1d' | sed '1{/^$/d}')"
    coproc ( rofi -e "Copied: $1$EXTRA" )
# Password doesn't exist yet
# Go to next rofi execution
else
	echo -e "\0prompt\x1f$1 doesn't exist, generate it?"
	echo -e "\0data\x1f$1"

	for i in "${OPTIONS_NEW[@]}"; do
	  echo $i
	done
fi