diff options
| author | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-06-10 18:58:52 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-06-10 18:58:52 +0200 |
| commit | b98e05ba63f2e108df634b4d9f9e5530769c6b80 (patch) | |
| tree | a1d3a7f20e826d264f2a6b2141b7b1bfa7debb6f /open-file | |
| parent | ed61c5f085cebb86d3d3a34ce01ec22069c1fc70 (diff) | |
| download | scripts-b98e05ba63f2e108df634b4d9f9e5530769c6b80.tar.gz scripts-b98e05ba63f2e108df634b4d9f9e5530769c6b80.zip | |
Added scripts and readme
Diffstat (limited to '')
| -rwxr-xr-x | open-file | 77 |
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 | |||
| 9 | menu=${MENU:-dmenu} | ||
| 10 | |||
| 11 | while getopts "s:t:" opt; do | ||
| 12 | case "$opt" in | ||
| 13 | s) | ||
| 14 | launcher="$OPTARG" | ||
| 15 | ;; | ||
| 16 | t) | ||
| 17 | mimetype="$OPTARG" | ||
| 18 | ;; | ||
| 19 | esac | ||
| 20 | done | ||
| 21 | |||
| 22 | shift `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 | |||
| 30 | case "$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 | ;; | ||
| 77 | esac | ||
