shell dot on steroids https://pagure.io/shellfu

ffood.sh.in 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. FFOOD_DATA_DIR=${FFOOD_DATA_DIR:-$HOME/.ffood}
  3. FFOOD_DIR=${FFOOD_DIR:-__FFOOD_DIR__}
  4. FFOOD_ARTIFACTS_DIR=${FFOOD_ARTIFACTS_DIR:-artifacts}
  5. FFOOD_DEBUG=${FFOOD_DEBUG:-false}
  6. FFOOD_DEBUGINIT=${FFOOD_DEBUGINIT:-false}
  7. FFOOD_INCLUDE=${FFOOD_INCLUDE:-$FFOOD_DIR/include}
  8. FFOOD_MKPRETTY=${FFOOD_MKPRETTY:-plain}
  9. FFOOD_VERBOSE=${FFOOD_VERBOSE:-false}
  10. FFOOD_VERSION=__VERSION__
  11. ffood() {
  12. case $1 in
  13. __debug)
  14. $FFOOD_DEBUGINIT || return 0
  15. shift
  16. echo "debug: $@" >&2
  17. ;;
  18. __die)
  19. shift
  20. echo "$@" >&2
  21. exit 1
  22. ;;
  23. doc)
  24. ffood __die "not implemented (sorry...)"
  25. ;;
  26. import)
  27. ffood __debug "importing module $2"
  28. local mfile=$(ffood _list_mfiles_like $2 | head -1)
  29. test -n "$mfile" || ffood __die "cannot find module $2"
  30. ffood __debug "found module file: $mfile"
  31. . $mfile
  32. return $?
  33. ;;
  34. _list_all_functions)
  35. local mfile
  36. ffood _list_all_mfiles | while read mfile;
  37. do
  38. ffood _list_functions_in_mfile "$mfile"
  39. done
  40. ;;
  41. _list_all_modules)
  42. local mp mfn;
  43. ffood _list_all_mfiles | while read mp;
  44. do
  45. mfn="${mp##*/}"
  46. echo "${mfn%%.sh}"
  47. done
  48. ;;
  49. _list_all_mfiles)
  50. {
  51. echo $FFOOD_INCLUDE/*.sh | tr ' ' '\n'
  52. test -n "$FFOOD_PATH" && echo $FFOOD_PATH/*.sh
  53. } | tr ' ' '\n'
  54. ;;
  55. _list_mfiles_like)
  56. test -f "$FFOOD_INCLUDE/$2.sh" && echo "$FFOOD_INCLUDE/$2.sh"
  57. test -n "$FFOOD_PATH" -a -f "$FFOOD_PATH/$2.sh" && echo "$FFOOD_PATH/$2.sh"
  58. ;;
  59. _list_functions_in_mfile)
  60. local mfile="$2"
  61. grep -HE '^[[:alnum:]_]+\(\) \{' "$mfile" \
  62. | sed -e 's/^.*\///; s/\.sh:/./; s/(.*//'
  63. ;;
  64. *)
  65. ffood __die "unknown ffood command: $1"
  66. ;;
  67. esac
  68. }
  69. ffood __debug "FFOOD_DATA_DIR='$FFOOD_DATA_DIR'"
  70. ffood __debug "FFOOD_DIR='$FFOOD_DIR'"
  71. ffood __debug "FFOOD_ARTIFACTS_DIR='$FFOOD_ARTIFACTS_DIR'"
  72. ffood __debug "FFOOD_DEBUG='$FFOOD_DEBUG'"
  73. ffood __debug "FFOOD_DEBUGINIT='$FFOOD_DEBUGINIT'"
  74. ffood __debug "FFOOD_INCLUDE='$FFOOD_INCLUDE'"
  75. ffood __debug "FFOOD_INIPATH='$FFOOD_INIPATH'"
  76. ffood __debug "FFOOD_MKPRETTY='$FFOOD_MKPRETTY'"
  77. ffood __debug "FFOOD_VERBOSE='$FFOOD_VERBOSE'"
  78. ffood __debug "FFOOD_VERSION='$FFOOD_VERSION'"