Skip to content

Commit 6f01e59

Browse files
author
Konrad Lother
committed
added edit subcommand
final path fixes (d'oh)
1 parent 899d1ec commit 6f01e59

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

file.bash

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ print_usage() {
1111
cmd_store() {
1212
local path="$1"
1313
local file="$2"
14-
local passfile="$PREFIX/$path.gpg"
1514

1615
if [[ ${path: -4} != ".b64" ]]; then
1716
path="${path}.b64"
1817
fi
1918

19+
local passfile="$PREFIX/$path.gpg"
20+
2021
cd $OLDPWD # fix for relative paths
2122

2223
check_sneaky_paths "$1"
@@ -28,7 +29,7 @@ cmd_store() {
2829
die "Error: $file does not exist."
2930
fi
3031

31-
if [[ -f $passfile ]]; then
32+
if [[ -f $passfile ]] && [[ "$PASS_FILE_FORCE_OVERWRITE" != "true" ]]; then
3233
read -r -p "A file with this name already exists in the store. Do you want to overwrite it? [y/N] " response
3334
if [[ $response != [yY] ]]; then
3435
exit 0;
@@ -46,12 +47,13 @@ cmd_store() {
4647

4748
cmd_retrieve() {
4849
local path="$1"
49-
local passfile="$PREFIX/$path.gpg"
5050

5151
if [[ ${path: -4} != ".b64" ]]; then
5252
path="${path}.b64"
5353
fi
5454

55+
local passfile="$PREFIX/$path.gpg"
56+
5557
if [[ -z $path ]]; then
5658
print_usage
5759
else
@@ -60,13 +62,39 @@ cmd_retrieve() {
6062
fi
6163
}
6264

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+
6388
case $1 in
6489
store|add|attach)
6590
shift && cmd_store "$@"
6691
;;
6792
retrieve|show|cat)
6893
shift && cmd_retrieve "$@"
6994
;;
95+
edit|vi)
96+
shift && cmd_edit "$@"
97+
;;
7098
*)
7199
print_usage
72100
;;

testfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
testfile

0 commit comments

Comments
 (0)