[
  {
    "path": "README.md",
    "content": "# unsed-image\n\nThis shell script is used to check and clean unused image file in your project  directory，supoort Android and IOS. \n\n## show unused image file\n\n    ./unused-image.sh -p /path/of/your/project\n\n\n## show and clean unused image file\n\n    ./unused-image.sh -r -p /path/of/your/project\n"
  },
  {
    "path": "unused-image.sh",
    "content": "#!/bin/sh\n\nPROGNAME=$(basename \"$0\")\nPROGDIR=$(dirname \"$0\")\n\nusage()\n{\n\techo \"Usage: $PROGNAME  [option]  -p path-of-project\"\n\techo \"\"\n\techo \"-p          Specifyed the path of your project\"\n\techo \"-r          Remove unused image file\"\n\techo \"-h          Show this message\"\n\n\texit 1\n}\n\nPRJ_ROOT=$1\nREMOVE=false\nCOUNT=0\n\n\nwhile getopts \":rp:\" optname\n  do\n    case \"$optname\" in\n      \"p\")\n        PRJ_ROOT=$OPTARG  # specifyed the project root\n        ;;\n      \"r\")\n        REMOVE=true\t\t  # remove unused image resource\n        ;;\n      \"?\")\n        usage\n        ;;\n      \":\")\n        echo \"No argument value for option $OPTARG\"\n        ;;\n      *)\n      # Should not occur\n        echo \"Unknown error while processing options\"\n        ;;\n    esac\n    #echo \"OPTIND is now $OPTIND\"\ndone\n\n\ncheck_files=`find $PRJ_ROOT -name '*.xib' -o -name '*.storyboard' -o -name '*.[mh]'  -o -name '*.pch' -o -name '*.java' -o -name '*.xml'`\n\nfor png in `find $PRJ_ROOT -name '*.png'`\ndo\n    match_name=`basename $png`\n\n    suffix1=\"@2x.png\"\n    suffix2=\".9.png\"\n    suffix3=\".png\"\n    suffix4=\"@3x.png\"\n\n    if [[ ${match_name/${suffix1}//} != $match_name ]]; then\n      match_name=${match_name%$suffix1}\n    elif [[ ${match_name/${suffix4}//} != $match_name ]]; then\n   \t\tmatch_name=${match_name%$suffix4}\n   \telif [[ ${match_name/${suffix2}//} != $match_name ]]; then\n   \t\tmatch_name=${match_name%$suffix2}\n    else\n    \tmatch_name=${match_name%$suffix3}\n    fi\n\n    dir_name=`dirname $png`\n    if [[ $dir_name =~ .bundle$ ]] || [[ $dir_name =~ .appiconset$ ]] || [[ $dir_name =~ .launchimage$ ]]; then\n      continue\n    fi\n\n    referenced=false\n\n    for file  in `echo $check_files | sed 's/\\n/ /g'`\n  \tdo\n  \t    if  grep -sqh \"$match_name\" \"$file\"; then\n  \t        referenced=true\n  \t    fi\n  \tdone\n\n  \tif ! $referenced ; then\n  \t\techo \"The '$png' was not referenced in any file\"\n  \t\tCOUNT=`expr $COUNT + 1`\n  \t\tif $REMOVE ; then\n  \t\t\techo \"Do remove unused image file '$png'\"\n  \t\t\trm -f $png\n  \t\tfi\n  \tfi\n\ndone\n\necho \"============= Total $COUNT unused image files =============\"\n"
  }
]