Added execute fallback to nuke

This commit is contained in:
Jonathan Rash 2021-07-20 19:12:37 -04:00 committed by Arun Prakash Jana
parent 7b31a356d2
commit 4b4355c733
No known key found for this signature in database
GPG Key ID: A75979F35C080412
1 changed files with 21 additions and 4 deletions

View File

@ -21,9 +21,10 @@
# Guards against accidentally opening mime types like executables, shared libs etc.
#
# Tries to play 'file' (1st argument) in the following order:
# i. by extension
# ii. by mime (image, video, audio, pdf)
# iii. by mime (other file types)
# 1. by extension
# 2. by mime (image, video, audio, pdf)
# 3. by mime (other file types)
# 4. by mime (prompt and run executables)
#
# Modification tips:
# 1. Invokes CLI utilities by default. Set GUI to 1 to enable GUI apps.
@ -63,8 +64,9 @@
# 1. Adapt, test and enable all mimes
# 2. Clean-up the unnecessary exit codes
# set to 1 to enable GUI apps
# set to 1 to enable GUI apps and/or BIN execution
GUI="${GUI:-0}"
BIN="${BIN:-0}"
set -euf -o noclobber -o noglob -o nounset
IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n
@ -513,10 +515,25 @@ handle_blocked() {
esac
}
handle_bin() {
case "${MIMETYPE}" in
application/x-executable|application/x-shellscript)
clear
echo '-------- Executable File --------' && file --dereference --brief -- "${FPATH}"
printf "Run executable (y/N)? "
read -r answer
case "$answer" in
[Yy]* ) exec "${FPATH}";;
[Nn]* ) exit;;
esac
esac
}
MIMETYPE="$( file -bL --mime-type -- "${FPATH}" )"
handle_extension
handle_multimedia "${MIMETYPE}"
handle_mime "${MIMETYPE}"
[ "$BIN" -ne 0 ] && [ -x "${FPATH}" ] && handle_bin
handle_blocked "${MIMETYPE}"
handle_fallback