Re: [RFC PATCH] Add option to print the first line of an entry

2021-12-29 Thread Johannes Altmanninger
On Wed, Dec 29, 2021 at 05:19:15PM +0100, Rene Kita wrote:
> On Sat, Dec 25, 2021 at 10:19:59AM +0100, Johannes Altmanninger wrote:
> > On Mon, Dec 20, 2021 at 01:40:26PM +0100, Rene Kita wrote:
> 
> > Of course -1 is probably way less common than  --clip, so maybe it's not
> > worth it, I'm not sure.
> I have to disagree. ;) I need -1 way more often then --clip. But maybe I
> just have an unusual workflow.

yeah it depends on the workflow; stdout should be a first class citizen so
I'm in favor.
I recently used it in rdesktop -p (pass ...)


Re: [RFC PATCH] Add option to print the first line of an entry

2021-12-29 Thread Rene Kita
On Sat, Dec 25, 2021 at 10:19:59AM +0100, Johannes Altmanninger wrote:
> On Mon, Dec 20, 2021 at 01:40:26PM +0100, Rene Kita wrote:
> > This commit enables the use of '-1' to print only the first line of an
> > entry. A typical use-case would be: 'password=$(pass -1 example.org)' or
> > 'pass -1 example.org | tmux loadb -'. Before this change one had to use
> > 'sed 1q' or similar when using multi-line entries.
> 
> I like this feature, thanks. It adds convenience, and is consistent with
> --clip= and --qrcode=
Thanks for your feedback!

> Of course -1 is probably way less common than  --clip, so maybe it's not
> worth it, I'm not sure.
I have to disagree. ;) I need -1 way more often then --clip. But maybe I
just have an unusual workflow.

> (Regarding the other thread, I also don't think this should be pushed to
> extensions, since it's a pretty common/core feature, and making the user
> type the extension name kind of defeats the point.)
> 
> The synopsis on error (like "pass -h") also needs an update:
> 
> diff --git a/src/password-store.sh b/src/password-store.sh
> index 77f7ad5..bb50431 100755
> --- a/src/password-store.sh
> +++ b/src/password-store.sh
> @@ -378,7 +378,7 @@ cmd_show() {
>   --) shift; break ;;
>   esac done
>  
> - [[ $err -ne 0 || ( $qrcode -eq 1 && $clip -eq 1 ) ]] && die "Usage: 
> $PROGRAM $COMMAND [--clip[=line-number],-c[line-number]] 
> [--qrcode[=line-number],-q[line-number]] [pass-name]"
> + [[ $err -ne 0 || ( $qrcode -eq 1 && $clip -eq 1 ) ]] && die "Usage: 
> $PROGRAM $COMMAND [-1] [--clip[=line-number],-c[line-number]] 
> [--qrcode[=line-number],-q[line-number]] [pass-name]"
>  
>   local pass
>   local path="$1"
Thanks, will add that to v1. The completion files/functions also need an
update; I'll add that too.


Re: [RFC PATCH] Add option to print the first line of an entry

2021-12-25 Thread Johannes Altmanninger
On Mon, Dec 20, 2021 at 01:40:26PM +0100, Rene Kita wrote:
> This commit enables the use of '-1' to print only the first line of an
> entry. A typical use-case would be: 'password=$(pass -1 example.org)' or
> 'pass -1 example.org | tmux loadb -'. Before this change one had to use
> 'sed 1q' or similar when using multi-line entries.

I like this feature, thanks. It adds convenience, and is consistent with
--clip= and --qrcode=

Of course -1 is probably way less common than  --clip, so maybe it's not
worth it, I'm not sure.

(Regarding the other thread, I also don't think this should be pushed to
extensions, since it's a pretty common/core feature, and making the user
type the extension name kind of defeats the point.)

The synopsis on error (like "pass -h") also needs an update:

diff --git a/src/password-store.sh b/src/password-store.sh
index 77f7ad5..bb50431 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -378,7 +378,7 @@ cmd_show() {
--) shift; break ;;
esac done
 
-   [[ $err -ne 0 || ( $qrcode -eq 1 && $clip -eq 1 ) ]] && die "Usage: 
$PROGRAM $COMMAND [--clip[=line-number],-c[line-number]] 
[--qrcode[=line-number],-q[line-number]] [pass-name]"
+   [[ $err -ne 0 || ( $qrcode -eq 1 && $clip -eq 1 ) ]] && die "Usage: 
$PROGRAM $COMMAND [-1] [--clip[=line-number],-c[line-number]] 
[--qrcode[=line-number],-q[line-number]] [pass-name]"
 
local pass
local path="$1"

> 
> Signed-off-by: Rene Kita 
> ---
>  man/pass.1| 9 +
>  src/password-store.sh | 7 +--
>  2 files changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/man/pass.1 b/man/pass.1
> index a555dcb..cd0ebf0 100644
> --- a/man/pass.1
> +++ b/man/pass.1
> @@ -94,10 +94,11 @@ List names of passwords inside the tree that match 
> \fIpass-names\fP by using the
>  .BR tree (1)
>  program. This command is alternatively named \fBsearch\fP.
>  .TP
> -\fBshow\fP [ \fI--clip\fP[=\fIline-number\fP], \fI-c\fP[\fIline-number\fP] ] 
> [ \fI--qrcode\fP[=\fIline-number\fP], \fI-q\fP[\fIline-number\fP] ] 
> \fIpass-name\fP
> -Decrypt and print a password named \fIpass-name\fP. If \fI--clip\fP or 
> \fI-c\fP
> -is specified, do not print the password but instead copy the first (or 
> otherwise specified)
> -line to the clipboard using
> +\fBshow\fP [ \fI-1\fP ] [ \fI--clip\fP[=\fIline-number\fP], 
> \fI-c\fP[\fIline-number\fP] ] [ \fI--qrcode\fP[=\fIline-number\fP], 
> \fI-q\fP[\fIline-number\fP] ] \fIpass-name\fP
> +Decrypt and print a password named \fIpass-name\fP. If \fI-1\fP is specified,
> +print only the first line. If \fI--clip\fP or \fI-c\fP is specified, do not
> +print the password but instead copy the first (or otherwise specified) line 
> to
> +the clipboard using
>  .BR xclip (1)
>  or
>  .BR wl-clipboard(1)
> diff --git a/src/password-store.sh b/src/password-store.sh
> index aef8d72..f496131 100755
> --- a/src/password-store.sh
> +++ b/src/password-store.sh
> @@ -367,12 +367,13 @@ cmd_init() {
>  
>  cmd_show() {
>   local opts selected_line clip=0 qrcode=0
> - opts="$($GETOPT -o q::c:: -l qrcode::,clip:: -n "$PROGRAM" -- "$@")"
> + opts="$($GETOPT -o :1q::c::: -l qrcode::,clip:: -n "$PROGRAM" -- "$@")"
>   local err=$?
>   eval set -- "$opts"
>   while true; do case $1 in
>   -q|--qrcode) qrcode=1; selected_line="${2:-1}"; shift 2 ;;
>   -c|--clip) clip=1; selected_line="${2:-1}"; shift 2 ;;
> + -1) selected_line=1; shift ;;
>   --) shift; break ;;
>   esac done
>  
> @@ -383,7 +384,7 @@ cmd_show() {
>   local passfile="$PREFIX/$path.gpg"
>   check_sneaky_paths "$path"
>   if [[ -f $passfile ]]; then
> - if [[ $clip -eq 0 && $qrcode -eq 0 ]]; then
> + if [[ $clip -eq 0 && $qrcode -eq 0 && -z $selected_line ]]; then
>   pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | 
> $BASE64)" || exit $?
>   echo "$pass" | $BASE64 -d
>   else
> @@ -394,6 +395,8 @@ cmd_show() {
>   clip "$pass" "$path"
>   elif [[ $qrcode -eq 1 ]]; then
>   qrcode "$pass" "$path"
> + else
> + echo "$pass"
>   fi
>   fi
>   elif [[ -d $PREFIX/$path ]]; then
> -- 
> 2.30.2
> 


Re: [RFC PATCH] Add option to print the first line of an entry

2021-12-22 Thread Greg Minshall
Rene,

> The idea is to make piping the password as easy as copying it to the
> clipboard. IMHO this should be a feature of pass.

easy is good!  here is how i, at least, use `pass tail` (*):


bash wonderful (master): {316} pass tail foo/bar
username: every...@example.com
bash wonderful (master): {317} 


on the question of whether this is easier, harder, i am neutral!

cheers, Greg

(*) once i have it installed, e.g., in

/usr/local/lib/password-store/extensions/tail.bash



Re: [RFC PATCH] Add option to print the first line of an entry

2021-12-22 Thread Rene Kita
On Tue, Dec 21, 2021 at 10:41:51AM +0300, Greg Minshall wrote:
> Rene,
Hi Greg!

> i wonder if it might make sense to do this as a separate extension, a
> companion, e.g., to pass-extension-tail?
I don't think this warrants a separate extension. An extension would be
a lot of code to avoid a '| sed 1q'. The code to get the first line is
already in pass.

The idea is to make piping the password as easy as copying it to the
clipboard. IMHO this should be a feature of pass.

> cheers, Greg
> 
Cheers, Rene


Re: [RFC PATCH] Add option to print the first line of an entry

2021-12-20 Thread Greg Minshall
Rene,

i wonder if it might make sense to do this as a separate extension, a
companion, e.g., to pass-extension-tail?

cheers, Greg