sx-open/sx-open

47 lines
791 B
Plaintext
Raw Normal View History

2014-09-25 13:26:15 +00:00
#!/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() {
2014-09-25 15:05:17 +00:00
local target="$1"
2014-09-25 13:26:15 +00:00
for h in "${!uri_handlers[@]}"; do
grep -oE "${uri_handlers[${h}]}" <<< "$target" && {
2014-09-25 15:05:17 +00:00
${h} "$target" &
return 0
2014-09-25 13:26:15 +00:00
}
done
2014-09-25 15:05:17 +00:00
return 1
2014-09-25 13:26:15 +00:00
}
handle_file() {
2014-09-25 15:05:17 +00:00
local target="$1"
[[ -f "$target" ]] || return 1
2014-09-25 13:26:15 +00:00
target_mimetype=$(file -ib "$target")
for m in "${!mime_handlers[@]}"; do
grep -oE "${mime_handlers[${m}]}" <<< "$target_mimetype" && {
2014-09-25 15:05:17 +00:00
${m} "$target" &
return 0
2014-09-25 13:26:15 +00:00
}
done
2014-09-25 15:05:17 +00:00
return 1
2014-09-25 13:26:15 +00:00
}
main() {
2014-09-25 15:05:17 +00:00
[[ "$1" ]] || { usage; exit; }
2014-09-25 13:26:15 +00:00
2014-09-25 15:05:17 +00:00
handle_file "$1" || handle_uri "$1"
2014-09-25 13:26:15 +00:00
}
main "$@"