On Mon, 24 Apr 2017 17:38:55 +0200
Kjetil Torgrim Homme <[email protected]> wrote:
> replacing bashisms with an (undocumented) reliance on GNU find
> (-printf) isn't a good idea IMHO.

Well spotted, thanks.


Here's an updated patch, tested in busybox.

The interesting bit:

    -password=$(printf '%s\n' "${password_files[@]}" | dmenu)
    +password="$(find "$prefix" -type f -name '*.gpg' -print \
    +            | sed "s#^$prefix/##;s/\.gpg$//" | dmenu)"

Don't know if it's any more worthwhile than before, but at least
it's not GNU dependent.


Addendum:

I suppose this might not deal properly with newlines, when it is
technically possible to insert entries containing newlines
(something like `pass insert $'foo\nbar'`).

However dmenu takes in a newline-separated list of values, so AFAIK
there's no good way to write and read newlines (or a substitute)
to and from dmenu.

This is also the current behaviour in master, for passmenu and shell
completion (bash: $'foo\nbar' -> 'f' can complete as 'foo' or 'bar',
zsh: $'foo\nbar' -> 'f' can complete as 'foo' and 'b' as 'bar').


Best,

-- 
John Gliksberg
==============
0033640607695
PhD Bull BXI, UVSQ & UCLM
>From 99e43d8ddad5c235d4493d87bb0f201597ed63e0 Mon Sep 17 00:00:00 2001
From: John Gliksberg <[email protected]>
Date: Fri, 14 Apr 2017 21:58:40 +0200
Subject: [PATCH] [passmenu] Remove bashisms

None of this is a big deal, and bash is used throughout pass,
but this script can be easily debashified.

  * Scrap unnecessary [[ ]] bashism.
  * Add : in default value expansion for readability.
  * Use $HOME instead of ~
    No need to rely on expansion rules for something so simple.
  * Use find + sed stream instead of bash's array expansions
    to deep-glob + substitute + strip extension.
    At the cost of two processes, avoid terse bash expressions
    in favour of common UNIX tools.
    It might even be faster to stream than to build array
    in three steps for a large number of entries
    (if speed is really a concern).
  * Shebang set to /bin/sh to allow running from dash or other.
---
 contrib/dmenu/passmenu | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/contrib/dmenu/passmenu b/contrib/dmenu/passmenu
index 8af5fd0..e2a3025 100755
--- a/contrib/dmenu/passmenu
+++ b/contrib/dmenu/passmenu
@@ -1,6 +1,4 @@
-#!/usr/bin/env bash
-
-shopt -s nullglob globstar
+#!/bin/sh
 
 case "$1" in
     --type )
@@ -16,14 +14,12 @@ case "$1" in
         ;;
 esac
 
-prefix=${PASSWORD_STORE_DIR-~/.password-store}
-password_files=( "$prefix"/**/*.gpg )
-password_files=( "${password_files[@]#"$prefix"/}" )
-password_files=( "${password_files[@]%.gpg}" )
+prefix="${PASSWORD_STORE_DIR:-"$HOME/.password-store"}"
 
-password=$(printf '%s\n' "${password_files[@]}" | dmenu)
+password="$(find "$prefix" -type f -name '*.gpg' -print \
+            | sed "s#^$prefix/##;s/\.gpg$//" | dmenu)"
 
-[[ -n $password ]] || exit
+test -n "$password" || exit
 
 case $typeit in
     0 )
-- 
2.12.2

_______________________________________________
Password-Store mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/password-store

Reply via email to