Agnosterテーマ:着色時間

Agnosterテーマ:着色時間

私はagnosterテーマを使用しています:[![ここに画像の説明を入力してください][1]][1]

さまざまなユーザー名の色で時間を着色する方法を知りたいです。

現在、agnoster.theme.shファイルのPrompt_context()関数は次のとおりです。

prompt_context() {
local user=`whoami`

if [[ $user == $DEFAULT_USER || $user != $DEFAULT_USER || -n $SSH_CLIENT ]]; then
        # green is the color of background
        # white is the color of foreground
        
    prompt_segment green white "[\A] $user@\h "     
fi

}

問題は、私のユーザー名と時間の色が同じであることです。

私は同様のことを試しました:

prompt_segment green white " ${red green [\A]}$user@\h "

しかし、これはうまくいきません。私もこれを見ました:https://github.com/ohmybash/oh-my-bash/blob/master/themes/agnoster/agnoster.theme.sh#L156-L178 しかし、私は少し迷子になりました。

誰でもどんなアイデアがありますか?

ベストアンサー1

もう一度試して解決策を見つけました。表示したい要素ごとに機能を追加する必要があり、時間を表示する機能と履歴ラインを希望の色で表示する機能を別々にしました。

# Display history line
prompt_historyline(){
    prompt_segment yellow white ' \! '
}


# Display time
prompt_time() {
  prompt_segment orange white ' [\A] '
}

私のプロンプト_コンテキスト機能:

prompt_context() {
    local user=`whoami`

    if [[ $user == $DEFAULT_USER || $user != $DEFAULT_USER || -n $SSH_CLIENT ]]; then
            # green is the color of background
            # white is the color of foreground          
            
        prompt_segment green white " $user@\h "        
    fi
}

次に、2つのニュース機能を基本機能(デフォルトのプロンプトビルダー)に追加しました。

build_prompt() {
[[ ! -z ${AG_EMACS_DIR+x} ]] && prompt_emacsdir
prompt_status
prompt_historyline
prompt_time
#[[ -z ${AG_NO_HIST+x} ]] && prompt_histdt
[[ -z ${AG_NO_CONTEXT+x} ]] && prompt_context
prompt_virtualenv
prompt_dir
prompt_git
prompt_end

}

結果は次のとおりです。

ここに画像の説明を入力してください。

おすすめ記事