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

ffoo.3.sh 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/bash
  2. # ~/bin/example
  3. . <(ffoom init)
  4. ffoo import core
  5. #
  6. # basic echo helpers
  7. #
  8. think "about saying something..." # thinks loud if FFOO_VERBOSE
  9. warn "this is just an example" # obvious :)
  10. false || die "false was true!" # Perlism :)
  11. x=1; y=2; z=3
  12. debug "x='$x'" "y='$y'" "z='$z'" # debug:example: x='1'
  13. # debug:example: y='2'
  14. # debug:example: z='3'
  15. debug -v x y z # << short for ^
  16. echo "hello" | debug_pipe mypipe # debug|mypipe|: hello
  17. warn -f should_be_empty # warns with name+content
  18. # unless the file is empty
  19. myfun() {
  20. num=42
  21. debug -v num
  22. }
  23. myfun # debug:myfun: num='42'
  24. #
  25. # more advanced functions
  26. #
  27. mkdir $HOME/.cfg
  28. cat >$HOME/.cfg/foo.ini <<EOF
  29. # a sample ini file
  30. [foo]
  31. multiline = also possible
  32. multiline = like this :)
  33. [foo.bar]
  34. baz = qux
  35. baz2 = public qux
  36. [py]
  37. s1 =#!/usr/bin/python
  38. s1 =def main():
  39. s1 = print "will work!"
  40. EOF
  41. ffoo import ini
  42. FFOO_INI_PATH=$HOME/.cfg
  43. iniread -s foo.bar -k baz foo.ini # prints "qux"
  44. iniread -p foo.bar.baz foo.ini # ...short for above
  45. iniread -p foo.bar.baz # ...even shorter
  46. iniread -S -p py.s1 > s1.py foo.ini # the -S will preserve spaces on RHS so
  47. python s1.py # << will work
  48. #
  49. # including runtime ini merging
  50. #
  51. mkdir $HOME/.cfg/private
  52. cat >$HOME/.cfg/private/foo.ini <<EOF
  53. # private extension to above
  54. [foo.bar]
  55. baz2 = secret qux!
  56. # this approach can make it easier
  57. # to sync private info separately
  58. EOF
  59. FFOO_INI_PATH=$HOME/.cfg:$HOME/.cfg-private
  60. iniread -p foo.bar.baz2 # merges both paths -- prints 2 lines
  61. iniread -1 -p foo.bar.baz2 # ... last one wins -- prints "secret..."
  62. iniread -S foo.ini # merges both files verbatim
  63. #
  64. # even more
  65. #
  66. ffoo import flow
  67. wait_until -e ! test -e badfile # -e means use eval (make "!" work)
  68. think "the badfile is away..."
  69. bad_file_away() { # but you can avoid eval
  70. ! test -f badfile
  71. }
  72. wait_until bad_file_away
  73. #
  74. # ... and more
  75. #
  76. ffoo import testing
  77. register_artifact future.log # does not need to exist yet
  78. myprog > future.log
  79. collect_artifacts # will preserve tree from /
  80. # and produce folder called e.g.
  81. # artifacts-20140915-141502
  82. #
  83. # ...AND MORE!
  84. #
  85. ffoo import sw
  86. cat > deps.ini <<EOF
  87. [needs.now]
  88. yum = ronn
  89. yum = vim
  90. pypi = docopt
  91. [needs.for_test]
  92. cpan = Test::More
  93. # yeah I made that up
  94. EOF
  95. iniread -s needs.now ./deps.ini | any_install
  96. iniread -s needs.for_test ./deps.ini | any_install