init
This commit is contained in:
commit
89052504ce
10
README.md
Normal file
10
README.md
Normal 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
39
sx-open
Executable 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
15
sx-open.cfg
Normal 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
|
Loading…
Reference in New Issue
Block a user