Bash で、エスケープシーケンスで使える色を調べる方法

Bash Escape Sequence Color

以下のスクリプトを作成して実行。

vi color.sh
chmod +x color.sh
./color.sh
#!/bin/bash

export txtrst='\x1b[00m'      # Reset

echo
for i in {0..255} ; do
  printf "\x1b[00;${i}m ${i}${txtrst}"
done
echo

echo
for i in {0..255} ; do
  printf "\x1b[38;05;%03dm 38;05;%03d " ${i} ${i}
  if [ $(( ${i} % 8 )) -eq 7 ] ; then
    echo
  fi
done
echo

ここで色の一覧が出てくるので、以下のように数字を指定して使用する。

export txt1='\[\033[38;05;105m\]' # Purple Dark
export txt2='\[\033[38;05;75m\]'  # Cyan Dark
export txt3='\[\033[38;05;98m\]'  # Purple Dark
export txt4='\[\033[00;38m\]'     # White

export txtrst='\[\033[00m\]'      # Reset

# Purple
PS1="${txt1}[${txt2}\$(date +%m/%d) \$(date +%H:%M)${txt1}][${txt3}\u${txt1}@${txt3}\h${txt1}:${txt4}\w${txt1}]${txt4}\$ ${txtrst}"