@@ -11,12 +11,13 @@ print_usage() {
11
11
cmd_store () {
12
12
local path=" $1 "
13
13
local file=" $2 "
14
- local passfile=" $PREFIX /$path .gpg"
15
14
16
15
if [[ ${path: -4} != " .b64" ]]; then
17
16
path=" ${path} .b64"
18
17
fi
19
18
19
+ local passfile=" $PREFIX /$path .gpg"
20
+
20
21
cd $OLDPWD # fix for relative paths
21
22
22
23
check_sneaky_paths " $1 "
@@ -28,7 +29,7 @@ cmd_store() {
28
29
die " Error: $file does not exist."
29
30
fi
30
31
31
- if [[ -f $passfile ]]; then
32
+ if [[ -f $passfile ]] && [[ " $PASS_FILE_FORCE_OVERWRITE " != " true " ]] ; then
32
33
read -r -p " A file with this name already exists in the store. Do you want to overwrite it? [y/N] " response
33
34
if [[ $response != [yY] ]]; then
34
35
exit 0;
@@ -46,12 +47,13 @@ cmd_store() {
46
47
47
48
cmd_retrieve () {
48
49
local path=" $1 "
49
- local passfile=" $PREFIX /$path .gpg"
50
50
51
51
if [[ ${path: -4} != " .b64" ]]; then
52
52
path=" ${path} .b64"
53
53
fi
54
54
55
+ local passfile=" $PREFIX /$path .gpg"
56
+
55
57
if [[ -z $path ]]; then
56
58
print_usage
57
59
else
@@ -60,13 +62,39 @@ cmd_retrieve() {
60
62
fi
61
63
}
62
64
65
+ cmd_edit () {
66
+ local path=" $1 "
67
+ local passfile=" $PREFIX /$path .gpg"
68
+
69
+ if [[ ${path: -4} != " .b64" ]]; then
70
+ path=" ${path} .b64"
71
+ fi
72
+ if [[ -z $path ]]; then
73
+ print_usage
74
+ elif [[ -z $EDITOR ]]; then
75
+ echo " \$ EDITOR not set, don't know how to open file."
76
+ exit 1
77
+ else
78
+ check_sneaky_paths " $path "
79
+ local tmpfile=$( mktemp)
80
+ chmod 0600 $tmpfile
81
+ cmd_retrieve $path $passfile > $tmpfile
82
+ $EDITOR $tmpfile
83
+ PASS_FILE_FORCE_OVERWRITE=" true" cmd_store $path $tmpfile
84
+ rm $tmpfile
85
+ fi
86
+ }
87
+
63
88
case $1 in
64
89
store|add|attach)
65
90
shift && cmd_store " $@ "
66
91
;;
67
92
retrieve|show|cat)
68
93
shift && cmd_retrieve " $@ "
69
94
;;
95
+ edit|vi)
96
+ shift && cmd_edit " $@ "
97
+ ;;
70
98
* )
71
99
print_usage
72
100
;;
0 commit comments