Read pairs, no need for a separator this way

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
Jack L. Frost 2018-07-27 08:05:14 +03:00
parent 7eef67695a
commit 8493a07fdc
1 changed files with 17 additions and 8 deletions

25
sx-open
View File

@ -27,15 +27,19 @@ handle_uri() {
declare -n result=$1 declare -n result=$1
declare h cmd regex target=$2 declare h cmd regex target=$2
for h in "${uri_handlers[@]}"; do set -- "${uri_handlers[@]}"
IFS='=' read cmd regex <<< "$h"
if [[ "$target" =~ ${regex} ]]; then while (( $# )); do
cmd=$1; regex=$2
if [[ "$target" =~ $regex ]]; then
act ${cmd} "$target"; result=$? act ${cmd} "$target"; result=$?
(( result )) && return 1 (( result )) && return 1
return 0 return 0
fi fi
shift 2
done done
return 3 return 3
@ -56,23 +60,28 @@ handle_file() {
IFS=';' read target_mimetype charset <<< $( file -ib "$target" ) IFS=';' read target_mimetype charset <<< $( file -ib "$target" )
for m in "${mime_handlers[@]}"; do set -- "${mime_handlers[@]}"
IFS='=' read cmd regex <<< "$m"
if [[ "$target_mimetype" =~ ${regex} ]]; then
while (( $# )); do
cmd=$1; regex=$2
if [[ "$target_mimetype" =~ $regex ]]; then
act ${cmd} "$target"; result=$? act ${cmd} "$target"; result=$?
(( result )) && return 1 (( result )) && return 1
return 0 return 0
fi fi
shift 2
done done
return 3 return 3
} }
# DSL # DSL
uri() { uri_handlers+=( "$1=$2" ); } uri() { uri_handlers+=( "$1" "$2" ); }
mime() { mime_handlers+=( "$1=$2" ); } mime() { mime_handlers+=( "$1" "$2" ); }
is_uri() [[ $1 =~ ^[a-zA-Z][a-zA-Z0-9\+\.\-]+:.+ ]] is_uri() [[ $1 =~ ^[a-zA-Z][a-zA-Z0-9\+\.\-]+:.+ ]]