-- Leo's gemini proxy
-- Connecting to git.thebackupbox.net:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
repo: shell-daemons action: commit revision: path_from: revision_from: 135dbc1a727057af92f290382a81a445bdb847c0: path_to: revision_to:
commit 135dbc1a727057af92f290382a81a445bdb847c0 Author: epoch <epoch@hack.thebackupbox.net> Date: Wed Aug 11 01:46:10 2021 +0000 rearranged the main loop in mime-type. duplicated a bit of code, but as long as it does not have to use file --mime-type for everything, it will go faster than it used to. now uses wordtr from the examples in libhashtable so... I guess install that shit too. diff --git a/mime-type b/mime-type
--- a/mime-type +++ b/mime-type @@ -5,71 +5,109 @@ export LANG=C.UTF-8 if [ "$1" = "-h" -o "$1" = "" ];then printf "usage: mime-type [-v] files...\n" - printf " mime-type [-s|--set] file mime-type\n" - printf " mime-type [-u|--unset] file\n" + printf " mime-type [-v] [-s|--set] mime-type files...\n" + printf " mime-type [-v] [-u|--unset] file...\n" + printf "WARNING: the -s and -u options rely on setfattr and will only work on some filesystems.\n" exit 0; fi -if [ "$1" = "-s" -o "$1" = "--set" ];then +if [ "$1" = "-v" -o "$1" = "--verbose" ];then shift - setfattr -n user.mime-type -v "$2" "$1" - exit 0 + verbose=1 fi -if [ "$1" = "-u" -o "$1" = "--unset" ];then +if [ "$1" = "-s" -o "$1" = "--set" ];then + shift + MIME_TYPE="$1" shift - setfattr -x user.mime-type "$1" + while [ "$1" ];do + [ "$verbose" ] && printf "%s: " "$1" + setfattr -n user.mime-type -v "${MIME_TYPE}" "$1" + done exit 0 fi -if [ "$1" = "-v" -o "$1" = "--verbose" ];then +if [ "$1" = "-u" -o "$1" = "--unset" ];then shift - verbose=1 + while [ "$1" ];do + [ "$verbose" ] && printf "%s: " "$1" + setfattr -x user.mime-type "$1" + done + exit 0 fi +### if I can find a way to turn this whole thing into a pipeline, wordtr +### will help it go really fast... +### could just do exec <>3 stuff with it. while [ "$1" ];do - MIME_TYPE="$(file --mime-type -L -b "$1")" - EXT="$(printf '%s\n' "$1" | grep '\.' | rev | cut -d. -f1 | rev)" - #printf 'type: %s ext: %s\n' $MIME_TYPE $EXT - ### extension based overrides go here - if [ "$EXT" = "♊︎" ];then - MIME_TYPE="text/gemini" - fi - if [ "$EXT" = "css" ];then - MIME_TYPE="text/css" - fi - if [ "$EXT" = "txt" ];then - MIME_TYPE="text/plain" - fi - if [ "$EXT" = "sh" ];then - MIME_TYPE="text/plain" - fi - if [ "$EXT" = "js" ];then - MIME_TYPE="text/javascript" - fi - if [ "$EXT" = "svg" ];then - MIME_TYPE="image/svg+xml" - fi - if [ "$EXT" = "hackvr" ];then - MIME_TYPE="application/hackvr" - fi - if [ "$EXT" = "img" ];then - MIME_TYPE="application/x86-image" - fi - if [ "$EXT" = "gmi" ];then - MIME_TYPE="text/gemini" - fi - if [ "$EXT" = "irc" ];then - MIME_TYPE="text/irc" - fi - ### derp if getfattr -n user.mime-type "$1" >/dev/null 2>&1;then MIME_TYPE="$(getfattr --only-values -n user.mime-type "$1" 2>/dev/null)" + [ "$verbose" ] && printf "%s: " "$1" + printf "%s\n" "${MIME_TYPE}" + shift + continue fi - if [ "$verbose" = "1" ];then - printf "%s: %s\n" "$1" "${MIME_TYPE}" - else + + EXT="$(printf '%s\n' "$1" | grep '\.' | rev | cut -d. -f1 | rev)" + #printf 'type: %s ext: %s\n' $MIME_TYPE $EXT + ### extension based overrides go here + ### these should probably be case +# if which wordtr >/dev/null 2>&1;then + MIME_TYPE="$( + printf "%s\n" "$EXT" | wordtr \ + "♊︎" "text/gemini" \ + "css" "text/css" \ + "txt" "text/plain" \ + "sh" "text/plain" \ + "js" "text/javascript" \ + "svg" "image/svg+xml" \ + "hackvr" "application/hackvr" \ + "img" "application/x86-image" \ + "gmi" "text/gemini" \ + "irc" "text/irc" + )" + + if [ "$MIME_TYPE" != "$EXT" ];then + [ "$verbose" ] && printf "%s: " "$1" printf "%s\n" "${MIME_TYPE}" + shift + continue fi + + MIME_TYPE="$(file --mime-type -L -b "$1")" + [ "$verbose" ] && printf "%s: " "$1" + printf "%s\n" "${MIME_TYPE}" shift +#else +# if [ "$EXT" = "♊︎" ];then +# MIME_TYPE="text/gemini" +# fi +# if [ "$EXT" = "css" ];then +# MIME_TYPE="text/css" +# fi +# if [ "$EXT" = "txt" ];then +# MIME_TYPE="text/plain" +# fi +# if [ "$EXT" = "sh" ];then +# MIME_TYPE="text/plain" +# fi +# if [ "$EXT" = "js" ];then +# MIME_TYPE="text/javascript" +# fi +# if [ "$EXT" = "svg" ];then +# MIME_TYPE="image/svg+xml" +# fi +# if [ "$EXT" = "hackvr" ];then +# MIME_TYPE="application/hackvr" +# fi +# if [ "$EXT" = "img" ];then +# MIME_TYPE="application/x86-image" +# fi +# if [ "$EXT" = "gmi" ];then +# MIME_TYPE="text/gemini" +# fi +# if [ "$EXT" = "irc" ];then +# MIME_TYPE="text/irc" +# fi + ### derp done
-----END OF PAGE-----
-- Response ended
-- Page fetched on Sun Jun 2 11:47:24 2024