colour-text-echo.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. # Klimbim Software collection, A bag full of things
  3. # Copyright (C) 2011-2023 Johannes 'Banana' Keßler
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. # 2013 http://www.bananas-playground.net
  18. # this function prints the given string in the given colour in a bash shell
  19. # either include this function directly into your script or source it as an
  20. # external file.
  21. #
  22. # usage example:
  23. # cecho "this is green" green; # prints the string in green
  24. #
  25. cecho () {
  26. local red='\033[0;31m'
  27. local blue='\033[0;34m'
  28. local green='\033[0;32m'
  29. local cyan='\033[0;36m'
  30. local purple='\033[0;35m'
  31. local brown='\033[0;33m'
  32. local yellow='\033[1;33m'
  33. local white='\033[1;37m'
  34. local black='\033[0;30m'
  35. local message=$1
  36. local color=${!2-$white}
  37. echo -en "$color"
  38. echo "$message"
  39. echo -en "\033[0m" # reset color
  40. return
  41. }