From 366f3d4c7cd7125a89b1a049b91a7dd9ab52ec6b Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 25 Apr 2014 02:38:11 +0200 Subject: Pipe everything to a pager. --- man/pass.1 | 8 ++++++++ src/password-store.sh | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/man/pass.1 b/man/pass.1 index 35c81ee..90c24a8 100644 --- a/man/pass.1 +++ b/man/pass.1 @@ -411,6 +411,14 @@ Sets the umask of all files modified by pass, by default \fI077\fP. .TP .I EDITOR The location of the text editor used by \fBedit\fP. +.TP +.I PAGER +The location of the pager used when paging large outputs. +.TP +.I PASSWORD_STORE_LESS +The options to pass to +.BR less (1) +when paging large outputs. .SH SEE ALSO .BR gpg2 (1), .BR pwgen (1), diff --git a/src/password-store.sh b/src/password-store.sh index d7f5eb0..6233a00 100755 --- a/src/password-store.sh +++ b/src/password-store.sh @@ -18,6 +18,12 @@ CLIP_TIME="${PASSWORD_STORE_CLIP_TIME:-45}" export GIT_DIR="${PASSWORD_STORE_GIT:-$PREFIX}/.git" export GIT_WORK_TREE="${PASSWORD_STORE_GIT:-$PREFIX}" +export LESS="${PASSWORD_STORE_LESS:-FRSXMK}" +PAGER="${PAGER:-pager}" +which "$PAGER" &>/dev/null || PAGER="less" +which "$PAGER" &>/dev/null || PAGER="more" +which "$PAGER" &>/dev/null || PAGER="cat" + # # BEGIN helper functions # @@ -313,12 +319,14 @@ cmd_show() { clip "$pass" "$path" fi elif [[ -d $PREFIX/$path ]]; then + { if [[ -z $path ]]; then echo "Password Store" else echo "${path%\/}" fi tree -C -l --noreport "$PREFIX/$path" | tail -n +2 | sed 's/\.gpg$//' + } | "$PAGER" elif [[ -z $path ]]; then die "Error: password store is empty. Try \"pass init\"." else @@ -328,9 +336,11 @@ cmd_show() { cmd_find() { [[ -z "$@" ]] && 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 's/\.gpg$//' + } | "$PAGER" } cmd_grep() { @@ -346,7 +356,7 @@ cmd_grep() { passfile="${passfile##*/}" printf "\e[94m%s/\e[1m%s\e[0m:\n" "$passfile_dir" "$passfile" echo "$grepresults" - done < <(find "$PREFIX" -iname '*.gpg' -print0) + done < <(find "$PREFIX" -iname '*.gpg' -print0) | "$PAGER" } cmd_insert() { -- cgit v1.2.3