commit 89052504ce77a5f9a77e9edee1290463bcf9b32c Author: fbt Date: Thu Sep 25 17:26:15 2014 +0400 init diff --git a/README.md b/README.md new file mode 100644 index 0000000..08257b2 --- /dev/null +++ b/README.md @@ -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. diff --git a/sx-open b/sx-open new file mode 100755 index 0000000..cd43ffe --- /dev/null +++ b/sx-open @@ -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 "$@" diff --git a/sx-open.cfg b/sx-open.cfg new file mode 100644 index 0000000..33435f2 --- /dev/null +++ b/sx-open.cfg @@ -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