dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit bfad46556277a7b4d9494185259aadac4ca82068
parent 1e0c90366c3aae36d491eb82928c4d9011a758ec
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Tue, 25 Feb 2020 19:17:08 +0100

Use file(1) for file type detection instead of filename regex

Diffstat:
M.local/bin/upload | 28+++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/.local/bin/upload b/.local/bin/upload @@ -46,14 +46,6 @@ show_version() { echo "https://src.adamsgaard.dk/dotfiles" } -regexmatch() { - printf '%s' "$1" | grep -E -q "$2" -} - -regeximatch() { - printf '%s' "$1" | grep -i -E -q "$2" -} - check_if_image() { if [ -f "$1" ]; then identify "$1" >/dev/null 2>&1 || die "error: $1 is not an image" @@ -105,13 +97,19 @@ upload_file() { rsync -rz $progress --chmod=Fu=rw,Fog=r -e "ssh" "$infile" \ "${user}@${host}:${remotedir}/'$newbasename'" if [ "$gopher" = 1 ]; then - if regeximatch "${basename}" '\.(png|jpg|jpeg|tif|bmp)$'; then - type=I - elif regeximatch "${basename}" '\.(pdf|ps|epub|mp4|mkv|webm|ogv|avi|ogg|gifv)$'; then - type=9 - else - type=0 - fi + mime_type="$(file -ib "$infile")" + case "$mime_type" in + image/*) + type=I;; + text/*) + type=0;; + *shellscript*) + type=0;; + *html*) + type=0;; + *) + type=9;; + esac url="gopher://${host}/${type}/${dir}/${newbasename}" else url="https://${host}/${dir}/${newbasename}"