aboutsummaryrefslogtreecommitdiff
path: root/open-file
diff options
context:
space:
mode:
Diffstat (limited to 'open-file')
-rwxr-xr-xopen-file77
1 files changed, 77 insertions, 0 deletions
diff --git a/open-file b/open-file
new file mode 100755
index 0000000..34df2d7
--- /dev/null
+++ b/open-file
@@ -0,0 +1,77 @@
1#!/bin/sh
2
3# Inspired by https://github.com/salman-abedin/launch.sh
4# Launches files based on their mimetypes
5# Use option -s devour to swallow or -s " " to open normally from terminal
6# Use -t to specify mimetype
7# Requires: dmenu_path or similar (fallback)
8
9menu=${MENU:-dmenu}
10
11while getopts "s:t:" opt; do
12 case "$opt" in
13 s)
14 launcher="$OPTARG"
15 ;;
16 t)
17 mimetype="$OPTARG"
18 ;;
19 esac
20done
21
22shift `expr $OPTIND - 1`
23
24[ -z "$launcher" ] && launcher="spawn"
25[ -z "$mimetype" ] && mimetype="$(file --mime-type "$1" -bL)"
26
27[ -d "$1" ] && $launcher $XFILEMANAGER "$1" && exit 0
28[ ! -f "$1" ] && echo "$1: bad argument" && exit 1
29
30case "$mimetype" in
31 video/*)
32 $launcher $VIDEOPLAYER "$1"
33 ;;
34 audio/*)
35 $launcher $MUSICPLAYER "$1"
36 ;;
37 application/pdf | application/postscript | image/vnd.djvu)
38 $launcher $VIEWER "$1"
39 ;;
40 image/*)
41 $launcher $IMAGEVIEWER "$1"
42 ;;
43 application/msword | \
44 application/vnd.oasis.opendocument.text | text/rtf | \
45 application/vnd.openxmlformats-officedocument.wordprocessingml.*)
46 $launcher $TEXTDOCUMENT "$1"
47 ;;
48 application/ms-excel | application/vnd.oasis.opendocument.spreadsheet | \
49 text/rtf | application/vnd.openxmlformats-officedocument.spreadsheetml.*)
50 $launcher $SPREADSHEET "$1"
51 ;;
52 text/html | text/enriched)
53 $launcher $BROWSER --new-window "$1"
54 ;;
55 text/*)
56 $launcher $XEDITOR "$1"
57 ;;
58 application/zip)
59 unzip "$1"
60 ;;
61 application/x-rar-compressed)
62 unrar "$1"
63 ;;
64 application/x-archive | application/x-tar | \
65 application/x-bzip2 | application/gzip | application/x-lzip | \
66 application/x-lzma | application/x-xz | application/x-gtar)
67 tar -tavf "$1"
68 ;;
69 *)
70 prog=$(dmenu_path | $menu -p "How to open $1 ?")
71 if [ -n "$prog" ]; then
72 $launcher $prog "$1"
73 else
74 exit 1
75 fi
76 ;;
77esac

Generated with cgit - Back to sebastiano.tronto.net