ユーザーに読みやすい出力を提供できる組み込み(bash/gentoo)機能はありますか?

ユーザーに読みやすい出力を提供できる組み込み(bash/gentoo)機能はありますか?

私はユーザーに読みやすい出力を提供するために、次の簡単な関数を使用しています。今、私はこれを行うためのいくつかの(gentoo-/bash-)組み込み関数があるかどうか疑問に思います。これは、車輪を「再創造」するように感じられるからです。よろしくお願いします。

function log
{
        red='\033[0;31m'
        green='\033[0;32m'
        yellow='\033[1;33m'
        term='\033[0m'

        if [ "$1" == "INFO" ]; then
                echo -e "${green}[i] $2 ${term}"
        elif [ "$1" == "WARN" ]; then
                echo -e "${yellow}[w] $2 ${term}"
        elif [ "$1" == "ERROR" ]; then
                echo -e "${red}[e] $2 ${term}"
        fi
}

ベストアンサー1

あなたが何をしたいのかわかりませんが、あなたの関数がどのようにしてPortageと相互作用する場合、色定義を使うことができます。からman 5 color.map

VARIABLES
       NORMAL = "normal"
              Defines color used for some words  occuring  in  other  contexts  than  those
              below.

       BAD = "red"
              Defines color used for some words occuring in bad context.

       BRACKET = "blue"
              Defines color used for brackets.

       GOOD = "green"
              Defines color used for some words occuring in good context.

       HILITE = "teal"
              Defines color used for highlighted words.

       INFORM = "darkgreen"
              Defines color used for informational words.

       [...]

       SECURITY_WARN = "red"
              Defines color used for security warnings.

       UNMERGE_WARN = "red"
              Defines color used for unmerge warnings.

       WARN = "yellow"
          Defines color used for warnings.

おすすめ記事