Skip to content

Instantly share code, notes, and snippets.

@DC-Shi
Forked from yonchu/color256.sh
Last active February 7, 2018 04:11
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 DC-Shi/3205d91f3fdb9a5960c21e8434f10054 to your computer and use it in GitHub Desktop.
Save DC-Shi/3205d91f3fdb9a5960c21e8434f10054 to your computer and use it in GitHub Desktop.
zsh/bashで256色のカラーパレットを表示
#!/bin/sh
#
# 256色のカラーパレットを表示する
# bash と zsh にて実行可能
#
# dc-shi: 更改了颜色表达方式,第一行为标准16色,
# 之后6*6*6的彩色
# 最后是24阶灰度
# 暂时未对zsh做更改
target_shell=$1
if [ -z "$1" ]; then
target_shell=$(basename "$SHELL")
fi
if [ "$target_shell" = "bash" ]; then
# 0~15 为一行
# 16~231 每六个一行
# 232~255 为一行
# 使用16进制
bash <<< 'for code in {0..255}; do echo -n "[38;05;${code}m $(printf %02X $code)"; [ ${code} -eq 15 ] && echo; [ ${code} -eq 231 ] && echo; [ $((${code} % 6)) -eq 3 -a ${code} -gt 15 -a ${code} -lt 231 ] && echo; done'
elif [ "$target_shell" = "zsh" ]; then
zsh <<< 'for code in {000..255}; do print -nP -- "%F{$code}$code %f"; [ $((${code} % 16)) -eq 15 ] && echo; done'
else
echo "error: Invalid argument ($target)"
echo "Usage: $0 [bash|zsh]"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment