12 Commits
0.1 ... 1.4

Author SHA1 Message Date
fbt
958ae3f264 associative arrays mess up sorting 2015-01-13 23:40:37 +03:00
fbt
d8b9b5dc01 ^file:// is redundant 2014-11-26 15:59:17 +03:00
fbt
7696ea5ce8 ugh, making this work with mimes is annoying 2014-11-25 13:22:15 +03:00
fbt
214ab03647 No no no, that was ugly as hell. Files need to be handled as uris if we want to do so by name 2014-11-21 14:14:01 +03:00
fbt
97b1be6732 the hash table declarations don't need to be in the config. 2014-11-21 13:48:57 +03:00
fbt
545447c9b0 Handling files by name. Takes precedence over mimes. 2014-11-21 13:48:09 +03:00
fbt
93ec32f793 a usage function 2014-11-08 08:03:59 +03:00
fbt
02c7e5cb1a no more grep! 2014-10-16 13:46:57 +04:00
fbt
b32491ea9c Fixing a typo in the readme 2014-09-28 01:49:58 +04:00
fbt
31a48b9795 Hmm. The ISC licence looks better 2014-09-26 02:41:28 +04:00
fbt
6eb58fa18a The year is wrong 2014-09-26 02:34:10 +04:00
fbt
6fd20205c4 add a license 2014-09-26 02:29:28 +04:00
4 changed files with 41 additions and 23 deletions

13
LICENSE Normal file
View File

@@ -0,0 +1,13 @@
Copyright (c) 2014, Jack L. Frost <fbt@fleshless.org>
Permission to use, copy, modify, and/or distribute this software for any purpose with or without
fee is hereby granted, provided that the above copyright notice and this permission notice appear
in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
OF THIS SOFTWARE.

View File

@@ -1,7 +1,7 @@
sx-open
=======
sx-open is an attemt to implement a saner alternative to xdg-open.
sx-open is an attempt to implement a saner alternative to xdg-open.
Installation
------------

39
sx-open
View File

@@ -3,16 +3,19 @@
# Source the config file.
cfg_file="$HOME/.config/sx-open.cfg"
cfg_uri_regex='^[A-Za-z]([A-Za-z0-9+.-]+)?://.+'
[[ -f "$cfg_file" ]] && { source "$cfg_file"; }
usage() { echo "usage function not implemented yet."; }
usage() { echo "${0##*/} <uri/file>"; }
handle_uri() {
local target="$1"
for h in "${!uri_handlers[@]}"; do
grep -oE "${uri_handlers[${h}]}" &>/dev/null <<< "$target" && {
${h} "$target" &
for h in "${uri_handlers[@]}"; do
IFS='=' read cmd regex <<< "$h"
[[ "$target" =~ ${regex} ]] && {
${cmd} "$target" &
return 0
}
done
@@ -20,14 +23,14 @@ handle_uri() {
return 1
}
handle_fs_target() {
local target="${1##*file://}"
handle_mime() {
target_mimetype=$(file -ib "$target")
for m in "${!mime_handlers[@]}"; do
grep -oE "${mime_handlers[${m}]}" &>/dev/null <<< "$target_mimetype" && {
${m} "$target" &
for m in "${mime_handlers[@]}"; do
IFS='=' read cmd regex <<< "$m"
[[ "$target_mimetype" =~ ${regex} ]] && {
${cmd} "$target" &
return 0
}
done
@@ -39,13 +42,17 @@ main() {
target="$1"
[[ "$target" ]] || { usage; exit; }
if [[ -e "$target" || "$target" == 'file://'* ]]; then
handle_fs_target "$target"
else
handle_uri "$target"
fi
handle_uri "$target" || {
[[ "$target" =~ file://.+ ]] && { target="${target##*file://}"; }
[[ "$?" -gt 0 ]] && { echo "No handlers found for $target"; }
[[ -e "$target" ]] && {
[[ "$target" =~ ^/.* ]] || { target="${PWD}/${target}"; }
handle_mime "$target"
}
}
[[ "$?" -gt 0 ]] && { echo "No handlers found for $target"; }
return 0
}

View File

@@ -1,16 +1,14 @@
# Configuration file for sx-open
# Note that as sx-open checks the regexes in order, they should be placed in order from specific to less so.
declare -A uri_handlers
declare -A mime_handlers
uri_handlers=(
["steam"]='^steam://.+'
["browser"]='.+'
'steam=^steam://.+'
'javaws=.+kvm.+?\.cgi$'
'browser=^http(s)://.+'
)
mime_handlers=(
["sxiv"]='image/.+'
'sxiv=image/.+'
)
# vim: syntax=sh