Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
303bdf5d71 | |||
d8b9b5dc01 | |||
7696ea5ce8 | |||
214ab03647 | |||
97b1be6732 | |||
545447c9b0 | |||
93ec32f793 |
26
sx-open
26
sx-open
@@ -1,11 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
# This is an attempt to replace xdg-open with something sane.
|
||||
|
||||
declare -A uri_handlers
|
||||
declare -A mime_handlers
|
||||
|
||||
# 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"
|
||||
@@ -20,9 +24,7 @@ handle_uri() {
|
||||
return 1
|
||||
}
|
||||
|
||||
handle_fs_target() {
|
||||
local target="${1##*file://}"
|
||||
|
||||
handle_mime() {
|
||||
target_mimetype=$(file -ib "$target")
|
||||
|
||||
for m in "${!mime_handlers[@]}"; do
|
||||
@@ -39,13 +41,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
|
||||
}
|
||||
|
@@ -1,12 +1,10 @@
|
||||
# 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"]='.+'
|
||||
["javaws"]='kvm.+?\.cgi$'
|
||||
["browser"]='^http(s)://.+'
|
||||
)
|
||||
|
||||
mime_handlers=(
|
||||
|
Reference in New Issue
Block a user