Created
October 8, 2019 01:21
-
-
Save Summertime/6dae32a1aa8298d8878f420f7322ae6f to your computer and use it in GitHub Desktop.
Detect color resolution of the terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
detect_color_resolution() { | |
# 24bit | |
if [ "$COLORTERM" = "truecolor" ] | |
then | |
printf '%s\n' 24 | |
return | |
elif [ "$COLORTERM" = "24bit" ] | |
then | |
printf '%s\n' 24 | |
return | |
fi | |
# 8bit | |
case $TERM in | |
*-256color) | |
printf '%s\n' 8 | |
return | |
;; | |
esac | |
# lets ask tput, bleh! | |
local TPUTCOL=$(tput colors) | |
case $TPUTCOL in | |
256) | |
printf '%s\n' 8 | |
return | |
;; | |
8) | |
printf '%s\n' 3 | |
return | |
;; | |
*) | |
printf '%s\n' 0 | |
return | |
;; | |
esac | |
} | |
printf '%s\n' $(detect_color_resolution) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment