Skip to content

Instantly share code, notes, and snippets.

@geermc4
Last active December 19, 2015 06:58
Show Gist options
  • Save geermc4/5914720 to your computer and use it in GitHub Desktop.
Save geermc4/5914720 to your computer and use it in GitHub Desktop.
Organize spree decorators in to paths based on virtual_path
export IFS=$'\n'
files=`find . -maxdepth 1 -type f`
for f in $files ; do
extra_crap=`grep -vh "^Deface" $f | grep -v " *:" | grep -v "^)" | sed '/^$/d'`
if [[ "$extra_crap" == "" ]]; then
overrides=`tr '\n' ' ' < $f | sed 's/Deface/\nDeface/g'`
for o in $overrides ; do
new_override=`echo $o | sed 's/\t/ /g;s/ \{1,\}/ /g;s/:\([a-z]\)/\n:\1/g'`
echo $new_override | sed 's/:\([a-z]\)/\n:\1/g' > tmp_file
sed -i'' 's/^ \{1,\}//g;s/ \{1,\}$//g;s/^:/ :/g' tmp_file
name=`grep -E ":name {1,}=>" tmp_file | sed "s/.*=>//g;s/[ ,\"']//g"`.rb
path=$(dirname `grep -E ":virtual_path {1,}=>" tmp_file | sed "s/.*=>//g;s/[ ,\"']//g"`)
if [[ ! -d $path ]]; then
mkdir -p $path
fi
if [[ "$path/$name" != $f ]]; then
mv tmp_file $path/$name
fi
git add $path/$name
if [[ $? != 0 ]]; then
break
fi
done
git rm $f
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment