aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/desktop/password-store.sh
blob: 6918e3f57e01bd7574f326f70cabbc5e07ec827a (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
#! /bin/bash

# Use rofi to quickly access password by command 'pass'
# xsel needed !!

ROFI_ARGS=( "-font" "Hack 22" )

find ~/.password-store -name '*gpg' -printf %P\\n | \
sed 's/.gpg$//' | \
rofi -dmenu "${ROFI_ARGS[@]}" | {
  # Get arguments for command 'pass'
  read ARG1 ARG2

  if [[ -z $ARG1 ]]; then
    exit 1
  elif [[ $ARG1 =~ gen ]]; then
    # Generate a new password by ARG2
    alacritty --hold -e pass --clip generate $ARG2
  else
    pass $ARG1 | {
      # If command fails, just fail directly
      read PASSWORD; [[ -z $PASSWORD ]] && exit 1

      # Simply copy password into system clipboard
      echo $PASSWORD | xsel -ib

      # Show success message, and display extra contents
      rofi -e "Copied: $ARG1 $(echo; echo; cat | sed '1{/^$/d}')" \
      "${ROFI_ARGS[@]}" 
  }
  fi
}