From aeadb503cb5d2aa2b1d403b0dfd2416e3b37ad50 Mon Sep 17 00:00:00 2001
From: John Gliksberg <jg.trosh@gmail.com>
Date: Fri, 14 Apr 2017 21:58:40 +0200
Subject: [PATCH 3/3] [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..1b09f9a 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' -printf '%P\n' \
+           | sed 's/\.gpg$//' | dmenu)
 
-[[ -n $password ]] || exit
+test -n "$password" || exit
 
 case $typeit in
     0 )
-- 
2.12.2

