summaryrefslogtreecommitdiff
path: root/.local/bin/dmenupass
blob: 11b1822ff267a6411703ae687946caf92eaf0d91 (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
#!/usr/bin/sh

getpswds() {
  RET=$(pass ls | sed -E '/^[A-Z]/d;s/[└├](─)* //g;s/(\[0+m)//g' | fzf)
  [ -z "${RET}" ] && exit 0
  echo -en "${RET}"
}

show() {
  PSWD=$1
  [ -z "$PSWD" ] && PSWD=$(getpswds)
  # Necessary in order to allow pasting and not immediately closing the thing
  pass show -c "$PSWD"
  notify-send -t 5000 "Pass" "Copied $PSWD to clipboard"
  sleep 30
}

add() {
  clear
  echo -n "Name for new password: "
  read PSWDNAME
  [ -z "${PSWDNAME}" ] && exit 0
  pass insert "${PSWDNAME}"
}

options() {
  RET=$(echo -e "ls\nshow\ninsert\nadd" | sort | fzf)
  [ -z "${RET}" ] && exit 0
  echo -en "${RET}"
}

CMD="${1}"

[ -z "${CMD}" ] && CMD=$(options)


case "${CMD}" in
  ls) getpswds >/dev/null;;
  show) show;;
  insert) add;;
  add) add;;
esac