From c9e97d63cdb0ae647add1efc7416b4ce0bd69aac Mon Sep 17 00:00:00 2001 From: Jeremy Kaplan Date: Fri, 15 Nov 2019 14:38:01 -0800 Subject: [PATCH] bin: Handle zero-match case in passget --- bin/passget | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/passget b/bin/passget index 4686e2a..e5d984e 100755 --- a/bin/passget +++ b/bin/passget @@ -17,7 +17,10 @@ set -euo pipefail url="$1" mapfile -t matches < <(op list items | jq -c '.[] | select(.overview.url and (.overview.url | contains("'"${url}"'"))) | { uuid: .uuid, url: .overview.url }') -if [ "${#matches[@]}" -eq 1 ]; then +if [ "${#matches[@]}" -eq 0 ]; then + >&2 echo "No matches found for ${url}" + exit 1 +elif [ "${#matches[@]}" -eq 1 ]; then item="${matches[0]}" uuid="$(echo "${item}" | jq -r '.uuid')" else