-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword
executable file
·67 lines (59 loc) · 1.39 KB
/
password
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
60
61
62
63
64
65
66
67
#!/bin/bash
prefix=${PASSWORD_STORE_DIR-~/.password-store}
password_files=( "$prefix"/*.gpg)
password_files+=( "$prefix"/**/*.gpg)
password_files=( "${password_files[@]#"$prefix"/}" )
password_files=( "${password_files[@]%.gpg}" )
showPassword() {
sel=()
num=1
for i in "${password_files[@]}"
do
sel+=("$num"": ""$i")
let "num+=1"
done
selection=$(printf '%s\n' "${sel[@]}" | dmenu -i -l $num | cut -d ' ' -f2)
pass $selection -c
}
addPassword() {
name=$(echo "" | dmenu -p "What name?")
password=$(echo "" | dmenu -p "What password?")
echo $password | pass insert -e $name
}
generatePassword() {
name=$(echo "" | dmenu -p "What name?")
length=$(echo "" | dmenu -p "How long should the password be?")
pass generate -c $name $length
}
noOP() {
operation=$(echo -e "show\nadd\ngenerate" | dmenu -i -p "What to do?")
case $operation in
"show")
showPassword;;
"add")
addPassword;;
"generate")
generatePassword;;
esac
}
printHelp() {
echo "Usage: password <option>"
echo "Options:"
echo -e "No Option\tAction selection in dmenu\n"
echo -e "\t-h\tPrint this\n"
echo -e "\t-s\tShow Passwords\n"
echo -e "\t-a\tAdd a Password\n"
echo -e "\t-g\tGenerate a Password\n"
}
case $1 in
"")
noOP;;
"-h")
printHelp;;
"-s")
showPassword;;
"-a")
addPassword;;
"-g")
generatePassword;;
esac