utils.sh 451 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env bash
  2. # All common functions can be added to this file
  3. exists() { type -t "$1" > /dev/null 2>&1; }
  4. is_gnu_sed () {
  5. sed --version >/dev/null 2>&1
  6. }
  7. replace () {
  8. echo "${1}"
  9. if is_gnu_sed; then
  10. sed -i -E "${1}" "${2}"
  11. else
  12. sed -i '' -E "${1}" "${2}"
  13. fi
  14. }
  15. if ! exists gsed; then
  16. if is_gnu_sed; then
  17. function gsed() {
  18. sed -i -E "$@"
  19. }
  20. else
  21. function gsed() {
  22. sed -i '' -E "$@"
  23. }
  24. fi
  25. fi