aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xopen-file119
1 files changed, 59 insertions, 60 deletions
diff --git a/open-file b/open-file
index 9a54446..024f81a 100755
--- a/open-file
+++ b/open-file
@@ -5,8 +5,7 @@
5# Use option -s devour to swallow or -s " " to open normally from terminal 5# Use option -s devour to swallow or -s " " to open normally from terminal
6# Use -t to specify mimetype 6# Use -t to specify mimetype
7# Requires: dmenu_path or similar (fallback) 7# Requires: dmenu_path or similar (fallback)
8# environment variables for default programs need to be set 8# dmenu-filepicker
9# (I might remove this requirement at some point)
10 9
11menu=${MENU:-dmenu} 10menu=${MENU:-dmenu}
12 11
@@ -30,67 +29,67 @@ while getopts "s:t:" opt; do
30 esac 29 esac
31done 30done
32 31
33shift `expr $OPTIND - 1`
34
35# If launcher = "", assume running in terminal, so some programs change 32# If launcher = "", assume running in terminal, so some programs change
36if [ -z "$launcher" ]; then 33if [ -z "$launcher" ]; then
37 xedit=${EDITOR:-vi} 34 xedit=${EDITOR:-vi}
38fi 35fi
39 36
40#[ -z "$launcher" ] && launcher="spawn" 37shift `expr $OPTIND - 1`
41[ -z "$mimetype" ] && mimetype="$(file --mime-type "$1" -bL)" 38toopen=$@
42 39[ -z "$toopen" ] && toopen=$(dmenu-filepicker)
43[ -d "$1" ] && echo "$1: is a directory" && exit 1
44[ ! -f "$1" ] && echo "$1: bad argument" && exit 1
45 40
46case "$mimetype" in 41for f in $toopen; do
47 video/*) 42 [ ! -f "$f" ] && echo "$f: bad argument" && continue
48 $launcher $video "$1" 43 [ -z "$mimetype" ] && mimetype="$(file --mime-type "$f" -bL)"
49 ;; 44 case "$mimetype" in
50 audio/*) 45 video/*)
51 $launcher $music "$1" 46 $launcher $video "$f"
52 ;; 47 ;;
53 application/pdf | application/postscript | image/vnd.djvu) 48 audio/*)
54 $launcher $pdf "$1" 49 $launcher $music "$f"
55 ;; 50 ;;
56 image/*) 51 application/pdf | application/postscript | image/vnd.djvu)
57 $launcher $img "$1" 52 $launcher $pdf "$f"
58 ;; 53 ;;
59 application/msword | \ 54 image/*)
60 application/vnd.oasis.opendocument.text | text/rtf | \ 55 $launcher $img "$f"
61 application/vnd.openxmlformats-officedocument.wordprocessingml.*) 56 ;;
62 $launcher $word "$1" 57 application/msword | \
63 ;; 58 application/vnd.oasis.opendocument.text | text/rtf | \
64 application/ms-excel | application/vnd.oasis.opendocument.spreadsheet | \ 59 application/vnd.openxmlformats-officedocument.wordprocessingml.*)
65 text/rtf | application/vnd.openxmlformats-officedocument.spreadsheetml.*) 60 $launcher $word "$f"
66 $launcher $sheet "$1" 61 ;;
67 ;; 62 application/ms-excel | application/vnd.oasis.opendocument.spreadsheet | \
68 text/html | text/enriched) 63 text/rtf | application/vnd.openxmlformats-officedocument.spreadsheetml.*)
69 $launcher $html "$1" 64 $launcher $sheet "$f"
70 ;; 65 ;;
71 text/*) 66 text/html | text/enriched)
72 $launcher $xedit "$1" 67 $launcher $html "$f"
73 ;; 68 ;;
74 application/zip) 69 text/*)
75 unzip "$1" 70 $launcher $xedit "$f"
76 ;; 71 ;;
77 application/x-rar-compressed) 72 application/zip)
78 unrar "$1" 73 unzip "$f"
79 ;; 74 ;;
80 application/x-archive | application/x-tar | \ 75 application/x-rar-compressed)
81 application/x-bzip2 | application/gzip | application/x-lzip | \ 76 unrar "$f"
82 application/x-lzma | application/x-xz | application/x-gtar) 77 ;;
83 tar -tavf "$1" 78 application/x-archive | application/x-tar | \
84 ;; 79 application/x-bzip2 | application/gzip | application/x-lzip | \
85 application/java-archive) 80 application/x-lzma | application/x-xz | application/x-gtar)
86 java -jar "$1" 81 tar -tavf "$f"
87 ;; 82 ;;
88 *) 83 application/java-archive)
89 prog=$(dmenu_path | $menu -p "How to open $1 ?") 84 java -jar "$f"
90 if [ -n "$prog" ]; then 85 ;;
91 $launcher $prog "$1" 86 *)
92 else 87 prog=$(dmenu_path | $menu -p "How to open $f ?")
93 exit 1 88 if [ -n "$prog" ]; then
94 fi 89 $launcher $prog "$f"
95 ;; 90 else
96esac 91 exit 1
92 fi
93 ;;
94 esac
95done

Generated with cgit - Back to sebastiano.tronto.net