ターミナルが256色使えるかどうか確認するbashスクリプトを作った

  • 24
    いいね
  • 0
    コメント
この記事は最終更新日から1年以上が経過しています。

この記事は 真夏の夜の淫夢 Advent Calendar 2014 114514日目の記事です

概要

ターミナルさん!?が256色使えるかパパパッと確認して、おわりっ!って出来たらべんり... べんりじゃない?

実行例

成功

失敗

ソースコード

Gist

NAXTU.sh
#!/bin/bash
#
#   @(#) ターミナルが256色使えるかどうか確認するスクリプトです
#
#   Author:
#       844196 (@84____)
#
#   License:
#       WTFPL 2.0
#


Y="\033[48;5;236m  \033[m"
J="\033[48;5;137m  \033[m"
U="\033[48;5;180m  \033[m"

function _CursorInvisible() {
    trap "clear; tput cnorm;" EXIT
    trap "clear; tput cnorm; exit 1" SIGINT
    tput sc; tput cup 0 0; tput civis
}

function _Sleep() {
    local t="${@}"
    if $(which sleepenh >/dev/null 2>&1); then
        local sleep='sleepenh'
    else
        local sleep='sleep'
    fi
    ${sleep} ${t} >/dev/null
}

function _MarginHeight() {
    local height=$(tput lines)
    local m=$(expr ${height} - ${1})
    for i in $(seq 1 ${m}); do
        echo " "
    done
}

function NAXTU() {
_MarginHeight 31;
local NAXTU="
                                    $Y$Y$Y$Y$Y$Y$Y
                                $J$J$U$U$Y$Y$Y$Y$Y$Y
                            $J$J$U$U$U$U$U$U$Y$Y$Y$Y$Y
                          $J$U$Y$Y$U$U$U$U$U$U$U$Y$Y$Y$Y
                        $J$U$U$U$Y$Y$U$U$U$U$U$U$U$Y$Y$Y$Y
                      $J$U$U$Y$Y$U$Y$Y$U$U$U$U$U$U$U$Y$Y$Y$Y
                  $J$J$U$U$U$U$U$Y$Y$Y$U$U$U$U$U$U$U$J$Y$Y$Y
                $J$J$U$U$U$U$U$U$U$U$U$Y$Y$Y$U$U$U$U$J$Y$Y$Y$Y
              $J$J$U$U$U$J$J$J$J$J$U$Y$Y$Y$Y$Y$U$U$J$U$J$Y$Y$Y
            $J$J$U$U$U$U$J$Y$J$U$U$U$U$Y$U$U$U$Y$U$U$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J$U$U$U$U$U$U$U$J$J$J$Y$Y
$U$U$U$U$U$U$J$U$U$U$U$U$U$U$U$U$J
$U$U$U$U$U$U$U$U$U$U$U$U$U$U$U$J
$U$U$U$U$U$U$U$U$U$U$U$U$U$U$J
$U$U$U$U$U$U$U$U$U$U$U$U$J$J$J$J"
echo -en "${NAXTU}"
}

_CursorInvisible; clear;
while :; do NAXTU; _Sleep 11.4514; clear; done

別解

#!/bin/bash
#
#   License:
#       どうとでも勝手にしやがれクソッタレ公衆利用許諾書 2.0
#


P_Y="236m"
P_J="137m"
P_U="180m"
P_N="m"
P_A="m\n"

NAXTU="NNNNNNNNNNNNNNNNNNYYYYYYYANNNNNNNNNNNNNNNNJJUUYYYYYYANNNNNNNNNNNNNNJJUUUUUUYYYYYANNNNNNNNNNNNNJUYYUUUUUUUYYYYANNNNNNNNNNNNJUUUYYUUUUUUUYYYYANNNNNNNNNNNJUUYYUYYUUUUUUUYYYYANNNNNNNNNJJUUUUUYYYUUUUUUUJYYYANNNNNNNNJJUUUUUUUUUYYYUUUUJYYYYANNNNNNNJJUUUJJJJJUYYYYYUUJUJYYYANNNNNNJJUUUUJYJUUUUYUUUYUUJJYYYYANNNNNNJUUUJJUUYJJUUUUUUUUJUJJYYYANNNNNJUUUJJJJUJJJUUUUUUUJUJJJYYYANNNNNJUUJUUUJUUJUUUUUUUUUJJYYYYYNANNNNJUUJYYYUUJUJUUUUUUUUJJYYYYYYANNNNJUJYYYYYUJUJUUUUUUUJJYYYYYYYNANNNJUUJYYYYYYJUUUUUUUUUJJYYYYYYYNANNNJUUJUYYYYJUUUUUUUUUUJYYYYYYYANNJJUUJJUYYJUUUUUUUUUUUJYYYYYYJANNJJJUUJJJJUUUUUUUUUUJUYYYYYYYJNANNJJJUUUUUUUUUUUUUUUUUYUYYYYYJNANNJJJJUUUUUUUUUUUUUUUUUUUUUUYJNANJJJJJJJUUUUUUUUUUUUUUUUJJUUJAJJJJJJJJJJJJJJUUUUUUUUUJJUUJNAJUJUJJJJJJJJJJJJJJUUUJUUUUJNAUJUJUJUJJJJJJJUUUUUUUJJUJJNAJUJUJUJUJUJUUUUUUUUUUYYJAUUUJUJUJUJUUUUUUUJJJYYAUUUUUUJUUUUUUUUUJAUUUUUUUUUUUUUUUJAUUUUUUUUUUUUUUJAUUUUUUUUUUUUJJJJN"


for i in {0..893}
do
    echo -en "\033[48;5;$(eval 'echo $P_'${NAXTU:$i:1})  "
done
echo