Read pairs, no need for a separator this way
Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
		
							
								
								
									
										25
									
								
								sx-open
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								sx-open
									
									
									
									
									
								
							| @@ -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\+\.\-]+:.+ ]] | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user