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

ffoo.sh.in 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. FFOO_DATA_DIR=${FFOO_DATA_DIR:-$HOME/.ffoo}
  3. FFOO_DIR=${FFOO_DIR:-__FFOO_DIR__}
  4. FFOO_ARTIFACTS_DIR=${FFOO_ARTIFACTS_DIR:-artifacts}
  5. FFOO_DEBUG=${FFOO_DEBUG:-false}
  6. FFOO_DEBUGINIT=${FFOO_DEBUGINIT:-false}
  7. FFOO_INCLUDE=${FFOO_INCLUDE:-$FFOO_DIR/include}
  8. FFOO_MKPRETTY=${FFOO_MKPRETTY:-plain}
  9. FFOO_VERBOSE=${FFOO_VERBOSE:-false}
  10. FFOO_VERSION=__VERSION__
  11. ffoo() {
  12. case $1 in
  13. __debug)
  14. $FFOO_DEBUGINIT || return 0
  15. shift
  16. echo "debug: $@" >&2
  17. ;;
  18. __die)
  19. shift
  20. echo "$@" >&2
  21. exit 1
  22. ;;
  23. doc)
  24. ffoo __die "not implemented (sorry...)"
  25. ;;
  26. import)
  27. ffoo __debug "importing module $2"
  28. local mfile=$(ffoo _list_mfiles_like $2 | head -1)
  29. test -n "$mfile" || ffoo __die "cannot find module $2"
  30. ffoo __debug "found module file: $mfile"
  31. . $mfile
  32. return $?
  33. ;;
  34. _list_all_functions)
  35. local mfile
  36. ffoo _list_all_mfiles | while read mfile;
  37. do
  38. ffoo _list_functions_in_mfile "$mfile"
  39. done
  40. ;;
  41. _list_all_modules)
  42. local mp mfn;
  43. ffoo _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 $FFOO_INCLUDE/*.sh | tr ' ' '\n'
  52. test -n "$FFOO_PATH" && echo $FFOO_PATH/*.sh
  53. } | tr ' ' '\n'
  54. ;;
  55. _list_mfiles_like)
  56. test -f "$FFOO_INCLUDE/$2.sh" && echo "$FFOO_INCLUDE/$2.sh"
  57. test -n "$FFOO_PATH" -a -f "$FFOO_PATH/$2.sh" && echo "$FFOO_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. ffoo __die "unknown ffoo command: $1"
  66. ;;
  67. esac
  68. }
  69. ffoo __debug "FFOO_DATA_DIR='$FFOO_DATA_DIR'"
  70. ffoo __debug "FFOO_DIR='$FFOO_DIR'"
  71. ffoo __debug "FFOO_ARTIFACTS_DIR='$FFOO_ARTIFACTS_DIR'"
  72. ffoo __debug "FFOO_DEBUG='$FFOO_DEBUG'"
  73. ffoo __debug "FFOO_DEBUGINIT='$FFOO_DEBUGINIT'"
  74. ffoo __debug "FFOO_INCLUDE='$FFOO_INCLUDE'"
  75. ffoo __debug "FFOO_INIPATH='$FFOO_INIPATH'"
  76. ffoo __debug "FFOO_MKPRETTY='$FFOO_MKPRETTY'"
  77. ffoo __debug "FFOO_VERBOSE='$FFOO_VERBOSE'"
  78. ffoo __debug "FFOO_VERSION='$FFOO_VERSION'"