made the code a bit cleaner
This commit is contained in:
parent
8ff05450d2
commit
b2eb1eabf0
26
sx-open
26
sx-open
|
@ -8,33 +8,39 @@ cfg_file="$HOME/.config/sx-open.cfg"
|
||||||
usage() { echo "usage function not implemented yet."; }
|
usage() { echo "usage function not implemented yet."; }
|
||||||
|
|
||||||
handle_uri() {
|
handle_uri() {
|
||||||
|
local target="$1"
|
||||||
|
|
||||||
for h in "${!uri_handlers[@]}"; do
|
for h in "${!uri_handlers[@]}"; do
|
||||||
grep -oE "${uri_handlers[${h}]}" <<< "$target" && {
|
grep -oE "${uri_handlers[${h}]}" <<< "$target" && {
|
||||||
"$h" "$target"
|
${h} "$target" &
|
||||||
break
|
return 0
|
||||||
}
|
}
|
||||||
done
|
done
|
||||||
|
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_file() {
|
handle_file() {
|
||||||
|
local target="$1"
|
||||||
|
|
||||||
|
[[ -f "$target" ]] || return 1
|
||||||
|
|
||||||
target_mimetype=$(file -ib "$target")
|
target_mimetype=$(file -ib "$target")
|
||||||
|
|
||||||
for m in "${!mime_handlers[@]}"; do
|
for m in "${!mime_handlers[@]}"; do
|
||||||
grep -oE "${mime_handlers[${m}]}" <<< "$target_mimetype" && {
|
grep -oE "${mime_handlers[${m}]}" <<< "$target_mimetype" && {
|
||||||
"$m" "$target"
|
${m} "$target" &
|
||||||
break
|
return 0
|
||||||
}
|
}
|
||||||
done
|
done
|
||||||
|
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
target="$1"; [[ "$target" ]] || { usage; exit; }
|
[[ "$1" ]] || { usage; exit; }
|
||||||
|
|
||||||
if [[ -f "$target" ]]; then
|
handle_file "$1" || handle_uri "$1"
|
||||||
handle_file
|
|
||||||
else
|
|
||||||
handle_uri
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user