Monday, May 15, 2017

Extract eclipse svg images

When creating new icons for applications I like browsing existing eclipse svg images. The repository structure is nice when you know what to look for. But with all its subfolders it is not suited for interactive browsing.

While I am not worlds greatest bash script kiddie, I assembled a script that clones the repo and sorts its svg images. after execution you end up with a folder eclipse_images that hosts the svg files.

If you improve the script, please post it here so others can benefit.

#!/bin/bash

# create working dir
mkdir eclipse_images
cd eclipse_images/

# get images
git clone  git://git.eclipse.org/gitroot/platform/eclipse.platform.images.git

# extract all svg images
for line in `find eclipse.platform.images/ -iname "*.svg"`;
do
   echo line | awk -v source="$line" '{str=source; gsub(/\//, "_", str); gsub(/eclipse.platform.images_org.eclipse.images_eclipse-svg_/, "", str); gsub(/icons_full_/, "", str); gsub(/_icons_/, "_", str); print "mv \"" source "\" \""  str "\""}' | bash -sx
done

# remove rest of repository
rm -rf eclipse.platform.images

# extract subtype 'wizard banner'
mkdir "wizban"
for line in `find . -maxdepth 1 -iname "*_wizban_*.svg"`;
do
 mv "$line" "wizban"
done

# extract overlay images
mkdir "overlay"
for line in `find . -maxdepth 1 -regextype posix-extended -regex "^.*_ovr(16_.*)?.*.svg"`;
do
 mv "$line" "overlay"
done

# extract progress indicators
mkdir "progress"
for line in `find . -maxdepth 1 -regextype posix-extended -regex "^.*_(prgss|progress)_.*.svg"`;
do
 mv "$line" "progress"
done

# extract view images
mkdir "views"
for line in `find . -maxdepth 1 -regextype posix-extended -regex "^.*_e?view(16)?_.*.svg"`;
do
 mv "$line" "views"
done

# ... and all the rest
declare -a arr=("obj16" "elcl16" "clcl16" "etool16" "ctool16" "obj")
mkdir "images"
for token in "${arr[@]}"
do
 for line in `find . -maxdepth 1 -iname "*_${token}_*.svg"`;
 do
  mv "$line" "images"
 done
done

cd ..