Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Graphic with escape codes for 256-color terminals (for colorful shell prompts) (imgur.com)
2 points by timoteostewart on April 10, 2022 | hide | past | favorite | 2 comments


The graphic is a screenshot of the output of the script below. If you run this script in a terminal, then you can copy the escape sequence you want to use and paste it wherever needed.

    #!/bin/bash

    for fgbg in 38 48 ; do
        for color in {0..255} ; do
            if (( $color < 256 )) ; then
                padding=""
            fi
            if (( $color < 100 )) ; then
                padding=" "
            fi
            if (( $color < 10 )) ; then
                padding="  "
            fi
            
            printf "\e[${fgbg};5;%sm  \\\\e[${fgbg};5;%sm${padding}  \e[0m" $color $color
            
            if [ $((($color + 1) % 6)) == 4 ] ; then
                echo ""
            fi
        done
        echo ""
    done

    exit 0


This works like a charm. Thank you for sharing it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: