aboutsummaryrefslogtreecommitdiff
path: root/icons-mkmimetypes.sh
blob: 202dbd52e340457f361404623ec17dfd3fed475b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
$TEMPLATE_FOLDER_FILE='file' # .png gets added automatically
#INPUT_FILE=test-globs
#INPUT_FILE=/usr/share/mime/generic-icons < /usr/share/mime/globs
INPUT_FILE=$1
TEMPLATE_FOLDER='scalable/mimetypes-templates' 
OUT_PATH="scalable/mimetypes"

MAX_LINES=`cat $INPUT_FILE | wc -l`
CUR_LINE=0

IFS=':' 
while read A B
do
  if [[ "$A" == "#"* ]]; then continue; fi

  MIME=$A
  FILE=${A/\//-} 
  TEXT=${B/\*\./}

  
  ((CUR_LINE++))
  printf "[%-4d/%-4d] checking for %s\n" "$CUR_LINE" "$MAX_LINES" "$FILE.png"

  if [[ -f "$TEMPLATE_FOLDER/$FILE.png" ]]; then
    echo "using $TEMPLATE_FOLDER"
    cp "$TEMPLATE_FOLDER/$FILE.png" "$OUT_PATH/$FILE.png"
  else

    FIND=$FILE
    while [[ 1 ]]
    do
      # printf "%s\n" $FIND
      if [[ -f "$TEMPLATE_FOLDER/$FIND.png" ]]; then break; fi

      if [[ "$FIND" == "${FIND%-*}" ]]; then FIND="$$TEMPLATE_FOLDER_FILE"; break; fi
      FIND=${FIND%-*}
    done

    # create $TEMPLATE_FOLDER file... just in case there is no desktop file...
    cp "$TEMPLATE_FOLDER/$FIND.png" "$OUT_PATH/$FILE.png"

    DESKTOP=`xdg-mime query default $MIME`
    if [[ -f /usr/share/applications/$DESKTOP ]]; then
      ICONTEXT=`grep -o 'Icon=.*' /usr/share/applications/$DESKTOP`
      APPICON=`find ../../ /usr/share/icons/Adwaita/scalable /usr/share/icons/hicolor/scalable -path '*apps*' -name "${ICONTEXT/Icon=/}*" -type f -print -quit` 

      printf "%-12s%s\t%s\t%s\t%s\n" "" $MIME $DESKTOP $FIND $APPICON

      if [[ "$APPICON" ]]; then
        convert \
          "$TEMPLATE_FOLDER/$FIND.png"  \( -density 400 $APPICON -resize 256 \) \
          -gravity north -geometry +0+20 \
          -compose darken -composite  $OUT_PATH/$FILE.png
      fi
    fi
  fi

  mogrify "$OUT_PATH/$FILE.png" \
    -gravity northwest -pointsize 60 -rotate 90 \
    -stroke '#444' -strokewidth 2 -annotate 0 "${FILE##*-}" \
    -fill   '#ff0'                -annotate 0 "${FILE##*-}" \
    -rotate -90 -resize 256 $OUT_PATH/$FILE.png

done < $INPUT_FILE
..