forked from carnager/rofi-pass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addpass
executable file
·67 lines (57 loc) · 2.02 KB
/
addpass
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
#!/usr/bin/env bash
source $HOME/.config/rofi-pass/config
if [[ -n "$3" && "$2" == "--root" ]]; then
root="${2}"
elif [[ -n $root ]]; then
root=$root
elif [[ -n $PASSWORD_STORE_DIR ]]; then
root=$PASSWORD_STORE_DIR
else
root="$HOME/.password-store"
fi
if [[ $1 == "--help" || $1 == "-h" ]]; then
echo "add pass files for rofi-pass"
echo "(C) 2015 Rasmus Steinke <rasi at xssn dot at>"
echo ""
echo "--name \"foobar\" Mandatory first argument - filename of password file"
echo "--root \"foobar\" Optional second argument - Absolute path to password store"
echo ""
echo "+FIELD \"barbaz\" Every field name has to start with \"+\""
echo " Values should be quoted"
echo ""
echo "Example:"
echo "addpass --name \"my password file\" --root \"$HOME/passwords\" +user \"Richard\" +foo \"bar\" +autotype \"foo :tab user :tab pass\""
exit
else
echo "$1"
if [[ $1 != "--name" ]]; then
echo "Missing --name option. Try --help"
exit
elif [[ $1 == "--name" ]]; then
Name="$2"
fi
fi
echo "Using database \"$root\""
OIFS=$IFS;
IFS="+";
fields="$@";
fieldsArray=($fields);
read -p "Enter password for entry \"${Name}\" > " -s pass
cd "${root}"
group=$(echo -e "No Group\n---\n$(find -type d -not -iwholename '*.git*' -printf '%d\t%P\n' | sort -r -nk1 | cut -f2-)" | rofi -dmenu -p "Choose Group > ")
echo -e "\n\nStoring file ${Name} in group ${group}"
printEntry () {
echo -e "$pass\n---"
for ((i=1; i<${#fieldsArray[@]}; ++i)); do
field=$(echo "${fieldsArray[$i]}" | awk -F' ' '{print $1}')
option=$(echo "${fieldsArray[$i]}" | cut -d ' ' -f 2- | sed -e 's/[[:blank:]]\+$//')
echo "$field: $option" | grep -Ev 'name:|--root|root:|^:' #${fieldsArray[$i]}";
done
}
if [[ "$group" == "No Group" ]]; then
printEntry | PASSWORD_STORE_DIR="${root}" pass insert -m "${Name}"
elif [[ "$group" == "" ]]; then
exit
else
printEntry | PASSWORD_STORE_DIR="${root}" pass insert -m "${group}/${Name}"
fi