hi. i wonder if i could put in a renewed plug for my own request from a while back? it would be great (for me, anyway) to see this in the main code base.
cheers, and thanks for all those secrets, Greg ---- From: Greg Minshall <minsh...@acm.org> To: password-store@lists.zx2c4.com Subject: option for no highlighting on output Date: Tue, 24 Sep 2019 06:09:22 +0300 hi. i wanted to edit those of my files that matched a certain pattern, and tried: ---- for i in $(pass grep -iw user | grep ':$' | sed s/://); do pass tailedit $i; done ---- but, i got files with names like: ---- tfxPMA-^[[94mbank-hsbc-^[[1mhesab[0m.txt ---- where the characters preceding the initial dash ('-') are to be expected, but the escape sequences ('^[[<NUM>m' [*]) are pass generating highlighting for display on the terminal. similar to a patch from a few months ago (4 Jun 2019) by Gonzalo Matheu i modified pass to optionally disable such escape sequences. i use the non-null existence of an environmental variable PASSWORD_STORE_NOHIGHLIGHT to activate this behavior. i also unconditionally (laziness?) take the "--color=always" argument off the grep command line, replacing it with ${GREPOPTIONS}. a patch follows. i would, of course, love to see it added to the base package. cheers, Greg ---- [*] here <NUM> is a sequence of digits, like '94', '1', '0'; note: i've manually substituted the character string '^[' for the actual escapes in the file names ---- --- src/password-store.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/password-store.sh b/src/password-store.sh index 284eabf..b3b5e8b 100755 --- a/src/password-store.sh +++ b/src/password-store.sh @@ -143,6 +143,12 @@ check_sneaky_paths() { done } +high() { # highlight (or not) + if [[ -z ${PASSWORD_STORE_NOHIGHLIGHT} ]]; then + printf "\e[%dm" $* + fi +} + # # END helper functions # @@ -418,14 +424,14 @@ cmd_grep() { [[ $# -lt 1 ]] && die "Usage: $PROGRAM $COMMAND [GREPOPTIONS] search-string" local passfile grepresults while read -r -d "" passfile; do - grepresults="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | grep --color=always "$@")" + grepresults="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | grep ${GREPOPTIONS} "$@")" [[ $? -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" + printf "%s%s%s%s%s:\n" "$(high 94)" "$passfile_dir" "$(high 1)" "$passfile" "$(high 0)" echo "$grepresults" done < <(find -L "$PREFIX" -path '*/.git' -prune -o -iname '*.gpg' -print0) } @@ -555,7 +561,7 @@ cmd_generate() { elif [[ $qrcode -eq 1 ]]; then qrcode "$pass" "$path" else - printf "\e[1mThe generated password for \e[4m%s\e[24m is:\e[0m\n\e[1m\e[93m%s\e[0m\n" "$path" "$pass" + printf "%sThe generated password for %s%s%s is:%s\n%s%s%s%s\n" "$(high 1)" "$(high 4)" "$path" "$(high 24)" "$(high 0)" "$(high 1)" "$(high 93)" "$pass" "$(high 0)" fi } -- 2.23.0