Skip to content

Instantly share code, notes, and snippets.

@gwpl
Created November 11, 2018 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwpl/0b0e6c3363d8ef97939d3d5b04cd5541 to your computer and use it in GitHub Desktop.
Save gwpl/0b0e6c3363d8ef97939d3d5b04cd5541 to your computer and use it in GitHub Desktop.
bash coloring handy functions
# source: https://stackoverflow.com/a/20910449/544721
norm="$(printf '\033[0m')" #returns to "normal"
bold="$(printf '\033[0;1m')" #set bold
red="$(printf '\033[0;31m')" #set red
boldred="$(printf '\033[0;1;31m')" #set bold, and set red.
somecommand | sed -e "s/someregexp/${boldred}&${norm}/g" # will color any occurence of someregexp in Bold red
printf "%s" "$red" ; locate something ; printf "%s" "$norm" # will color output of locate something in red
#I (ab)use printf "%s" "something", as it's more portable than echo,and easy to modify
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment