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