1 Commits
1.4 ... 1.3

Author SHA1 Message Date
fbt
303bdf5d71 that is also redundant 2014-11-26 16:00:03 +03:00
2 changed files with 13 additions and 14 deletions

19
sx-open
View File

@@ -1,6 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# This is an attempt to replace xdg-open with something sane. # This is an attempt to replace xdg-open with something sane.
declare -A uri_handlers
declare -A mime_handlers
# Source the config file. # Source the config file.
cfg_file="$HOME/.config/sx-open.cfg" cfg_file="$HOME/.config/sx-open.cfg"
cfg_uri_regex='^[A-Za-z]([A-Za-z0-9+.-]+)?://.+' cfg_uri_regex='^[A-Za-z]([A-Za-z0-9+.-]+)?://.+'
@@ -11,11 +14,9 @@ usage() { echo "${0##*/} <uri/file>"; }
handle_uri() { handle_uri() {
local target="$1" local target="$1"
for h in "${uri_handlers[@]}"; do for h in "${!uri_handlers[@]}"; do
IFS='=' read cmd regex <<< "$h" [[ "$target" =~ ${uri_handlers[${h}]} ]] && {
${h} "$target" &
[[ "$target" =~ ${regex} ]] && {
${cmd} "$target" &
return 0 return 0
} }
done done
@@ -26,11 +27,9 @@ handle_uri() {
handle_mime() { handle_mime() {
target_mimetype=$(file -ib "$target") target_mimetype=$(file -ib "$target")
for m in "${mime_handlers[@]}"; do for m in "${!mime_handlers[@]}"; do
IFS='=' read cmd regex <<< "$m" [[ "$target_mimetype" =~ ${mime_handlers[${m}]} ]] && {
${m} "$target" &
[[ "$target_mimetype" =~ ${regex} ]] && {
${cmd} "$target" &
return 0 return 0
} }
done 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. # Note that as sx-open checks the regexes in order, they should be placed in order from specific to less so.
uri_handlers=( uri_handlers=(
'steam=^steam://.+' ["steam"]='^steam://.+'
'javaws=.+kvm.+?\.cgi$' ["javaws"]='kvm.+?\.cgi$'
'browser=^http(s)://.+' ["browser"]='^http(s)://.+'
) )
mime_handlers=( mime_handlers=(
'sxiv=image/.+' ["sxiv"]='image/.+'
) )
# vim: syntax=sh # vim: syntax=sh