Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
303bdf5d71 | |||
d8b9b5dc01 | |||
7696ea5ce8 | |||
214ab03647 | |||
97b1be6732 | |||
545447c9b0 | |||
93ec32f793 | |||
02c7e5cb1a | |||
b32491ea9c | |||
31a48b9795 | |||
6eb58fa18a | |||
6fd20205c4 |
13
LICENSE
Normal file
13
LICENSE
Normal 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.
|
@@ -1,7 +1,7 @@
|
|||||||
sx-open
|
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
|
Installation
|
||||||
------------
|
------------
|
||||||
|
28
sx-open
28
sx-open
@@ -1,17 +1,21 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# This is an attempt to replace xdg-open with something sane.
|
# This is an attempt to replace xdg-open with something sane.
|
||||||
|
|
||||||
|
declare -A uri_handlers
|
||||||
|
declare -A mime_handlers
|
||||||
|
|
||||||
# Source the config file.
|
# Source the config file.
|
||||||
cfg_file="$HOME/.config/sx-open.cfg"
|
cfg_file="$HOME/.config/sx-open.cfg"
|
||||||
|
cfg_uri_regex='^[A-Za-z]([A-Za-z0-9+.-]+)?://.+'
|
||||||
[[ -f "$cfg_file" ]] && { source "$cfg_file"; }
|
[[ -f "$cfg_file" ]] && { source "$cfg_file"; }
|
||||||
|
|
||||||
usage() { echo "usage function not implemented yet."; }
|
usage() { echo "${0##*/} <uri/file>"; }
|
||||||
|
|
||||||
handle_uri() {
|
handle_uri() {
|
||||||
local target="$1"
|
local target="$1"
|
||||||
|
|
||||||
for h in "${!uri_handlers[@]}"; do
|
for h in "${!uri_handlers[@]}"; do
|
||||||
grep -oE "${uri_handlers[${h}]}" &>/dev/null <<< "$target" && {
|
[[ "$target" =~ ${uri_handlers[${h}]} ]] && {
|
||||||
${h} "$target" &
|
${h} "$target" &
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -20,13 +24,11 @@ handle_uri() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_fs_target() {
|
handle_mime() {
|
||||||
local target="${1##*file://}"
|
|
||||||
|
|
||||||
target_mimetype=$(file -ib "$target")
|
target_mimetype=$(file -ib "$target")
|
||||||
|
|
||||||
for m in "${!mime_handlers[@]}"; do
|
for m in "${!mime_handlers[@]}"; do
|
||||||
grep -oE "${mime_handlers[${m}]}" &>/dev/null <<< "$target_mimetype" && {
|
[[ "$target_mimetype" =~ ${mime_handlers[${m}]} ]] && {
|
||||||
${m} "$target" &
|
${m} "$target" &
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -39,11 +41,15 @@ main() {
|
|||||||
target="$1"
|
target="$1"
|
||||||
[[ "$target" ]] || { usage; exit; }
|
[[ "$target" ]] || { usage; exit; }
|
||||||
|
|
||||||
if [[ -e "$target" || "$target" == 'file://'* ]]; then
|
handle_uri "$target" || {
|
||||||
handle_fs_target "$target"
|
[[ "$target" =~ file://.+ ]] && { target="${target##*file://}"; }
|
||||||
else
|
|
||||||
handle_uri "$target"
|
[[ -e "$target" ]] && {
|
||||||
fi
|
[[ "$target" =~ ^/.* ]] || { target="${PWD}/${target}"; }
|
||||||
|
|
||||||
|
handle_mime "$target"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[[ "$?" -gt 0 ]] && { echo "No handlers found for $target"; }
|
[[ "$?" -gt 0 ]] && { echo "No handlers found for $target"; }
|
||||||
|
|
||||||
|
@@ -1,12 +1,10 @@
|
|||||||
# Configuration file for sx-open
|
# 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.
|
# 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=(
|
uri_handlers=(
|
||||||
["steam"]='^steam://.+'
|
["steam"]='^steam://.+'
|
||||||
["browser"]='.+'
|
["javaws"]='kvm.+?\.cgi$'
|
||||||
|
["browser"]='^http(s)://.+'
|
||||||
)
|
)
|
||||||
|
|
||||||
mime_handlers=(
|
mime_handlers=(
|
||||||
|
Reference in New Issue
Block a user