Skip to content
Browse files

update doc; change search order

  • Loading branch information...
1 parent 86ce6ca commit f957fc2d8377f2318b088da96d233deae200b726 @taylorchu taylorchu committed
Showing with 18 additions and 22 deletions.
  1. +4 −5 README
  2. +14 −17 xdg-open
View
9 README
@@ -15,15 +15,14 @@ for example, I want to define how to open 'text/html'. mime will search in order
1. 'txt' in your config
2. <protocol> in your config (i.e. http, ftp, magnet) ...etc.
3. 'text/html' in your config
-4. 'text/html' in .desktop
-5. 'text/' in your config
+4. 'text/' in your config
+5. 'text/html' in .desktop
6. 'text/' in .desktop
-7. if mimi still cannot find anything, it will open a terminal and bug you.
+7. if mimi still cannot find anything, it will open dmenu and bug you.
note:
-1. sometimes, mimi is smart enough to figure out protocal based on mime-type when it searches for .desktop.
+1. sometimes, mimi is smart enough to figure out protocol based on mime-type when it searches for .desktop.
2. sometimes, if an app requires a terminal to run (ncurses programs), mimi is able to find one terminal app in .desktop.
-if anything fails, it will open a terminal and bug you.
=customize=
this is my own stuff
View
31 xdg-open
@@ -36,10 +36,12 @@ EOF
exit 1
}
+# config
# 1. ext
# 2. protocol
# 3. mime
# 4. general mime
+# .desktop (mime and general mime)
# 5. ask
[[ "$@" == "" ]] && usage
@@ -48,7 +50,9 @@ arg="$@"
ext=""
protocol=""
mime=""
+general_mime=""
+# fix file://
if [[ "$arg" =~ ^file://(.*) ]]; then
# strip file://
arg="${BASH_REMATCH[1]}"
@@ -67,7 +71,7 @@ if [[ -e "$arg" ]]; then
fi
fi
-# handle protocol
+# protocol to mime
if [[ "$arg" =~ ^([a-zA-Z]+): ]]; then
# use protocol to guess mime
protocol="${BASH_REMATCH[1]}"
@@ -81,15 +85,13 @@ if [[ "$arg" =~ ^([a-zA-Z]+): ]]; then
fi
-# application is too general
+# application mime is specific
if [[ "$mime" =~ ^(audio|image|text|video)/ ]]; then
general_mime="${mime%%/*}/"
-else
- general_mime=""
fi
-# 1. ext and 2. protocol
-for search in $ext $protocol; do
+# config
+for search in $ext $protocol $mime $general_mime; do
app="$(find_in_config "$search")"
if [[ "$app" != "" ]]; then
($app "$arg") &
@@ -98,15 +100,8 @@ for search in $ext $protocol; do
done
terminal="$(find_terminal)"
-# 3. mime and 4. protocol
+# .desktop
for search in $mime $general_mime; do
- echo "$search"
- app="$(find_in_config "$search")"
- if [[ "$app" != "" ]]; then
- # has config and mime defined in config
- ($app "$arg") &
- exit 0
- fi
desktop="$(find_desktop_file_by MimeType "$search")"
if [[ "$desktop" != "" ]]; then
# find our own
@@ -122,7 +117,9 @@ for search in $mime $general_mime; do
fi
done
-# 5. ask
-choice="$(IFS=: && stest -flx $PATH| sort -u | dmenu -p "how to open '$arg'")"
-($choice "$arg") &
+# ask
+choice="$(IFS=: && stest -flx $PATH | sort -u | dmenu -p "how to open $arg ($mime)")"
+if [[ "$choice" != "" ]]; then
+ ($choice "$arg") &
+fi
exit 0

0 comments on commit f957fc2

Please sign in to comment.
Something went wrong with that request. Please try again.