Nah, that doesn't really work. Falling back to this method

This commit is contained in:
Jack L. Frost 2014-09-25 19:11:43 +04:00
parent b2eb1eabf0
commit 69cbb6f286

21
sx-open
View File

@ -11,7 +11,7 @@ handle_uri() {
local target="$1"
for h in "${!uri_handlers[@]}"; do
grep -oE "${uri_handlers[${h}]}" <<< "$target" && {
grep -oE "${uri_handlers[${h}]}" &>/dev/null <<< "$target" && {
${h} "$target" &
return 0
}
@ -20,15 +20,15 @@ handle_uri() {
return 1
}
handle_file() {
handle_fs_target() {
local target="$1"
[[ -f "$target" ]] || return 1
[[ -e "$target" ]] || return 1
target_mimetype=$(file -ib "$target")
for m in "${!mime_handlers[@]}"; do
grep -oE "${mime_handlers[${m}]}" <<< "$target_mimetype" && {
grep -oE "${mime_handlers[${m}]}" &>/dev/null <<< "$target_mimetype" && {
${m} "$target" &
return 0
}
@ -38,9 +38,18 @@ handle_file() {
}
main() {
[[ "$1" ]] || { usage; exit; }
target="$1"
[[ "$target" ]] || { usage; exit; }
handle_file "$1" || handle_uri "$1"
if [[ -e "$target" ]]; then
handle_fs_target "$target"
else
handle_uri "$target"
fi
[[ "$?" -gt 0 ]] && {
echo "No handlers found for $target"
}
}
main "$@"