summaryrefslogtreecommitdiff
path: root/tests/fake-editor-change-password.sh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xtests/fake-editor-change-password.sh25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/fake-editor-change-password.sh b/tests/fake-editor-change-password.sh
new file mode 100755
index 0000000..bfae8e1
--- /dev/null
+++ b/tests/fake-editor-change-password.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+# Fake editor program for testing 'pass edit'.
+# Changes password to 'Hello World', leaving rest of file intact.
+#
+# Intended use:
+# export FAKE_EDITOR_PASSWORD="blah blah blah"
+# export EDITOR=fake-editor-change-password.sh
+# $EDITOR <password file>
+#
+# Arguments: <filename>
+# Returns: 0 on success, 1 on error
+
+if [[ $# -ne 1 ]]; then
+ echo "Usage: $0 <filename>"
+ exit 1
+fi
+
+filename=$1 ; shift ;
+new_password="${FAKE_EDITOR_PASSWORD:-Hello World}"
+
+# And change only first line of file
+# -i.tmp allows editing file in place. Extension needed on Mac OSX
+sed -i.tmp "1 s/^.*$/$new_password/g" "$filename"
+
+exit 0