Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function parse_yaml {
  4. local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
  5. sed -ne "s|^\($s\):|\1|" \
  6. -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
  7. -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $@ |
  8. awk -F$fs '{
  9. indent = length($1)/2;
  10. vname[indent] = $2;
  11. for (i in vname) {if (i > indent) {delete vname[i]}}
  12. if (length($3) > 0) {
  13. vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
  14. printf("%s%s:%s\n", vn, $2, $3);
  15. }
  16. }'
  17. }
  18.  
  19. function generate_replacement {
  20. awk -F: '{
  21. VAL[$1] = $2;
  22. }
  23. END {
  24. for (key in VAL) {
  25. printf "-e '\''s/\\\$%s\\\$/%s/'\'' ", key, VAL[key];
  26. }
  27. }' $@
  28. }
  29.  
  30. params=$(parse_yaml <<EOF
  31. color:
  32. bg: #424F60
  33. line: #CED6DE
  34. dark: #28343F
  35. light: #60748B
  36. note:
  37. bg: #FBFCA8
  38. line: #BBBC88
  39. font:
  40. main: DejaVu Serif
  41. note: DejaVu Serif
  42. EOF
  43.  
  44. <<EOF
  45. color:
  46. bg: #111111
  47. EOF)
  48.  
  49. replacement_params=$(generate_replacement <(echo "$params"))
  50. eval "find ./ -type f -name uml.skin -exec sed -i '' $replacement_params {} \;"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement