Ever burned a cake?
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

71 行
1.6KB

  1. #!/bin/bash
  2. # Originally written by anon, modified
  3. BLUE='\033[34m'
  4. GREEN='\033[32m'
  5. BOLD='\033[1m'
  6. NORMAL='\033[0m'
  7. MARKNAME="@BAKE"
  8. MARK="${MARKNAME} "
  9. MARKSTR="${BLUE}${MARKNAME}${NORMAL}"
  10. enable -n echo
  11. usage() {
  12. IFSTR="${GREEN}<input_file>${NORMAL}"
  13. echo -e "${BOLD}Usage: $0 <input_file>${NORMAL}" >&2
  14. echo -e "\t$0 runs the value of ${MARKSTR}." >&2
  15. echo -e "\tThe point of this script is ease to compialation of single source file (toy) programs." >&2
  16. echo -e "\tThe value of ${MARKSTR} is read from ${IFSTR} in is whatever comes after '${MARK}' until the end of the line." >&2
  17. echo -e "\tInside the value of ${MARKSTR} all mentions of special placeholders are replaced:" >&2
  18. echo -e "\t\t${BLUE}\$@${NORMAL} - ${IFSTR}"
  19. echo -e "\t\t${BLUE}\$*${NORMAL} - ${IFSTR} with the last extension cut off"
  20. echo -e "\t\t${BLUE}\$+${NORMAL} - All remaining arguments"
  21. }
  22. if [[ $# -lt 1 ]]; then
  23. usage
  24. exit 1
  25. fi
  26. if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
  27. usage
  28. exit 0
  29. fi
  30. run=1
  31. if [[ $1 == "-n" ]] || [[ $1 == "--dry-run" ]]; then
  32. if [[ $# -lt 2 ]]; then
  33. usage
  34. exit 1
  35. fi
  36. run=0
  37. shift 1
  38. fi
  39. input_file=$1
  40. shift 1
  41. if [[ ! -f $input_file ]]; then
  42. echo -e "Input file '$input_file' does not exist." >&2
  43. exit 1
  44. fi
  45. line=$(grep "$MARK" "$input_file" | head -1)
  46. line=${line//\$@/$input_file}
  47. line=${line//\$\*/${input_file%.*}}
  48. line=${line//\$+/$@}
  49. if [[ -n $line ]]; then
  50. command="${line#*${MARK}}"
  51. echo "Exec: $command"
  52. if [[ $run -eq 1 ]]; then
  53. echo "Output:"
  54. $command
  55. fi
  56. else
  57. echo -e "${MARKSTR} is not defined." >&2
  58. fi