Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion xdg-open
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash

readonly CONFIG="$HOME/.config/mimi/mimi.conf"
silent=false


find_in_config() {
[[ -f "$CONFIG" ]] || return
Expand Down Expand Up @@ -31,7 +33,9 @@ run() {
}

fork_run() {
if ! $silent; then
echo "'$1' $(printf "%q " "${@:2}")"
fi
if tty -s; then
# in interactive mode, just run normally.
run "$@"
Expand All @@ -48,7 +52,11 @@ exists() {
usage() {
cat <<-EOF

Usage: xdg-open [file|directory|protocol]
Usage: xdg-open [-sh] [file|directory|protocol]

Options:
-s Do not write to standard output
-h Print this help message

It opens a file according to the extension
To setup the extension, create $CONFIG
Expand All @@ -58,6 +66,17 @@ usage() {
exit 1
}

while getopts 'sh' OPTION; do
case "$OPTION" in
s)
silent=true
shift 1
;;
h) usage ;;
?) usage ;;
esac
done

# config
# 1. ext
# 2. protocol
Expand Down Expand Up @@ -143,6 +162,7 @@ for search in $ext $protocol $mime $general_mime; do
i=0
for w in "${app[@]}"; do
if [[ -n "$(echo "$w" | grep '^\$')" ]]; then

program="$(echo "$w" | sed 's/^\$//')"
app[$i]="$(env | grep "^$program=" | head -1 | cut -d = -f 2)"
fi
Expand Down