2ff: Make it idempotent and clean it up a bit - farbfeld - suckless image format with conversion tools
 (HTM) git clone git://git.suckless.org/farbfeld
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 728997ff9662e6790165fd76296bef9ff8a09d93
 (DIR) parent 1f8903d1689e5f796fbe227587081d28f864cb07
 (HTM) Author: FRIGN <dev@frign.de>
       Date:   Mon, 19 Sep 2016 19:07:27 +0200
       
       2ff: Make it idempotent and clean it up a bit
       
       If a file begins with "farbfeld", we just pass it through.
       
       Diffstat:
         M 2ff                                 |      28 ++++++++++++++++++++--------
       
       1 file changed, 20 insertions(+), 8 deletions(-)
       ---
 (DIR) diff --git a/2ff b/2ff
       @@ -5,20 +5,32 @@ if [ "$#" -ne 0 ]; then
        fi
        
        TMP=$(mktemp)
       -cat > "$TMP";
       +cat > "$TMP"
        
       -FORMAT=$(file -ib "$TMP" | cut -d ";" -f 1);
       +if [ "$(head -c 8 "$TMP")" = "farbfeld" ]; then
       +        cat < "$TMP"
       +        exit 0
       +fi
       +
       +FORMAT=$(file -ib "$TMP" | cut -d ";" -f 1)
        
        case "$FORMAT" in
       -    image/png)  png2ff < "$TMP"; ret=$? ;;
       -    image/jpeg) jpg2ff < "$TMP"; ret=$? ;;
       -    *) convert "$TMP" png:- 2>/dev/null | png2ff 2>/dev/null; ret=$? ;;
       +image/png)
       +        png2ff < "$TMP"
       +        ;;
       +image/jpeg)
       +        jpg2ff < "$TMP"
       +        ;;
       +*)
       +        convert "$TMP" png:- 2>/dev/null | png2ff 2>/dev/null
       +        ;;
        esac
        
       -rm "$TMP";
       +ret=$?
       +rm "$TMP"
        
        if [ $ret -ne 0 ]; then
       -        printf "%s: failed to convert %s\n" "$0" "$FORMAT" >&2;
       +        printf "%s: failed to convert from %s\n" "$0" "$FORMAT" >&2
        fi
        
       -exit $ret;
       +exit $ret