54 lines
937 B
Bash
Executable File
54 lines
937 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# This is an attempt to replace xdg-open with something sane.
|
|
|
|
# Source the config file.
|
|
cfg_file="$HOME/.config/sx-open.cfg"
|
|
[[ -f "$cfg_file" ]] && { source "$cfg_file"; }
|
|
|
|
usage() { echo "usage function not implemented yet."; }
|
|
|
|
handle_uri() {
|
|
local target="$1"
|
|
|
|
for h in "${!uri_handlers[@]}"; do
|
|
[[ "$target" =~ ${uri_handlers[${h}]} ]] && {
|
|
${h} "$target" &
|
|
return 0
|
|
}
|
|
done
|
|
|
|
return 1
|
|
}
|
|
|
|
handle_fs_target() {
|
|
local target="${1##*file://}"
|
|
|
|
target_mimetype=$(file -ib "$target")
|
|
|
|
for m in "${!mime_handlers[@]}"; do
|
|
[[ "$target_mimetype" =~ ${mime_handlers[${m}]} ]] && {
|
|
${m} "$target" &
|
|
return 0
|
|
}
|
|
done
|
|
|
|
return 1
|
|
}
|
|
|
|
main() {
|
|
target="$1"
|
|
[[ "$target" ]] || { usage; exit; }
|
|
|
|
if [[ -e "$target" || "$target" == 'file://'* ]]; then
|
|
handle_fs_target "$target"
|
|
else
|
|
handle_uri "$target"
|
|
fi
|
|
|
|
[[ "$?" -gt 0 ]] && { echo "No handlers found for $target"; }
|
|
|
|
return 0
|
|
}
|
|
|
|
main "$@"
|