This commit is contained in:
Jack L. Frost 2014-09-25 17:26:15 +04:00
commit 89052504ce
3 changed files with 64 additions and 0 deletions

10
README.md Normal file
View File

@ -0,0 +1,10 @@
sx-open
=======
sx-open is an attemt to implement a saner alternative to xdg-open.
Installation
------------
Clone the repo, drop sx-open.cfg into your $HOME/.config.
As this thing is meant to replace xdg-open, you will probably want to link sx-open into xdg-open somewhere in your $PATH as to override the default one.

39
sx-open Executable file
View File

@ -0,0 +1,39 @@
#!/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 "$@"

15
sx-open.cfg Normal file
View File

@ -0,0 +1,15 @@
# Configuration file for sx-open
declare -A uri_handlers
declare -A mime_handlers
uri_handlers=(
["steam"]='^steam://.+'
["browser"]='.+'
)
mime_handlers=(
["sxiv"]='image/.+'
)
# vim: syntax=sh