aboutsummaryrefslogtreecommitdiffhomepage
path: root/X11/rofi/pass.get
blob: 80dc0ccf4af6ce0d9f0b74092c4e3c088153178b (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
54
55
56
57
58
59
#! /bin/bash

GENERATION_HINT="Generate with default config"

# Generate a new password if ROFI_DATA is given by last execution
if [ -n "${ROFI_DATA}" ]; then
  PASSWORD="${ROFI_DATA}"
  export ROFI_DATA=

  # If custom arguments for password generation is given
  # Set environment variable
  if [ ${ROFI_RETV} -eq 2 ]; then
    extra_arguments="${1}"
  fi

  # Generate password in a new process
  # And Use current script to copy the values info X11 selections
  coproc ( 
    pass generate ${PASSWORD} ${extra_arguments}
    $0 ${PASSWORD}
  )

  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 PRIMARY selection and kill it in 30s
  echo "$RESULT" | sed -n 1p | tr -d '\n' | xsel -i -t 30000
  # Copy the second line (most of the time, account name) into CLIPBOARD selection
  echo "$RESULT" | sed -n 2p | tr -d '\n' | xsel -ib

  # 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
elif pass find $1 &>/dev/null; then
  echo -e "\0prompt\x1fGPG Issue"
  echo Passphase is not chached
else 
  echo -e "\0prompt\x1f$1"
  echo -e "\0message\x1fThis password doesn't exist, generate with custom arguments?"
  echo -e "\0data\x1f$1"
  echo ${GENERATION_HINT}
fi