Skip to content

Instantly share code, notes, and snippets.

@HotoRas
Created June 29, 2024 07:36
Show Gist options
  • Save HotoRas/84080ad2902905d0c96128f45557be25 to your computer and use it in GitHub Desktop.
Save HotoRas/84080ad2902905d0c96128f45557be25 to your computer and use it in GitHub Desktop.
colorgrid
# Source: https://unix.stackexchange.com/questions/124407/what-color-codes-can-i-use-in-my-bash-ps1-prompt/124409#124409
function colorgrid( )
{
iter=16
while [ $iter -lt 52 ]
do
second=$[$iter+36]
third=$[$second+36]
four=$[$third+36]
five=$[$four+36]
six=$[$five+36]
seven=$[$six+36]
if [ $seven -gt 250 ];then seven=$[$seven-251]; fi
echo -en "\033[38;5;$(echo $iter)m█ "
printf "%03d" $iter
echo -en " \033[38;5;$(echo $second)m█ "
printf "%03d" $second
echo -en " \033[38;5;$(echo $third)m█ "
printf "%03d" $third
echo -en " \033[38;5;$(echo $four)m█ "
printf "%03d" $four
echo -en " \033[38;5;$(echo $five)m█ "
printf "%03d" $five
echo -en " \033[38;5;$(echo $six)m█ "
printf "%03d" $six
echo -en " \033[38;5;$(echo $seven)m█ "
printf "%03d" $seven
iter=$[$iter+1]
printf '\r\n'
done
}

Colorgrid

Source from https://unix.stackexchange.com/questions/124407/what-color-codes-can-i-use-in-my-bash-ps1-prompt/124409#124409

How to use

One-Time

  1. You can just paste the whole function into your shell and enter,
  2. and just run colorgrid

Save

  1. Save to where you prefer (like ~/.colorgrid),

  2. append to your shell init file like ~/.bash_aliases:

    if [ -f ~/.colorgrid ]; then
        . ~/.colorgrid
    fi
  3. and then source the file and run

You don't have to append on every shell you use, if you source the same alias file (like ~/.bash_aliases being sourced by ~/.bashrc by default) on each shell init file.

For example, I appended ~/.bash_aliases on ~/.zsh_aliases so that I can use same aliases and user-defined functions in both terminal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment