diff options
Diffstat (limited to '')
| -rwxr-xr-x | open-file | 24 |
1 files changed, 17 insertions, 7 deletions
| @@ -2,9 +2,10 @@ | |||
| 2 | 2 | ||
| 3 | # Inspired by https://github.com/salman-abedin/launch.sh | 3 | # Inspired by https://github.com/salman-abedin/launch.sh |
| 4 | # Launches files based on their mimetypes | 4 | # Launches files based on their mimetypes |
| 5 | # Usage: open-file [-m menu] [-s launcher] [-t mimetype] [files...] | ||
| 6 | # Requires: dmenu_path or similar (fallback), dmenu-filepicker | 5 | # Requires: dmenu_path or similar (fallback), dmenu-filepicker |
| 7 | 6 | ||
| 7 | # Usage: open-file [-m menu] [-s launcher] [-t mimetype] [files...] | ||
| 8 | |||
| 8 | menu="dmenu -i -l 15" | 9 | menu="dmenu -i -l 15" |
| 9 | 10 | ||
| 10 | # Change default apps here | 11 | # Change default apps here |
| @@ -17,8 +18,12 @@ sheet="libreoffice" | |||
| 17 | html="firefox --new-window" | 18 | html="firefox --new-window" |
| 18 | xedit="xedit" | 19 | xedit="xedit" |
| 19 | 20 | ||
| 21 | usage() { | ||
| 22 | echo "Usage: open-file [-m MENU] [-s LAUNCHER] [-t MIMETYPE] [files...]" | ||
| 23 | } | ||
| 24 | |||
| 20 | openfile() { | 25 | openfile() { |
| 21 | f="$@" | 26 | f="$*" |
| 22 | localmime="$mimetype" | 27 | localmime="$mimetype" |
| 23 | 28 | ||
| 24 | [ ! -f "$f" ] && echo "$f: bad argument" && exit 1 | 29 | [ ! -f "$f" ] && echo "$f: bad argument" && exit 1 |
| @@ -43,8 +48,9 @@ openfile() { | |||
| 43 | application/vnd.openxmlformats-officedocument.wordprocessingml.*) | 48 | application/vnd.openxmlformats-officedocument.wordprocessingml.*) |
| 44 | prog="$word" | 49 | prog="$word" |
| 45 | ;; | 50 | ;; |
| 46 | application/ms-excel | application/vnd.oasis.opendocument.spreadsheet | \ | 51 | application/ms-excel | \ |
| 47 | text/rtf | application/vnd.openxmlformats-officedocument.spreadsheetml.*) | 52 | application/vnd.oasis.opendocument.spreadsheet | \ |
| 53 | application/vnd.openxmlformats-officedocument.spreadsheetml.*) | ||
| 48 | prog="$sheet" | 54 | prog="$sheet" |
| 49 | ;; | 55 | ;; |
| 50 | text/html | text/enriched) | 56 | text/html | text/enriched) |
| @@ -78,7 +84,7 @@ openfile() { | |||
| 78 | esac | 84 | esac |
| 79 | 85 | ||
| 80 | if [ -n "$prog" ]; then | 86 | if [ -n "$prog" ]; then |
| 81 | $launcher $prog "$f" | 87 | $launcher "$prog" "$f" |
| 82 | else | 88 | else |
| 83 | exit 1 | 89 | exit 1 |
| 84 | fi | 90 | fi |
| @@ -95,10 +101,14 @@ while getopts "m:s:t:" opt; do | |||
| 95 | t) | 101 | t) |
| 96 | mimetype="$OPTARG" | 102 | mimetype="$OPTARG" |
| 97 | ;; | 103 | ;; |
| 104 | *) | ||
| 105 | usage | ||
| 106 | exit 1 | ||
| 107 | ;; | ||
| 98 | esac | 108 | esac |
| 99 | done | 109 | done |
| 100 | 110 | ||
| 101 | shift `expr $OPTIND - 1` | 111 | shift $((OPTIND - 1)) |
| 102 | 112 | ||
| 103 | if [ -n "$1" ]; then | 113 | if [ -n "$1" ]; then |
| 104 | while [ -n "$1" ]; do | 114 | while [ -n "$1" ]; do |
| @@ -106,7 +116,7 @@ if [ -n "$1" ]; then | |||
| 106 | shift | 116 | shift |
| 107 | done | 117 | done |
| 108 | else | 118 | else |
| 109 | dmenu-filepicker -m "$menu" | while read line; do | 119 | dmenu-filepicker -m "$menu" | while read -r line; do |
| 110 | openfile "$line" & | 120 | openfile "$line" & |
| 111 | done | 121 | done |
| 112 | fi | 122 | fi |
