From c054744d48d28768ad38905ded0b14299ee94163 Mon Sep 17 00:00:00 2001 From: fbt Date: Fri, 27 Jul 2018 16:28:13 +0300 Subject: [PATCH] Allow multiple regexes to be specified Signed-off-by: fbt --- sx-open | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/sx-open b/sx-open index a9e0cf8..59b41cc 100755 --- a/sx-open +++ b/sx-open @@ -1,8 +1,6 @@ #!/usr/bin/env bash # This is an attempt to replace xdg-open with something sane. -usage() { printf '%s [-dhv] \n' "${0##*/}"; } - usage() { cat <<- EOF sx-open [-dhv] @@ -62,7 +60,6 @@ handle_file() { set -- "${mime_handlers[@]}" - while (( $# )); do cmd=$1; regex=$2 @@ -80,8 +77,21 @@ handle_file() { } # DSL -uri() { uri_handlers+=( "$1" "$2" ); } -mime() { mime_handlers+=( "$1" "$2" ); } +uri() { + declare r handler=$1; shift + + for r in "$@"; do + uri_handlers+=( "$handler" "$r" ) + done +} + +mime() { + declare r handler=$1; shift + + for r in "$@"; do + uri_handlers+=( "$1" "$r" ) + done +} is_uri() [[ $1 =~ ^[a-zA-Z][a-zA-Z0-9\+\.\-]+:.+ ]]