[PATCH] variablize flags for various commands

lhn at lorrin.org lhn at lorrin.org
Mon Mar 6 06:45:08 CET 2017


The variable names (CP_OPTS, RM_OPTS, MV_OPTS, GREP_OPTS, MKDIR_OPTS) 
seem too generic to me, given that they're just one subset of the 
options for a particular situation. E.g. OUTPUT_OPTS would be better 
since they're all related to logging, seems better to me. (And don't 
include the -p for mkdir in there; if there's ever support for a 
platform whose mkdir doesn't have a -p, it can get it's own variable.)

Cheers
-Lorrin

On 03/03/2017 06:46 AM, Aaron Bieber wrote:
> Hola,
>
> This patch allows p-s to function on OpenBSD using native cp, rm, mv,
> grep and mkdir. It does this by exposing command flags that can be
> overwritten in the platform/$(uname).sh scripts.
>
> Tests all pass on OpenBSD and Debian 8.7.
>
> Cheers,
> Aaron
>
> diff --git a/src/password-store.sh b/src/password-store.sh
> index 1ab6fb5..737ea5b 100755
> --- a/src/password-store.sh
> +++ b/src/password-store.sh
> @@ -20,6 +20,13 @@ GENERATED_LENGTH="${PASSWORD_STORE_GENERATED_LENGTH:-25}"
>   CHARACTER_SET="${PASSWORD_STORE_CHARACTER_SET:-[:graph:]}"
>   CHARACTER_SET_NO_SYMBOLS="${PASSWORD_STORE_CHARACTER_SET_NO_SYMBOLS:-[:alnum:]}"
>   
> +CP_OPTS="-v"
> +RM_OPTS="-v"
> +MV_OPTS="-v"
> +GREP_OPTS="--color=always"
> +MKDIR_OPTS="-v -p"
> +TREE="tree"
> +
>   export GIT_CEILING_DIRECTORIES="$PREFIX/.."
>   
>   #
> @@ -316,14 +323,14 @@ cmd_init() {
>   
>   	if [[ $# -eq 1 && -z $1 ]]; then
>   		[[ ! -f "$gpg_id" ]] && die "Error: $gpg_id does not exist and so cannot be removed."
> -		rm -v -f "$gpg_id" || exit 1
> +		rm $RM_OPTS -f "$gpg_id" || exit 1
>   		if [[ -n $INNER_GIT_DIR ]]; then
>   			git -C "$INNER_GIT_DIR" rm -qr "$gpg_id"
>   			git_commit "Deinitialize ${gpg_id}${id_path:+ ($id_path)}."
>   		fi
>   		rmdir -p "${gpg_id%/*}" 2>/dev/null
>   	else
> -		mkdir -v -p "$PREFIX/$id_path"
> +		mkdir $MKDIR_OPTS "$PREFIX/$id_path"
>   		printf "%s\n" "$@" > "$gpg_id"
>   		local id_print="$(printf "%s, " "$@")"
>   		echo "Password store initialized for ${id_print%, }${id_path:+ ($id_path)}"
> @@ -379,7 +386,7 @@ cmd_show() {
>   		else
>   			echo "${path%\/}"
>   		fi
> -		tree -C -l --noreport "$PREFIX/$path" | tail -n +2 | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g' # remove .gpg at end of line, but keep colors
> +		"$TREE" -C -l --noreport "$PREFIX/$path" | tail -n +2 | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g' # remove .gpg at end of line, but keep colors
>   	elif [[ -z $path ]]; then
>   		die "Error: password store is empty. Try \"pass init\"."
>   	else
> @@ -391,14 +398,14 @@ cmd_find() {
>   	[[ $# -eq 0 ]] && die "Usage: $PROGRAM $COMMAND pass-names..."
>   	IFS="," eval 'echo "Search Terms: $*"'
>   	local terms="*$(printf '%s*|*' "$@")"
> -	tree -C -l --noreport -P "${terms%|*}" --prune --matchdirs --ignore-case "$PREFIX" | tail -n +2 | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g'
> +	"$TREE" -C -l --noreport -P "${terms%|*}" --prune --matchdirs --ignore-case "$PREFIX" | tail -n +2 | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g'
>   }
>   
>   cmd_grep() {
>   	[[ $# -ne 1 ]] && die "Usage: $PROGRAM $COMMAND search-string"
>   	local search="$1" passfile grepresults
>   	while read -r -d "" passfile; do
> -		grepresults="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | grep --color=always "$search")"
> +		grepresults="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | grep $GREP_OPTS "$search")"
>   		[[ $? -ne 0 ]] && continue
>   		passfile="${passfile%.gpg}"
>   		passfile="${passfile#$PREFIX/}"
> @@ -430,7 +437,7 @@ cmd_insert() {
>   
>   	[[ $force -eq 0 && -e $passfile ]] && yesno "An entry already exists for $path. Overwrite it?"
>   
> -	mkdir -p -v "$PREFIX/$(dirname "$path")"
> +	mkdir $MKDIR_OPTS "$PREFIX/$(dirname "$path")"
>   	set_gpg_recipients "$(dirname "$path")"
>   
>   	if [[ $multiline -eq 1 ]]; then
> @@ -464,7 +471,7 @@ cmd_edit() {
>   
>   	local path="${1%/}"
>   	check_sneaky_paths "$path"
> -	mkdir -p -v "$PREFIX/$(dirname "$path")"
> +	mkdir $MKDIR_OPTS "$PREFIX/$(dirname "$path")"
>   	set_gpg_recipients "$(dirname "$path")"
>   	local passfile="$PREFIX/$path.gpg"
>   	set_git "$passfile"
> @@ -506,7 +513,7 @@ cmd_generate() {
>   	local length="${2:-$GENERATED_LENGTH}"
>   	check_sneaky_paths "$path"
>   	[[ ! $length =~ ^[0-9]+$ ]] && die "Error: pass-length \"$length\" must be a number."
> -	mkdir -p -v "$PREFIX/$(dirname "$path")"
> +	mkdir $MKDIR_OPTS "$PREFIX/$(dirname "$path")"
>   	set_gpg_recipients "$(dirname "$path")"
>   	local passfile="$PREFIX/$path.gpg"
>   	set_git "$passfile"
> @@ -561,7 +568,7 @@ cmd_delete() {
>   
>   	[[ $force -eq 1 ]] || yesno "Are you sure you would like to delete $path?"
>   
> -	rm $recursive -f -v "$passfile"
> +	rm $recursive -f $RM_OPTS "$passfile"
>   	set_git "$passfile"
>   	if [[ -n $INNER_GIT_DIR && ! -e $passfile ]]; then
>   		git -C "$INNER_GIT_DIR" rm -qr "$passfile"
> @@ -595,7 +602,7 @@ cmd_copy_move() {
>   	echo "$old_path"
>   	[[ -e $old_path ]] || die "Error: $1 is not in the password store."
>   
> -	mkdir -p -v "${new_path%/*}"
> +	mkdir $MKDIR_OPTS "${new_path%/*}"
>   	[[ -d $old_path || -d $new_path || $new_path == */ ]] || new_path="${new_path}.gpg"
>   
>   	local interactive="-i"
> @@ -603,7 +610,8 @@ cmd_copy_move() {
>   
>   	set_git "$new_path"
>   	if [[ $move -eq 1 ]]; then
> -		mv $interactive -v "$old_path" "$new_path" || exit 1
> +		echo mv $interactive $MV_OPTS "$old_path" "$new_path"
> +		mv $interactive $MV_OPTS "$old_path" "$new_path" || exit 1
>   		[[ -e "$new_path" ]] && reencrypt_path "$new_path"
>   
>   		set_git "$new_path"
> @@ -620,7 +628,7 @@ cmd_copy_move() {
>   		fi
>   		rmdir -p "$old_dir" 2>/dev/null
>   	else
> -		cp $interactive -r -v "$old_path" "$new_path" || exit 1
> +		cp $interactive -r $CP_OPTS "$old_path" "$new_path" || exit 1
>   		[[ -e "$new_path" ]] && reencrypt_path "$new_path"
>   		git_add_file "$new_path" "Copy ${1} to ${2}."
>   	fi
> diff --git a/src/platform/openbsd.sh b/src/platform/openbsd.sh
> index b66b32f..aa7d479 100644
> --- a/src/platform/openbsd.sh
> +++ b/src/platform/openbsd.sh
> @@ -38,3 +38,10 @@ tmpdir() {
>   
>   GETOPT="gnugetopt"
>   SHRED="rm -P -f"
> +CP_OPTS=""
> +RM_OPTS=""
> +MV_OPTS=""
> +GREP_OPTS=""
> +MKDIR_OPTS="-p"
> +TREE="colortree"
> +
>
>
>
> _______________________________________________
> Password-Store mailing list
> Password-Store at lists.zx2c4.com
> https://lists.zx2c4.com/mailman/listinfo/password-store

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/password-store/attachments/20170305/38544ed1/attachment.html>


More information about the Password-Store mailing list