40 lines
724 B
Bash
Executable File
40 lines
724 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() {
|
|
for h in "${!uri_handlers[@]}"; do
|
|
grep -oE "${uri_handlers[${h}]}" <<< "$target" && {
|
|
"$h" "$target"
|
|
break
|
|
}
|
|
done
|
|
}
|
|
|
|
handle_file() {
|
|
target_mimetype=$(file -ib "$target")
|
|
|
|
for m in "${!mime_handlers[@]}"; do
|
|
grep -oE "${mime_handlers[${m}]}" <<< "$target_mimetype" && {
|
|
"$m" "$target"
|
|
}
|
|
done
|
|
}
|
|
|
|
main() {
|
|
target="$1"; [[ "$target" ]] || { usage; exit; }
|
|
|
|
if [[ -f "$target" ]]; then
|
|
handle_file
|
|
else
|
|
handle_uri
|
|
fi
|
|
}
|
|
|
|
main "$@"
|