Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
53 lines (43 sloc) 865 Bytes
#!/bin/bash
err() {
echo $1
usage
exit
}
usage() {
cat <<EOF
Usage: xdg-open [file|url]
It opens a file according to the extension
To setup the extension, create ~/.config/mimi/mime.conf
e.g.
default:urxvt -e ranger
pdf:mupdf
mimi :)
EOF
}
find_program() {
grep "^$1:" "$CONFIG" | cut -d : -f 2
}
CONFIG="$HOME/.config/mimi/mime.conf"
[[ -f "$CONFIG" ]] || err "No configuration file found."
if [[ "$@" == http* ]]; then
# handle url
browser=$(find_program html)
if [[ "$browser" == "" ]]; then
err "'html' is not defined in configuration file."
else
$browser "$@"
fi
else
# handle file
filename="$@"
[[ -f "$filename" ]] || err "The file does not exist."
ext=${filename##*.}
program=$(find_program "$ext")
if [[ "$program" == "" ]]; then
default=$(find_program default)
$default "$filename"
else
$program "$filename"
fi
fi
Jump to Line
Something went wrong with that request. Please try again.