-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtofi-pass.sh
executable file
·47 lines (37 loc) · 932 Bytes
/
tofi-pass.sh
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
#!/bin/bash
# Copy a password to the clipboard using tofi
# Check if tofi is installed
if ! command -v tofi &> /dev/null
then
echo "tofi could not be found"
exit
fi
# Check if pass is installed
if ! command -v pass &> /dev/null
then
echo "pass could not be found"
exit
fi
PASS=""
RET=""
# Check if PASSWORD_STORE_DIR is set
if [ -z "$PASSWORD_STORE_DIR" ]
then
PASSWORD_STORE_DIR="$HOME/.password-store"
fi
# Get all the passwords
PASS=$(find "$PASSWORD_STORE_DIR" -name '*.gpg' | sed "s|$PASSWORD_STORE_DIR\/||g" | sed 's/.gpg//g')
# Get the password to copy
PASS=$(echo "$PASS" | tofi --prompt-text "Select a password to copy: " 2>/dev/null)
# Exit if the user cancels
if [ -z "$PASS" ]
then
exit
fi
# Copy the password to the clipboard
RET=$(pass show --clip "$PASS")
# Notify if notif-send is installed
if command -v notify-send &> /dev/null
then
notify-send -t 45000 "tofi-pass" "$RET"
fi