#!/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 grep -oE "${uri_handlers[${h}]}" &>/dev/null <<< "$target" && { ${h} "$target" & return 0 } done return 1 } handle_fs_target() { local target="${1##*file://}" [[ -e "$target" ]] || return 1 target_mimetype=$(file -ib "$target") for m in "${!mime_handlers[@]}"; do grep -oE "${mime_handlers[${m}]}" &>/dev/null <<< "$target_mimetype" && { ${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" } } main "$@"