# 右プロンプト function __command_rprompt() { local green="\e[32m" local blue="\e[34m" local yellow="\e[33m" local reset="\e[0m"
local git_branch=""
# 現在のディレクトリがGitリリポジリであればブランチ名を取得 if type __git_ps1 &> /dev/null; then git_branch=$(__git_ps1 "%s") if [[ -n "$git_branch" ]]; then git_branch="${git_branch}" fi fi
# 各要素を色付け local aws_profile_colored="${green}${AWS_PROFILE}${reset}" local git_branch_colored="${blue}${git_branch}${reset}" local time_colored="${yellow}$(date '+%H:%M:%S')${reset}"
# 長さを計算 local rprompt_display_elements=() if [[ -n "$AWS_PROFILE" ]]; then rprompt_display_elements+=("$AWS_PROFILE") fi if [[ -n "$git_branch" ]]; then rprompt_display_elements+=("$git_branch") fi rprompt_display_elements+=("$(date '+%H:%M:%S')")
local rprompt_display_str=$(IFS=' '; echo "${rprompt_display_elements[*]}") local rprompt_len=${#rprompt_display_str} local num=$(($COLUMNS - rprompt_len - 2))
# 文字列を結合 local rprompt_final="" if [[ -n "$git_branch" ]]; then rprompt_final+="$git_branch_colored " fi if [[ -n "$AWS_PROFILE" ]]; then rprompt_final+="$aws_profile_colored " fi rprompt_final+="$time_colored"