aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-29 17:07:03 +0100
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-29 17:07:03 +0100
commit55384b992b17ffb2a2d0b36ae8dd251c788ff71a (patch)
tree303aef6be6544d6b1ceb89ab7c67b8ca22e7cf57
parent68898198058898bf6df880106adfabe9cd2704c6 (diff)
downloadscripts-55384b992b17ffb2a2d0b36ae8dd251c788ff71a.tar.gz
scripts-55384b992b17ffb2a2d0b36ae8dd251c788ff71a.zip
Fixed opening multiple files with spaces in name
Diffstat (limited to '')
-rwxr-xr-xopen-file54
1 files changed, 33 insertions, 21 deletions
diff --git a/open-file b/open-file
index 0134e5c..003da25 100755
--- a/open-file
+++ b/open-file
@@ -18,27 +18,9 @@ sheet=${SPREADSHEET:-libreoffice}
18html=${HTMLVIEWER:-firefox} 18html=${HTMLVIEWER:-firefox}
19xedit=${XEDITOR:-gedit} 19xedit=${XEDITOR:-gedit}
20 20
21while getopts "s:t:" opt; do 21openfile() {
22 case "$opt" in 22 f="$@"
23 s)
24 launcher="$OPTARG"
25 ;;
26 t)
27 mimetype="$OPTARG"
28 ;;
29 esac
30done
31 23
32# If launcher = "", assume running in terminal, so some programs change
33#if [ -z "$launcher" ]; then
34# xedit=${EDITOR:-vi}
35#fi
36
37shift `expr $OPTIND - 1`
38toopen=$@
39[ -z "$toopen" ] && toopen=$(dmenu-filepicker)
40
41for f in $toopen; do
42 [ ! -f "$f" ] && echo "$f: bad argument" && exit 1 24 [ ! -f "$f" ] && echo "$f: bad argument" && exit 1
43 [ -z "$mimetype" ] && localmime="$(file --mime-type "$f" -bL)" 25 [ -z "$mimetype" ] && localmime="$(file --mime-type "$f" -bL)"
44 26
@@ -91,8 +73,38 @@ for f in $toopen; do
91 esac 73 esac
92 74
93 if [ -n "$prog" ]; then 75 if [ -n "$prog" ]; then
94 $launcher $prog "$f" & 76 $launcher $prog "$f"
95 else 77 else
96 exit 1 78 exit 1
97 fi 79 fi
80}
81
82while getopts "s:t:" opt; do
83 case "$opt" in
84 s)
85 launcher="$OPTARG"
86 ;;
87 t)
88 mimetype="$OPTARG"
89 ;;
90 esac
98done 91done
92
93# If launcher = "", assume running in terminal, so some programs change
94#if [ -z "$launcher" ]; then
95# xedit=${EDITOR:-vi}
96#fi
97
98shift `expr $OPTIND - 1`
99toopen=$@
100
101if [ -n "$1" ]; then
102 while [ -n "$1" ]; do
103 openfile "$1" &
104 shift
105 done
106else
107 dmenu-filepicker | while read line; do
108 openfile "$line" &
109 done
110fi

Generated with cgit - Back to sebastiano.tronto.net