This commit is contained in:
Jack L. Frost 2015-02-19 14:03:49 +03:00
commit 2470681dcb
2 changed files with 14 additions and 14 deletions

20
sx-open
View File

@ -1,12 +1,8 @@
#!/usr/bin/env bash
# This is an attempt to replace xdg-open with something sane.
declare -A uri_handlers
declare -A mime_handlers
# Source the config file.
cfg_file="$HOME/.config/sx-open.cfg"
cfg_uri_regex='^[A-Za-z]([A-Za-z0-9+.-]+)?://.+'
[[ -f "$cfg_file" ]] && { source "$cfg_file"; }
usage() { echo "${0##*/} <uri/file>"; }
@ -14,9 +10,11 @@ usage() { echo "${0##*/} <uri/file>"; }
handle_uri() {
local target="$1"
for h in "${!uri_handlers[@]}"; do
[[ "$target" =~ ${uri_handlers[${h}]} ]] && {
${h} "$target" &
for h in "${uri_handlers[@]}"; do
IFS='=' read cmd regex <<< "$h"
[[ "$target" =~ ${regex} ]] && {
${cmd} "$target" &
return 0
}
done
@ -27,9 +25,11 @@ handle_uri() {
handle_mime() {
target_mimetype=$(file -ib "$target")
for m in "${!mime_handlers[@]}"; do
[[ "$target_mimetype" =~ ${mime_handlers[${m}]} ]] && {
${m} "$target" &
for m in "${mime_handlers[@]}"; do
IFS='=' read cmd regex <<< "$m"
[[ "$target_mimetype" =~ ${regex} ]] && {
${cmd} "$target" &
return 0
}
done

View File

@ -2,13 +2,13 @@
# Note that as sx-open checks the regexes in order, they should be placed in order from specific to less so.
uri_handlers=(
["steam"]='^steam://.+'
["javaws"]='kvm.+?\.cgi$'
["browser"]='^http(s)://.+'
'steam=^steam://.+'
'javaws=.+kvm.+?\.cgi$'
'browser=^http(s)://.+'
)
mime_handlers=(
["sxiv"]='image/.+'
'sxiv=image/.+'
)
# vim: syntax=sh