Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Related, one of my favorite in-depth stack overflow answers: https://stackoverflow.com/a/33206814


Here's a useful one-liner to print the code for each of the 256 colors in their respective color, so that you can quickly see which one you want:

    for i in {0..255}; do  printf "\x1b[38;5;${i}mcolor%-5i\x1b[0m" $i ; if ! (( ($i + 1 ) % 8 )); then echo ; fi ; done


If we're doing one-liners, there are several advantages to:

    for i in {0..255}; do printf '\e[48;5;%dm%-10s' "$i" "color$i"; if (( (i >= 16 && i < 232) ? (i%6 == 3) : (i%8 == 7) )); then printf '\e[m\n'; fi; done
There are several more-complete versions floating around on the internet; I have personalized 2 myself ... hmm, I don't seem to have the one I remember that does contrast automatically ...


You can make any program in a ; language a one liner.


Well sure, but I think everyone would understand a one liner as something that fits in a single loop.

And you know that. Why are you arguing about this?




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

Search: