[PATCH] Added way to insert files, modified help accordingly. Added -h as additional help parameter

HacKan hackan at gmail.com
Fri Jan 27 19:02:45 CET 2017


---
 src/password-store.sh | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 081057a..9d5b236 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -262,10 +262,12 @@ cmd_usage() {
 	        If put on the clipboard, it will be cleared in $CLIP_TIME seconds.
 	    $PROGRAM grep search-string
 	        Search for password files containing search-string when decrypted.
-	    $PROGRAM insert [--echo,-e | --multiline,-m] [--force,-f] pass-name
+	    $PROGRAM insert [--echo,-e | --multiline,-m] [--force,-f] pass-name [file-path]
 	        Insert new password. Optionally, echo the password back to the console
-	        during entry. Or, optionally, the entry may be multiline. Prompt before
-	        overwriting existing password unless forced.
+	        during entry. Or, optionally, the entry may be multiline. 
+	        If file-path is a file, it will be inserted (options for 
+	        echo and multiline are ignored)
+	        Prompt before overwriting existing password or file unless forced.
 	    $PROGRAM edit pass-name
 	        Insert a new password or edit an existing password using ${EDITOR:-vi}.
 	    $PROGRAM generate [--no-symbols,-n] [--clip,-c] [--in-place,-i | --force,-f] pass-name [pass-length]
@@ -415,7 +417,7 @@ cmd_insert() {
 		--) shift; break ;;
 	esac done
 
-	[[ $err -ne 0 || ( $multiline -eq 1 && $noecho -eq 0 ) || $# -ne 1 ]] && die "Usage: $PROGRAM $COMMAND [--echo,-e | --multiline,-m] [--force,-f] pass-name"
+	[[ $err -ne 0 || ( $multiline -eq 1 && $noecho -eq 0 ) || $# -lt 1 || $# -gt 2 ]] && die "Usage: $PROGRAM $COMMAND [--echo,-e | --multiline,-m] [--force,-f] pass-name [file-path]"
 	local path="${1%/}"
 	local passfile="$PREFIX/$path.gpg"
 	check_sneaky_paths "$path"
@@ -425,7 +427,18 @@ cmd_insert() {
 	mkdir -p -v "$PREFIX/$(dirname "$path")"
 	set_gpg_recipients "$(dirname "$path")"
 
-	if [[ $multiline -eq 1 ]]; then
+	local pwdorfile="password"
+	if [[ -n "${2}" ]]; then
+	    [[ -r "${2}" && -L "${2}" ]] && yesno "The file is a symlink and it's going to be resolved. Are you sure you want that?"
+
+		if [[ -r "${2}" && -f "${2}" ]]; then
+			pwdorfile="file"
+			check_sneaky_paths "${2}"
+			$GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" "${2}" || die "File encryption aborted."
+		else
+			die "File is not valid."
+		fi
+	elif [[ $multiline -eq 1 ]]; then
 		echo "Enter contents of $path and press Ctrl+D when finished:"
 		echo
 		$GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" || die "Password encryption aborted."
@@ -448,7 +461,7 @@ cmd_insert() {
 		read -r -p "Enter password for $path: " -e password
 		$GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" <<<"$password" || die "Password encryption aborted."
 	fi
-	git_add_file "$passfile" "Add given password for $path to store."
+	git_add_file "$passfile" "Add given $pwdorfile for $path to store."
 }
 
 cmd_edit() {
@@ -657,7 +670,7 @@ COMMAND="$1"
 
 case "$1" in
 	init) shift;			cmd_init "$@" ;;
-	help|--help) shift;		cmd_usage "$@" ;;
+	help|--help|-h) shift;		cmd_usage "$@" ;;
 	version|--version) shift;	cmd_version "$@" ;;
 	show|ls|list) shift;		cmd_show "$@" ;;
 	find|search) shift;		cmd_find "$@" ;;
-- 
2.11.0



More information about the Password-Store mailing list