Git Repos / dotfiles / bin / test_mimetype.sh
Last update to this file was on 2024-01-02 at 05:12.
Show test_mimetype.sh
#!/bin/sh
#
# Copyright (c) 2015-2022, Cameron Vanderzanden. Available under the
# terms of the 2-clause BSD license. Please see the file "LICENSE" in
# the root dir of this repository for more information.
#
#- test_mimetype.sh 2016/01/05 cev, updated 2021/07/23 and 2022/01/29 cev
## Usage: test_mimetype.sh [-hvV] [-t type] <file>
##
## Call file(1) on <file> to determine if <file> is a file of mime type
## [-t type]. Type defaults to text/plain.
##
## -h Show help
## -t Test against mimetype [type].
## -v Verbose
## -V Print version info
[ -x $HOME/.local/bin/cev_print.sh ] && . $HOME/.local/bin/cev_print.sh
self="${0##*'/'}"
testtype="text/plain"
verbose=""
while getopts "ht:vV?" option; do
case $option in
h) print_help && exit ;;
t) testtype="$OPTARG" ;;
v) verbose="Y" ;;
V) print_version && exit ;;
"?") print_help && exit ;;
esac
shift $((OPTIND - 1))
done
if [ $# -lt 1 ]; then
print_nofile
exit 2
else
filename="$@"
shortname="$(basename "$@")"
if [ ! -f "$filename" ]; then
print_filenotfound "$filename"
exit 3
fi
filetype="$(file -b --mime-type "$filename")"
if [ "$filetype" = "$testtype" ]; then
if [ "$verbose" ]; then
print_self
printf "%b%s%b is %b%s%b\n" \
"$_high" "$shortname" "$_norm" "$_high" "$testtype" "$_clear"
fi
exit 0
else
if [ "$verbose" ]; then
print_self
printf "%b%s%b is not %b%s%b\n" \
"$_high" "$shortname" "$_norm" "$_high" "$testtype" "$_clear"
fi
exit 1
fi
fi
Return to the top of this page or return to the overview of this repo.
Log test_mimetype.sh
Date | Commit Message | Author | + | - |
---|---|---|---|---|
2024-01-02 | Change from FreeBSD to Linux, other minor changes | cev | +1 | -1 |
2022-01-29 | Adding first batch of audio file handling scripts. | cev | +63 |
Return to the top of this page or return to the overview of this repo.