[PATCH] pass generates quite a few errors/warnings with shellcheck

Oliver Albertini oliver.ruben at gmail.com
Mon May 20 17:41:14 CEST 2019


> -		grepresults="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | grep --color=always "$@")"
> -		[[ $? -ne 0 ]] && continue
> -		passfile="${passfile%.gpg}"
> -		passfile="${passfile#$PREFIX/}"
> -		local passfile_dir="${passfile%/*}/"
> -		[[ $passfile_dir == "${passfile}/" ]] && passfile_dir=""
> -		passfile="${passfile##*/}"
> -		printf "\e[94m%s\e[1m%s\e[0m:\n" "$passfile_dir" "$passfile"
> -		echo "$grepresults"
> +		if grepresults="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | grep --color=always "$@")";
> +        	then
> +			passfile="${passfile%.gpg}"
> +			passfile="${passfile#$PREFIX/}"
> +			local passfile_dir="${passfile%/*}/"
> +			[[ $passfile_dir == "${passfile}/" ]] && passfile_dir=""
> +			passfile="${passfile##*/}"
> +			printf "\\e[94m%s\\e[1m%s\\e[0m:\\n" "$passfile_dir" "$passfile"
> +			echo "$grepresults"
> +        	fi

How about this?

grepresults="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | grep --color=always "$@")" || continue

This way, we don't need an indented if block.

This patch looks good to me, and I'm glad that people are using shellcheck.
By the way, it might be helpful to include the path to source files in a
comment line above the source commands, that way shellcheck can do more
thorough checking. I haven't used that a lot, but if it takes a relative
path, it should work.


--

Oliver


More information about the Password-Store mailing list