diff options
Diffstat (limited to '.local/bin')
-rwxr-xr-x | .local/bin/nuke | 228 |
1 files changed, 137 insertions, 91 deletions
diff --git a/.local/bin/nuke b/.local/bin/nuke index f8f9d8b..cbcf3a3 100755 --- a/.local/bin/nuke +++ b/.local/bin/nuke | |||
@@ -1,6 +1,5 @@ | |||
1 | #!/usr/bin/env sh | 1 | #!/usr/bin/env sh |
2 | 2 | ||
3 | # ############################################################################# | ||
4 | # Description: Sample script to play files in apps by file type or mime | 3 | # Description: Sample script to play files in apps by file type or mime |
5 | # | 4 | # |
6 | # Shell: POSIX compliant | 5 | # Shell: POSIX compliant |
@@ -14,7 +13,7 @@ | |||
14 | # 2. Run nnn with the program option to indicate a CLI opener | 13 | # 2. Run nnn with the program option to indicate a CLI opener |
15 | # nnn -c | 14 | # nnn -c |
16 | # # The -c program option overrides option -e | 15 | # # The -c program option overrides option -e |
17 | # 3. nuke can use nnn plugins (e.g. mocplay is used for audio), $PATH is updated. | 16 | # 3. nuke can use nnn plugins (e.g. mocq is used for audio), $PATH is updated. |
18 | # | 17 | # |
19 | # Details: | 18 | # Details: |
20 | # Inspired by ranger's scope.sh, modified for usage with nnn. | 19 | # Inspired by ranger's scope.sh, modified for usage with nnn. |
@@ -22,9 +21,10 @@ | |||
22 | # Guards against accidentally opening mime types like executables, shared libs etc. | 21 | # Guards against accidentally opening mime types like executables, shared libs etc. |
23 | # | 22 | # |
24 | # Tries to play 'file' (1st argument) in the following order: | 23 | # Tries to play 'file' (1st argument) in the following order: |
25 | # i. by extension | 24 | # 1. by extension |
26 | # ii. by mime (image, video, audio, pdf) | 25 | # 2. by mime (image, video, audio, pdf) |
27 | # iii. by mime (other file types) | 26 | # 3. by mime (other file types) |
27 | # 4. by mime (prompt and run executables) | ||
28 | # | 28 | # |
29 | # Modification tips: | 29 | # Modification tips: |
30 | # 1. Invokes CLI utilities by default. Set GUI to 1 to enable GUI apps. | 30 | # 1. Invokes CLI utilities by default. Set GUI to 1 to enable GUI apps. |
@@ -32,7 +32,7 @@ | |||
32 | # 3. Start GUI apps in bg to unblock. Redirect stdout and strerr if required. | 32 | # 3. Start GUI apps in bg to unblock. Redirect stdout and strerr if required. |
33 | # 4. Some CLI utilities are piped to the $PAGER, to wait and quit uniformly. | 33 | # 4. Some CLI utilities are piped to the $PAGER, to wait and quit uniformly. |
34 | # 5. If the output cannot be paged use "read -r _" to wait for user input. | 34 | # 5. If the output cannot be paged use "read -r _" to wait for user input. |
35 | # 6. On a DE, try 'xdg-open' in handle_fallback() as last resort. | 35 | # 6. On a DE, try 'xdg-open' or 'open' in handle_fallback() as last resort. |
36 | # | 36 | # |
37 | # Feel free to change the utilities to your favourites and add more mimes. | 37 | # Feel free to change the utilities to your favourites and add more mimes. |
38 | # | 38 | # |
@@ -42,7 +42,7 @@ | |||
42 | # rar: list with unrar | 42 | # rar: list with unrar |
43 | # 7-zip: list with 7z | 43 | # 7-zip: list with 7z |
44 | # pdf: zathura (GUI), pdftotext, mutool, exiftool | 44 | # pdf: zathura (GUI), pdftotext, mutool, exiftool |
45 | # audio: mocplay (nnn plugin using MOC), mpv, mediainfo, exiftool | 45 | # audio: mocq (nnn plugin using MOC), mpv, media_client (Haiku), mediainfo, exiftool |
46 | # avi|mkv|mp4: smplayer, mpv (GUI), ffmpegthumbnailer, mediainfo, exiftool | 46 | # avi|mkv|mp4: smplayer, mpv (GUI), ffmpegthumbnailer, mediainfo, exiftool |
47 | # log: vi | 47 | # log: vi |
48 | # torrent: rtorrent, transmission-show | 48 | # torrent: rtorrent, transmission-show |
@@ -51,22 +51,22 @@ | |||
51 | # htm|html|xhtml: w3m, lynx, elinks | 51 | # htm|html|xhtml: w3m, lynx, elinks |
52 | # json: jq, python (json.tool module) | 52 | # json: jq, python (json.tool module) |
53 | # Multimedia by mime: | 53 | # Multimedia by mime: |
54 | # image/*: imv/sxiv (GUI), viu (https://github.com/atanunq/viu), img2txt, exiftool | 54 | # image/*: imv/sxiv/nsxiv (GUI), viu (https://github.com/atanunq/viu), img2txt, exiftool |
55 | # video/*: smplayer, mpv (GUI), ffmpegthumbnailer, mediainfo, exiftool | 55 | # video/*: smplayer, mpv (GUI), ffmpegthumbnailer, mediainfo, exiftool |
56 | # audio/*: mocplay (nnn plugin using MOC), mpv, mediainfo, exiftool | 56 | # audio/*: mocq (nnn plugin using MOC), mpv, media_client (Haiku), mediainfo, exiftool |
57 | # application/pdf: zathura (GUI), pdftotext, mutool, exiftool | 57 | # application/pdf: zathura (GUI), pdftotext, mutool, exiftool |
58 | # Other mimes: | 58 | # Other mimes: |
59 | # text/troff: man -l | 59 | # text/troff: man -l |
60 | # text/* | */xml: vi | 60 | # text/* | */xml: vi |
61 | # image/vnd.djvu): djvutxt, exiftool | 61 | # image/vnd.djvu): djvutxt, exiftool |
62 | # | 62 | # |
63 | # ToDo: | 63 | # TODO: |
64 | # 1. Adapt, test and enable all mimes | 64 | # 1. Adapt, test and enable all mimes |
65 | # 2. Clean-up the unnecessary exit codes | 65 | # 2. Clean-up the unnecessary exit codes |
66 | # ############################################################################# | ||
67 | 66 | ||
68 | # set to 1 to enable GUI apps | 67 | # set to 1 to enable GUI apps and/or BIN execution |
69 | GUI="1" | 68 | GUI="${GUI:-1}" |
69 | BIN="${BIN:-0}" | ||
70 | 70 | ||
71 | set -euf -o noclobber -o noglob -o nounset | 71 | set -euf -o noclobber -o noglob -o nounset |
72 | IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n | 72 | IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n |
@@ -76,66 +76,80 @@ IMAGE_CACHE_PATH="$(dirname "$1")"/.thumbs | |||
76 | 76 | ||
77 | FPATH="$1" | 77 | FPATH="$1" |
78 | FNAME=$(basename "$1") | 78 | FNAME=$(basename "$1") |
79 | EDITOR="${EDITOR:-vi}" | 79 | EDITOR="${VISUAL:-${EDITOR:-vi}}" |
80 | PAGER="${PAGER:-less -R}" | 80 | PAGER="${PAGER:-less -R}" |
81 | ext="${FNAME##*.}" | 81 | ext="${FNAME##*.}" |
82 | if ! [ -z "$ext" ]; then | 82 | if [ -n "$ext" ]; then |
83 | ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')" | 83 | ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')" |
84 | fi | 84 | fi |
85 | 85 | ||
86 | is_mac() { | ||
87 | uname | grep -q "Darwin" | ||
88 | } | ||
89 | |||
86 | handle_pdf() { | 90 | handle_pdf() { |
87 | if [ "$GUI" -ne 0 ] && which zathura >/dev/null 2>&1; then | 91 | if [ "$GUI" -ne 0 ]; then |
88 | zathura "${FPATH}" >/dev/null 2>&1 & | 92 | if is_mac; then |
89 | exit 0 | 93 | nohup open "${FPATH}" >/dev/null 2>&1 & |
90 | elif which pdftotext >/dev/null 2>&1; then | 94 | elif type zathura >/dev/null 2>&1; then |
95 | nohup zathura "${FPATH}" >/dev/null 2>&1 & | ||
96 | else | ||
97 | return | ||
98 | fi | ||
99 | elif type pdftotext >/dev/null 2>&1; then | ||
91 | ## Preview as text conversion | 100 | ## Preview as text conversion |
92 | pdftotext -l 10 -nopgbrk -q -- "${FPATH}" - | eval "$PAGER" | 101 | pdftotext -l 10 -nopgbrk -q -- "${FPATH}" - | eval "$PAGER" |
93 | exit 0 | 102 | elif type mutool >/dev/null 2>&1; then |
94 | elif which mutool >/dev/null 2>&1; then | ||
95 | mutool draw -F txt -i -- "${FPATH}" 1-10 | eval "$PAGER" | 103 | mutool draw -F txt -i -- "${FPATH}" 1-10 | eval "$PAGER" |
96 | exit 0 | 104 | elif type exiftool >/dev/null 2>&1; then |
97 | elif which exiftool >/dev/null 2>&1; then | ||
98 | exiftool "${FPATH}" | eval "$PAGER" | 105 | exiftool "${FPATH}" | eval "$PAGER" |
99 | exit 0 | 106 | else |
107 | return | ||
100 | fi | 108 | fi |
109 | exit 0 | ||
101 | } | 110 | } |
102 | 111 | ||
103 | handle_audio() { | 112 | handle_audio() { |
104 | if which mocp >/dev/null 2>&1 && which mocplay >/dev/null 2>&1; then | 113 | if type mocp >/dev/null 2>&1 && type mocq >/dev/null 2>&1; then |
105 | mocplay "${FPATH}" "opener" >/dev/null 2>&1 | 114 | mocq "${FPATH}" "opener" >/dev/null 2>&1 |
106 | exit 0 | 115 | elif type mpv >/dev/null 2>&1; then |
107 | elif which mpv >/dev/null 2>&1; then | ||
108 | mpv "${FPATH}" >/dev/null 2>&1 & | 116 | mpv "${FPATH}" >/dev/null 2>&1 & |
109 | exit 0 | 117 | elif type media_client >/dev/null 2>&1; then |
110 | elif which mediainfo >/dev/null 2>&1; then | 118 | media_client play "${FPATH}" >/dev/null 2>&1 & |
119 | elif type mediainfo >/dev/null 2>&1; then | ||
111 | mediainfo "${FPATH}" | eval "$PAGER" | 120 | mediainfo "${FPATH}" | eval "$PAGER" |
112 | exit 0 | 121 | elif type exiftool >/dev/null 2>&1; then |
113 | elif which exiftool >/dev/null 2>&1; then | ||
114 | exiftool "${FPATH}"| eval "$PAGER" | 122 | exiftool "${FPATH}"| eval "$PAGER" |
115 | exit 0 | 123 | else |
124 | return | ||
116 | fi | 125 | fi |
126 | exit 0 | ||
117 | } | 127 | } |
118 | 128 | ||
119 | handle_video() { | 129 | handle_video() { |
120 | if [ "$GUI" -ne 0 ] && which smplayer >/dev/null 2>&1; then | 130 | if [ "$GUI" -ne 0 ]; then |
121 | smplayer "${FPATH}" >/dev/null 2>&1 & | 131 | if is_mac; then |
122 | exit 0 | 132 | nohup open "${FPATH}" >/dev/null 2>&1 & |
123 | elif [ "$GUI" -ne 0 ] && which mpv >/dev/null 2>&1; then | 133 | elif type smplayer >/dev/null 2>&1; then |
124 | mpv "${FPATH}" >/dev/null 2>&1 & | 134 | nohup smplayer "${FPATH}" >/dev/null 2>&1 & |
125 | exit 0 | 135 | elif type mpv >/dev/null 2>&1; then |
126 | elif which ffmpegthumbnailer >/dev/null 2>&1; then | 136 | nohup mpv "${FPATH}" >/dev/null 2>&1 & |
137 | else | ||
138 | return | ||
139 | fi | ||
140 | elif type ffmpegthumbnailer >/dev/null 2>&1; then | ||
127 | # Thumbnail | 141 | # Thumbnail |
128 | [ -d "${IMAGE_CACHE_PATH}" ] || mkdir "${IMAGE_CACHE_PATH}" | 142 | [ -d "${IMAGE_CACHE_PATH}" ] || mkdir "${IMAGE_CACHE_PATH}" |
129 | ffmpegthumbnailer -i "${FPATH}" -o "${IMAGE_CACHE_PATH}/${FNAME}.jpg" -s 0 | 143 | ffmpegthumbnailer -i "${FPATH}" -o "${IMAGE_CACHE_PATH}/${FNAME}.jpg" -s 0 |
130 | viu -n "${IMAGE_CACHE_PATH}/${FNAME}.jpg" | eval "$PAGER" | 144 | viu -n "${IMAGE_CACHE_PATH}/${FNAME}.jpg" | eval "$PAGER" |
131 | exit 0 | 145 | elif type mediainfo >/dev/null 2>&1; then |
132 | elif which mediainfo >/dev/null 2>&1; then | ||
133 | mediainfo "${FPATH}" | eval "$PAGER" | 146 | mediainfo "${FPATH}" | eval "$PAGER" |
134 | exit 0 | 147 | elif type exiftool >/dev/null 2>&1; then |
135 | elif which exiftool >/dev/null 2>&1; then | ||
136 | exiftool "${FPATH}"| eval "$PAGER" | 148 | exiftool "${FPATH}"| eval "$PAGER" |
137 | exit 0 | 149 | else |
150 | return | ||
138 | fi | 151 | fi |
152 | exit 0 | ||
139 | } | 153 | } |
140 | 154 | ||
141 | # handle this extension and exit | 155 | # handle this extension and exit |
@@ -144,22 +158,22 @@ handle_extension() { | |||
144 | ## Archive | 158 | ## Archive |
145 | a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\ | 159 | a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\ |
146 | rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip) | 160 | rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip) |
147 | if which atool >/dev/null 2>&1; then | 161 | if type atool >/dev/null 2>&1; then |
148 | atool --list -- "${FPATH}" | eval "$PAGER" | 162 | atool --list -- "${FPATH}" | eval "$PAGER" |
149 | exit 0 | 163 | exit 0 |
150 | elif which bsdtar >/dev/null 2>&1; then | 164 | elif type bsdtar >/dev/null 2>&1; then |
151 | bsdtar --list --file "${FPATH}" | eval "$PAGER" | 165 | bsdtar --list --file "${FPATH}" | eval "$PAGER" |
152 | exit 0 | 166 | exit 0 |
153 | fi | 167 | fi |
154 | exit 1;; | 168 | exit 1;; |
155 | rar) | 169 | rar) |
156 | if which unrar >/dev/null 2>&1; then | 170 | if type unrar >/dev/null 2>&1; then |
157 | ## Avoid password prompt by providing empty password | 171 | ## Avoid password prompt by providing empty password |
158 | unrar lt -p- -- "${FPATH}" | eval "$PAGER" | 172 | unrar lt -p- -- "${FPATH}" | eval "$PAGER" |
159 | fi | 173 | fi |
160 | exit 1;; | 174 | exit 1;; |
161 | 7z) | 175 | 7z) |
162 | if which 7z >/dev/null 2>&1; then | 176 | if type 7z >/dev/null 2>&1; then |
163 | ## Avoid password prompt by providing empty password | 177 | ## Avoid password prompt by providing empty password |
164 | 7z l -p -- "${FPATH}" | eval "$PAGER" | 178 | 7z l -p -- "${FPATH}" | eval "$PAGER" |
165 | exit 0 | 179 | exit 0 |
@@ -183,39 +197,35 @@ handle_extension() { | |||
183 | 197 | ||
184 | ## Log files | 198 | ## Log files |
185 | log) | 199 | log) |
186 | # "$EDITOR" "${FPATH}" | 200 | "$EDITOR" "${FPATH}" |
187 | "$PAGER" "${FPATH}" | ||
188 | exit 0;; | 201 | exit 0;; |
189 | 202 | ||
190 | ## BitTorrent | 203 | ## BitTorrent |
191 | torrent) | 204 | torrent) |
192 | if which rtorrent >/dev/null 2>&1; then | 205 | if type rtorrent >/dev/null 2>&1; then |
193 | rtorrent "${FPATH}" | 206 | rtorrent "${FPATH}" |
194 | exit 0 | 207 | exit 0 |
195 | elif which transmission-show >/dev/null 2>&1; then | 208 | elif type transmission-show >/dev/null 2>&1; then |
196 | transmission-show -- "${FPATH}" | 209 | transmission-show -- "${FPATH}" |
197 | exit 0 | 210 | exit 0 |
198 | fi | 211 | fi |
199 | exit 1;; | 212 | exit 1;; |
200 | 213 | ||
201 | ## OpenDocument | 214 | ## OpenDocument |
202 | odt|ods|odp|sxw|pptx|docx) | 215 | odt|ods|odp|sxw) |
203 | if which odt2txt >/dev/null 2>&1; then | 216 | if type odt2txt >/dev/null 2>&1; then |
204 | ## Preview as text conversion | 217 | ## Preview as text conversion |
205 | odt2txt "${FPATH}" | eval "$PAGER" | 218 | odt2txt "${FPATH}" | eval "$PAGER" |
206 | exit 0 | 219 | exit 0 |
207 | elif [ "$GUI" -ne 0 ] && which libreoffice >/dev/null 2>&1; then | ||
208 | libreoffice "${FPATH}" & | ||
209 | exit 0 | ||
210 | fi | 220 | fi |
211 | exit 1;; | 221 | exit 1;; |
212 | 222 | ||
213 | ## Markdown | 223 | ## Markdown |
214 | md) | 224 | md) |
215 | if which glow >/dev/null 2>&1; then | 225 | if type glow >/dev/null 2>&1; then |
216 | glow -sdark "${FPATH}" | eval "$PAGER" | 226 | glow -sdark "${FPATH}" | eval "$PAGER" |
217 | exit 0 | 227 | exit 0 |
218 | elif which lowdown >/dev/null 2>&1; then | 228 | elif type lowdown >/dev/null 2>&1; then |
219 | lowdown -Tterm "${FPATH}" | eval "$PAGER" | 229 | lowdown -Tterm "${FPATH}" | eval "$PAGER" |
220 | exit 0 | 230 | exit 0 |
221 | fi | 231 | fi |
@@ -224,13 +234,13 @@ handle_extension() { | |||
224 | ## HTML | 234 | ## HTML |
225 | htm|html|xhtml) | 235 | htm|html|xhtml) |
226 | ## Preview as text conversion | 236 | ## Preview as text conversion |
227 | if which w3m >/dev/null 2>&1; then | 237 | if type w3m >/dev/null 2>&1; then |
228 | w3m -dump "${FPATH}" | eval "$PAGER" | 238 | w3m -dump "${FPATH}" | eval "$PAGER" |
229 | exit 0 | 239 | exit 0 |
230 | elif which lynx >/dev/null 2>&1; then | 240 | elif type lynx >/dev/null 2>&1; then |
231 | lynx -dump -- "${FPATH}" | eval "$PAGER" | 241 | lynx -dump -- "${FPATH}" | eval "$PAGER" |
232 | exit 0 | 242 | exit 0 |
233 | elif which elinks >/dev/null 2>&1; then | 243 | elif type elinks >/dev/null 2>&1; then |
234 | elinks -dump "${FPATH}" | eval "$PAGER" | 244 | elinks -dump "${FPATH}" | eval "$PAGER" |
235 | exit 0 | 245 | exit 0 |
236 | fi | 246 | fi |
@@ -238,40 +248,44 @@ handle_extension() { | |||
238 | 248 | ||
239 | ## JSON | 249 | ## JSON |
240 | json) | 250 | json) |
241 | if which jq >/dev/null 2>&1; then | 251 | if type jq >/dev/null 2>&1; then |
242 | jq --color-output . "${FPATH}" | eval "$PAGER" | 252 | jq --color-output . "${FPATH}" | eval "$PAGER" |
243 | exit 0 | 253 | exit 0 |
244 | elif which python >/dev/null 2>&1; then | 254 | elif type python >/dev/null 2>&1; then |
245 | python -m json.tool -- "${FPATH}" | eval "$PAGER" | 255 | python -m json.tool -- "${FPATH}" | eval "$PAGER" |
246 | exit 0 | 256 | exit 0 |
247 | fi | 257 | fi |
248 | ;; | 258 | ;; |
249 | |||
250 | ## TeX | ||
251 | tex) | ||
252 | "$EDITOR" "${FPATH}" | ||
253 | exit 0;; | ||
254 | esac | 259 | esac |
255 | } | 260 | } |
256 | 261 | ||
262 | # sets the variable abs_target, this should be faster than calling printf | ||
257 | abspath() { | 263 | abspath() { |
258 | case "$1" in | 264 | case "$1" in |
259 | /*) printf "%s\n" "$1";; | 265 | /*) abs_target="$1";; |
260 | *) printf "%s\n" "$PWD/$1";; | 266 | *) abs_target="$PWD/$1";; |
261 | esac | 267 | esac |
262 | } | 268 | } |
263 | 269 | ||
270 | # storing the result to a tmp file is faster than calling listimages twice | ||
264 | listimages() { | 271 | listimages() { |
265 | find -L "$(dirname "$target")" -maxdepth 1 -type f -iregex \ | 272 | find -L "///${1%/*}" -maxdepth 1 -type f -print0 | |
266 | '.*\(jpe?g\|bmp\|png\|gif\)$' -print0 | sort -z | 273 | grep -izZE '\.(jpe?g|png|gif|webp|tiff|bmp|ico|svg)$' | |
274 | sort -z | tee "$tmp" | ||
267 | } | 275 | } |
268 | 276 | ||
269 | load_dir() { | 277 | load_dir() { |
270 | target="$(abspath "$2")" | 278 | abspath "$2" |
271 | count="$(listimages | grep -a -m 1 -ZznF "$target" | cut -d: -f1)" | 279 | tmp="${TMPDIR:-/tmp}/nuke_$$" |
280 | trap 'rm -f $tmp' EXIT | ||
281 | count="$(listimages "$abs_target" | grep -a -m 1 -ZznF "$abs_target" | cut -d: -f1)" | ||
272 | 282 | ||
273 | if [ -n "$count" ]; then | 283 | if [ -n "$count" ]; then |
274 | listimages | xargs -0 "$1" -n "$count" -- | 284 | if [ "$GUI" -ne 0 ]; then |
285 | xargs -0 nohup "$1" -n "$count" -- < "$tmp" | ||
286 | else | ||
287 | xargs -0 "$1" -n "$count" -- < "$tmp" | ||
288 | fi | ||
275 | else | 289 | else |
276 | shift | 290 | shift |
277 | "$1" -- "$@" # fallback | 291 | "$1" -- "$@" # fallback |
@@ -300,19 +314,27 @@ handle_multimedia() { | |||
300 | 314 | ||
301 | ## Image | 315 | ## Image |
302 | image/*) | 316 | image/*) |
303 | if [ "$GUI" -ne 0 ] && which imvr >/dev/null 2>&1; then | 317 | if [ "$GUI" -ne 0 ]; then |
304 | load_dir imvr "${FPATH}" >/dev/null 2>&1 & | 318 | if is_mac; then |
305 | exit 0 | 319 | nohup open "${FPATH}" >/dev/null 2>&1 & |
306 | elif [ "$GUI" -ne 0 ] && which sxiv >/dev/null 2>&1; then | 320 | exit 0 |
307 | load_dir sxiv "${FPATH}" >/dev/null 2>&1 & | 321 | elif type imvr >/dev/null 2>&1; then |
308 | exit 0 | 322 | load_dir imvr "${FPATH}" >/dev/null 2>&1 & |
309 | elif which viu >/dev/null 2>&1; then | 323 | exit 0 |
324 | elif type sxiv >/dev/null 2>&1; then | ||
325 | load_dir sxiv "${FPATH}" >/dev/null 2>&1 & | ||
326 | exit 0 | ||
327 | elif type nsxiv >/dev/null 2>&1; then | ||
328 | load_dir nsxiv "${FPATH}" >/dev/null 2>&1 & | ||
329 | exit 0 | ||
330 | fi | ||
331 | elif type viu >/dev/null 2>&1; then | ||
310 | viu -n "${FPATH}" | eval "$PAGER" | 332 | viu -n "${FPATH}" | eval "$PAGER" |
311 | exit 0 | 333 | exit 0 |
312 | elif which img2txt >/dev/null 2>&1; then | 334 | elif type img2txt >/dev/null 2>&1; then |
313 | img2txt --gamma=0.6 -- "${FPATH}" | eval "$PAGER" | 335 | img2txt --gamma=0.6 -- "${FPATH}" | eval "$PAGER" |
314 | exit 0 | 336 | exit 0 |
315 | elif which exiftool >/dev/null 2>&1; then | 337 | elif type exiftool >/dev/null 2>&1; then |
316 | exiftool "${FPATH}" | eval "$PAGER" | 338 | exiftool "${FPATH}" | eval "$PAGER" |
317 | exit 0 | 339 | exit 0 |
318 | fi | 340 | fi |
@@ -455,11 +477,11 @@ handle_mime() { | |||
455 | 477 | ||
456 | ## DjVu | 478 | ## DjVu |
457 | image/vnd.djvu) | 479 | image/vnd.djvu) |
458 | if which djvutxt >/dev/null 2>&1; then | 480 | if type djvutxt >/dev/null 2>&1; then |
459 | ## Preview as text conversion (requires djvulibre) | 481 | ## Preview as text conversion (requires djvulibre) |
460 | djvutxt "${FPATH}" | eval "$PAGER" | 482 | djvutxt "${FPATH}" | eval "$PAGER" |
461 | exit 0 | 483 | exit 0 |
462 | elif which exiftool >/dev/null 2>&1; then | 484 | elif type exiftool >/dev/null 2>&1; then |
463 | exiftool "${FPATH}" | eval "$PAGER" | 485 | exiftool "${FPATH}" | eval "$PAGER" |
464 | exit 0 | 486 | exit 0 |
465 | fi | 487 | fi |
@@ -469,8 +491,13 @@ handle_mime() { | |||
469 | 491 | ||
470 | handle_fallback() { | 492 | handle_fallback() { |
471 | if [ "$GUI" -ne 0 ]; then | 493 | if [ "$GUI" -ne 0 ]; then |
472 | xdg-open "${FPATH}" >/dev/null 2>&1 & | 494 | if type xdg-open >/dev/null 2>&1; then |
473 | exit 0 | 495 | nohup xdg-open "${FPATH}" >/dev/null 2>&1 & |
496 | exit 0 | ||
497 | elif type open >/dev/null 2>&1; then | ||
498 | nohup open "${FPATH}" >/dev/null 2>&1 & | ||
499 | exit 0 | ||
500 | fi | ||
474 | fi | 501 | fi |
475 | 502 | ||
476 | echo '----- File details -----' && file --dereference --brief -- "${FPATH}" | 503 | echo '----- File details -----' && file --dereference --brief -- "${FPATH}" |
@@ -496,10 +523,29 @@ handle_blocked() { | |||
496 | esac | 523 | esac |
497 | } | 524 | } |
498 | 525 | ||
499 | MIMETYPE="$( file --dereference --brief --mime-type -- "${FPATH}" )" | 526 | handle_bin() { |
527 | case "${MIMETYPE}" in | ||
528 | application/x-executable|application/x-shellscript) | ||
529 | clear | ||
530 | echo '-------- Executable File --------' && file --dereference --brief -- "${FPATH}" | ||
531 | printf "Run executable (y/N/'a'rgs)? " | ||
532 | read -r answer | ||
533 | case "$answer" in | ||
534 | [Yy]* ) exec "${FPATH}";; | ||
535 | [Aa]* ) | ||
536 | printf "args: " | ||
537 | read -r args | ||
538 | exec "${FPATH}" "$args";; | ||
539 | [Nn]* ) exit;; | ||
540 | esac | ||
541 | esac | ||
542 | } | ||
543 | |||
544 | MIMETYPE="$( file -bL --mime-type -- "${FPATH}" )" | ||
500 | handle_extension | 545 | handle_extension |
501 | handle_multimedia "${MIMETYPE}" | 546 | handle_multimedia "${MIMETYPE}" |
502 | handle_mime "${MIMETYPE}" | 547 | handle_mime "${MIMETYPE}" |
548 | [ "$BIN" -ne 0 ] && [ -x "${FPATH}" ] && handle_bin | ||
503 | handle_blocked "${MIMETYPE}" | 549 | handle_blocked "${MIMETYPE}" |
504 | handle_fallback | 550 | handle_fallback |
505 | 551 | ||