summaryrefslogtreecommitdiff
path: root/dmenu_keepass
blob: d87a4c893e8fd43de1d839c153a4bef99e3407a1 (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
#!/sbin/sh

HAS_KEYFILE="y"

PASS_DIR="$HOME/Pass"
[ -n "$HAS_KEYFILE" ] && \
  KEYFILE=`ls $PASS_DIR | barmenu $@ -p 'keyfile:'` && \
  [ -n "$KEYFILE" ] && \
  KEYFILE_FLAG="-k" && \
  echo "$KEYFILE" || \
  exit 2

PASS_DB=`ls $PASS_DIR | barmenu $@ -p 'database:'` && \
  [ -f "$PASS_DIR/$PASS_DB" ] &&
  echo "$PASS_DB" || \
  exit 1


PASS_WD=`barmenu -P $@ -p 'password:'`

PASS_LS=`echo "$PASS_WD" | keepassxc-cli ls -Rf "$KEYFILE_FLAG" "$PASS_DIR/$KEYFILE" "$PASS_DIR/$PASS_DB"`

PASSWORD_SEL=`echo "$PASS_LS" | barmenu $@ -p password`

PASS_ATTR=`echo "username\npassword" | barmenu $@ -p "which attribute to copy?"` && \
  [ -z "$PASS_ATTR" ] && \
  PASS_ATTR="password"

echo "$PASS_WD" | keepassxc-cli clip -a "$PASS_ATTR" "$KEYFILE_FLAG" "$PASS_DIR/$KEYFILE" "$PASS_DIR/$PASS_DB" "$PASSWORD_SEL" 15