commit 728997ff9662e6790165fd76296bef9ff8a09d93
Author:     FRIGN <d...@frign.de>
AuthorDate: Mon Sep 19 19:07:27 2016 +0200
Commit:     FRIGN <d...@frign.de>
CommitDate: Mon Sep 19 19:07:27 2016 +0200

    2ff: Make it idempotent and clean it up a bit
    
    If a file begins with "farbfeld", we just pass it through.

diff --git a/2ff b/2ff
index 07c7d46..1b61cef 100755
--- 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

Reply via email to