init
This commit is contained in:
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 "$@"
|
Reference in New Issue
Block a user