gd-slide.fish 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/fish
  2. set SLIDE_NUM $argv[1]
  3. set SLIDE_NAME $argv[2]
  4. set SLIDE_TITLE $argv[3]
  5. set SLIDE_NAME_MARK 'TEMPLATE_NAME'
  6. set SLIDE_TITLE_MARK 'TEMPLATE_TITLE'
  7. set SLIDES_PATH "../godot/slides"
  8. set TEMPLATE_FOLDER "$SLIDES_PATH/template"
  9. set TEMPLATE_FILE "$TEMPLATE_FOLDER/$SLIDE_NAME_MARK.tscn"
  10. set SLIDE_FOLDER "$SLIDES_PATH/$SLIDE_NUM"
  11. set SLIDE_FILE "$SLIDE_FOLDER/$SLIDE_NAME.tscn"
  12. function gen-res-id
  13. echo (head -n 10 /dev/urandom | tr -dc 'a-z' | string shorten -m $argv[1] --char="")
  14. end
  15. set IDS_MARK 'aaaaa' 'bbbbb' 'ccccc' 'uuuuuuuuuuuuu'
  16. echo "Read $TEMPLATE_FILE"
  17. set CONTENT (cat $TEMPLATE_FILE)
  18. function get-content
  19. printf %s\n $CONTENT
  20. end
  21. echo "Rename template : $SLIDE_NAME_MARK -> $SLIDE_NAME"
  22. set CONTENT (get-content | sed -e "s/$SLIDE_NAME_MARK/$SLIDE_NAME/")
  23. echo "Set title : $SLIDE_TITLE_MARK -> $SLIDE_TITLE"
  24. set CONTENT (get-content | sed -e "s/$SLIDE_TITLE_MARK/$SLIDE_TITLE/")
  25. echo "Replace marks"
  26. for k in (seq (count $IDS_MARK))
  27. set NEW_ID (gen-res-id (string length $IDS_MARK[$k]))
  28. echo $k ':' $IDS_MARK[$k] '->' $NEW_ID
  29. set CONTENT (get-content | sed -e "s/$IDS_MARK[$k]/$NEW_ID/")
  30. end
  31. echo "Write to : $SLIDE_FILE"
  32. mkdir --parents $SLIDE_FOLDER
  33. get-content > $SLIDE_FILE