aboutsummaryrefslogtreecommitdiff
path: root/open-file
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2023-06-20 23:01:09 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2023-06-20 23:01:09 +0200
commit581865ee0c8b8aea872f053d804a41fb5f416b17 (patch)
tree9a2f99ea48c31629a5c3c42b0454483982cdbfed /open-file
parentc5d101ab2c9db3b1a001cb56953cb90b24f8fdcf (diff)
downloadscripts-581865ee0c8b8aea872f053d804a41fb5f416b17.tar.gz
scripts-581865ee0c8b8aea872f053d804a41fb5f416b17.zip
Various shellcheck fixes (www.shellcheck.net)
Diffstat (limited to 'open-file')
-rwxr-xr-xopen-file24
1 files changed, 17 insertions, 7 deletions
diff --git a/open-file b/open-file
index f2fd336..212ae40 100755
--- a/open-file
+++ b/open-file
@@ -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
8menu="dmenu -i -l 15" 9menu="dmenu -i -l 15"
9 10
10# Change default apps here 11# Change default apps here
@@ -17,8 +18,12 @@ sheet="libreoffice"
17html="firefox --new-window" 18html="firefox --new-window"
18xedit="xedit" 19xedit="xedit"
19 20
21usage() {
22 echo "Usage: open-file [-m MENU] [-s LAUNCHER] [-t MIMETYPE] [files...]"
23}
24
20openfile() { 25openfile() {
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
99done 109done
100 110
101shift `expr $OPTIND - 1` 111shift $((OPTIND - 1))
102 112
103if [ -n "$1" ]; then 113if [ -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
108else 118else
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
112fi 122fi

Generated with cgit - Back to sebastiano.tronto.net