-3

I use oh-my-zsh and after updates it show the great looking logo: enter image description here

I created simple script and ask stackoverflow users explain me how to achive colored output of the logo?

#!/bin/bash

logo(){
  #can't have a bash script without a cool logo :D
  echo '
  _
 | | __ _ ____ _   _ _ __ ___  ___  ___  _ __
 | |/ _  |_  /| | | |  __/ _ \/ __|/ _ \|  _ \
 | | (_|  / / | | | | | |  __/ (__  (_) | | | |
 |_|\__ _|___/ \__  |_|  \___|\___|\___/|_| |_|
               |___/
'
}

main(){
  logo
}
main $1
storenth
  • 967
  • 11
  • 18
  • 1
    What have you searched for, and what did you find? What have you tried, and how did it fail? – tripleee Jul 28 '20 at 12:50
  • As an aside, you want `main "$@"` or possibly `main "$1"`; see also [When to wrap quotes around a shell variable?](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable) – tripleee Jul 28 '20 at 12:52
  • 2
    Stack Overflow is for questions about **developing software**. Questions about customizing your environment in ways not specific to software development are off-topic here, and belong on [unix.se] instead. – Charles Duffy Jul 28 '20 at 13:05
  • This is software about, not env setup. – storenth Jul 29 '20 at 03:23

1 Answers1

2

Take a look at the source of the oh-my-zsh upgrade script:

https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/upgrade.sh

This part of the script is responsible for showing the logo:

  printf '%s         %s__      %s           %s        %s       %s     %s__   %s\n' $RB_RED $RB_ORANGE $RB_YELLOW $RB_GREEN $RB_BLUE $RB_INDIGO $RB_VIOLET $RB_RESET
  printf '%s  ____  %s/ /_    %s ____ ___  %s__  __  %s ____  %s_____%s/ /_  %s\n' $RB_RED $RB_ORANGE $RB_YELLOW $RB_GREEN $RB_BLUE $RB_INDIGO $RB_VIOLET $RB_RESET
  printf '%s / __ \%s/ __ \  %s / __ `__ \%s/ / / / %s /_  / %s/ ___/%s __ \ %s\n' $RB_RED $RB_ORANGE $RB_YELLOW $RB_GREEN $RB_BLUE $RB_INDIGO $RB_VIOLET $RB_RESET
  printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s   / /_%s(__  )%s / / / %s\n' $RB_RED $RB_ORANGE $RB_YELLOW $RB_GREEN $RB_BLUE $RB_INDIGO $RB_VIOLET $RB_RESET
  printf '%s\____/%s_/ /_/ %s /_/ /_/ /_/%s\__, / %s   /___/%s____/%s_/ /_/  %s\n' $RB_RED $RB_ORANGE $RB_YELLOW $RB_GREEN $RB_BLUE $RB_INDIGO $RB_VIOLET $RB_RESET
  printf '%s    %s        %s           %s /____/ %s       %s     %s          %s\n' $RB_RED $RB_ORANGE $RB_YELLOW $RB_GREEN $RB_BLUE $RB_INDIGO $RB_VIOLET $RB_RESET

You have to insert color escape sequences before each segment of your logo that requires a different color. The escape sequences are defined as follows:

  RB_RED=$(printf '\033[38;5;196m')
  RB_ORANGE=$(printf '\033[38;5;202m')
  RB_YELLOW=$(printf '\033[38;5;226m')
  RB_GREEN=$(printf '\033[38;5;082m')
  RB_BLUE=$(printf '\033[38;5;021m')
  RB_INDIGO=$(printf '\033[38;5;093m')
  RB_VIOLET=$(printf '\033[38;5;163m')

See the script source for more info.

tomptz
  • 71
  • 5
  • It would be better to use `tput setaf` or `tput setab` (for background color) instead of just `printf` and the escape sequence. Take a look at https://gist.github.com/dtmilano/4055d6df5b6e4ea87c5a72dc2d604193. – Diego Torres Milano Jul 28 '20 at 17:17