Files
cshenv/tcshrc.prompt.final

382 lines
13 KiB
Tcsh
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

############################
### Final Prompt Setting ###
############################
#if( $?CSHENV_DEBUG ) then
# echo "Loading prompt session information."
#endif
#if( $?CSHENV_SESSION_PROFILE ) then
# safe_source ${CSHENV_DIR}/tcshrc.session.prompt.${CSHENV_SESSION_PROFILE}
#endif
#if( $?CSHENV_DEBUG ) then
# echo "Loaded prompt session information."
#endif
if( $?CSHENV_DEBUG ) then
echo "Setting up dynamic colour loading..."
endif
# Recompute cached sgr codes from any configuration updates
if( ! $?curr_branch_color ) then
set curr_branch_color=impossible
endif
if( "${curr_branch_color}" != "${branch_color}" ) then
set curr_branch_color="${branch_color}"
set branch_color_seq="%{[`__build_sgr_code no-csi reset ${curr_branch_color}`m"
endif
if( ! $?curr_dirs_color ) then
set curr_dirs_color=impossible
endif
if( "${curr_dirs_color}" != "${dirs_color}" ) then
set curr_dirs_color="${dirs_color}"
set dirs_color_seq="%{[`__build_sgr_code no-csi reset ${curr_dirs_color}`m"
endif
if( ! $?curr_ahead_tracking_color ) then
set curr_ahead_tracking_color=impossible
endif
if( "${curr_ahead_tracking_color}" != "${ahead_tracking_color}" ) then
set curr_ahead_tracking_color="${ahead_tracking_color}"
set ahead_tracking_color_seq="^[[`__build_sgr_code no-csi reset ${curr_ahead_tracking_color}`m"
endif
if( ! $?curr_behind_tracking_color ) then
set curr_behind_tracking_color=impossible
endif
if( "${curr_behind_tracking_color}" != "${behind_tracking_color}" ) then
set curr_behind_tracking_color="${behind_tracking_color}"
set behind_tracking_color_seq="^[[`__build_sgr_code no-csi reset ${curr_behind_tracking_color}`m"
endif
if( ! $?curr_percent_color ) then
set curr_percent_color=impossible
endif
if( "${curr_percent_color}" != "${percent_color}" ) then
set curr_percent_color="${percent_color}"
set percent_color_seq="[`__build_sgr_code no-csi reset ${curr_percent_color}`m"
endif
if( ! $?curr_at_color ) then
set curr_at_color=impossible
endif
if( "${curr_at_color}" != "${at_color}" ) then
set curr_at_color="${at_color}"
set at_color_seq="%{[`__build_sgr_code no-csi reset ${curr_at_color}`m%}"
endif
if( ! $?curr_depth_color ) then
set curr_depth_color=impossible
endif
if( "${curr_depth_color}" != "${depth_color}" ) then
set curr_depth_color="${depth_color}"
set depth_color_seq="%{[`__build_sgr_code no-csi reset ${curr_depth_color}`m%}"
endif
if( ! $?curr_line_color ) then
set curr_line_color=impossible
endif
if( "${curr_line_color}" != "${line_color}" ) then
set curr_line_color="${line_color}"
set line_color_seq="%{[`__build_sgr_code no-csi reset ${curr_line_color}`m%}"
endif
if( ! $?curr_path_color ) then
set curr_path_color=impossible
endif
if( "${curr_path_color}" != "${path_color}" ) then
set curr_path_color="${path_color}"
set path_color_seq="%{[`__build_sgr_code no-csi reset ${curr_path_color}`m%}"
endif
if( ! $?curr_host_color ) then
set curr_host_color=impossible
endif
if( "${curr_host_color}" != "${host_color}" ) then
set curr_host_color="${host_color}"
set host_color_seq="%{[`__build_sgr_code no-csi reset ${curr_host_color}`m%}"
endif
if( ! $?curr_date_color ) then
set curr_date_color=impossible
endif
if( "${curr_date_color}" != "${date_color}" ) then
set curr_date_color="${date_color}"
set date_color_seq="[`__build_sgr_code no-csi reset ${curr_date_color}`m"
set date_prompt_view="%{${date_color_seq}%}${date_prompt}%{${sgr_reset}%}"
endif
if( ! $?curr_time_color ) then
set curr_time_color=impossible
endif
if( "${curr_time_color}" != "${time_color}" ) then
set curr_time_color="${time_color}"
set time_color_seq="[`__build_sgr_code no-csi reset ${curr_time_color}`m"
set time_prompt_view="%{${time_color_seq}%}${time_prompt}%{${sgr_reset}%}"
endif
if( ! $?curr_text_color ) then
set curr_text_color=impossible
endif
if( "${curr_text_color}" != "${text_color}" ) then
set curr_text_color="${text_color}"
set text_color_seq="[`__build_sgr_code no-csi reset ${curr_text_color}`m"
endif
if( ! $?curr_brace_color ) then
set curr_brace_color=impossible
endif
if( "${curr_brace_color}" != "${brace_color}" ) then
set curr_brace_color="${brace_color}"
set brace_color_seq="%{[`__build_sgr_code no-csi reset ${curr_brace_color}`m%}"
endif
if( ! $?curr_user_color ) then
set curr_user_color=impossible
endif
if( "${curr_user_color}" != "${user_color}" ) then
set curr_user_color="${user_color}"
set user_color_seq="%{[`__build_sgr_code no-csi reset ${curr_user_color}`m%}"
endif
if( ! $?curr_prompt_color ) then
set curr_prompt_color=impossible
endif
if( "${curr_prompt_color}" != "${prompt_color}" ) then
set curr_prompt_color="${prompt_color}"
set prompt_color_seq="%{[`__build_sgr_code no-csi reset ${curr_prompt_color}`m%}"
endif
if( $?CSHENV_DEBUG ) echo "Dynamic color loading processed..."
if( ${prompt_hcolor} != 0 ) then
set last_color = ${reference_colors[${prompt_hcolor}]}
endif
if( ${prompt_hsym} != 0 ) then
set last_sym = ${referencechars[${prompt_hsym}]}
endif
@ prompt_hcolor = $prompt_hcolor % ${#reference_colors}
@ prompt_hsym = $prompt_hsym % ${#referencechars}
set critical_battery_level = 10
set low_battery_level = 20
set weak_battery_level = 33
set medium_battery_level = 50
set strong_battery_level = 75
while( ${prompt_hcolor} == 0 )
if( $?CSHENV_DEBUG ) then
echo colorshuffle
endif
#echo 
# Shuffle, if supported
if( $?CSHENV_DETECTED_SHUF ) then
set reference_colors=`shuf -e $reference_colors`
else
#echo "FALLBACK COLOR!"
set reference_colors=`echo $reference_colors | tr " " "\n" | sort -R | xargs`
endif
if( ! $?last_color ) then
break
endif
set first_color = ${reference_colors[1]}
if( ${first_color} != ${last_color} ) then
break
endif
end
while( ${prompt_hsym} == 0 )
if( $?CSHENV_DEBUG ) then
echo symbolshuffle
endif
#echo 
if( $?CSHENV_DETECTED_SHUF ) then
set referencechars=`shuf -e $referencechars`
#set reference_colors=`shuf -e $reference_colors`
else
#echo "FALLBACK CHAR!"
set referencechars=`echo $referencechars | tr " " "\n" | sort -R | xargs`
endif
if( ! $?last_sym ) then
break
endif
set first_sym = ${referencechars[1]}
if( ${first_sym} != ${last_sym} ) then
break
endif
end
@ prompt_hcolor = ${prompt_hcolor} + 1
@ prompt_hsym = ${prompt_hsym} + 1
if( $?CSHENV_DEBUG ) then
echo ${prompt_hcolor} ${prompt_hsym}
echo "Setting prompt"
endif
set prompt_reference_core="%{${reference_colors[${prompt_hcolor}]}%}${referencechars[${prompt_hsym}]}"
#if( ${referencechars[${prompt_hsym}]} == `env LC_ALL=C.UTF-8 printf "\u2328"` ) then
# set prompt_reference="%{${dim}%}<${prompt_reference_core} %{${dim}%}> "
#else
# set prompt_reference="%{${dim}%}< ${prompt_reference_core} %{${dim}%}> "
#endif
set prompt_reference="%{${dim}%}< ${prompt_reference_core} %{${dim}%}> "
#set prompt_reference="%{${csi}0;48\;5\;7m%}(${prompt_reference_core}%{${csi}0;48\;5\;7m%})%{${dim}%}"
#set prompt_reference="${prompt_reference_core}%{${text_color_seq}%} \- "
if( $?CSHENV_SHOW_BATTERY_LEVEL ) then
if( $CSHENV_SYSTEM == "Darwin" ) then
set battery_level=`pmset -g batt | grep -Eo "\d+%" | cut -d% -f1`
else if( $?CSHENV_BATTERY_DEVICE ) then
set battery_level=`cat ${CSHENV_BATTERY_DEVICE}`
else
set battery_level=`cat /sys/class/power_supply/BAT1/capacity`
endif
if( ${battery_level} < ${critical_battery_level} ) then
set battery_color=${red}${blink}
else if( ${battery_level} < ${low_battery_level} ) then
set battery_color=${red}
else if( ${battery_level} < ${weak_battery_level} ) then
set battery_color=${yellow}
else if( ${battery_level} < ${medium_battery_level} ) then
set battery_color=${bright_yellow}
else if( ${battery_level} < ${strong_battery_level} ) then
set battery_color=${green}
else
set battery_color=${bright_green}
endif
if( ${battery_level} < 10 ) then
set battery_level=" ${battery_level}"
else if( ${battery_level} < 100 ) then
set battery_level=" ${battery_level}"
endif
#set battery_prompt="%{${battery_color}%}%{${battery_level}${at_color}\%%}%{${dim}%} "
set battery_prefix="%{${csi}m${csi}28D%}"
set battery_prompt="%{${csi}38;2;128;128;255;3mBattery Level:${sgr_reset} ${battery_color}${battery_level}${percent_color_seq}%${sgr_reset} %}"
else
set battery_prefix=""
set battery_prompt=""
endif
set git_prompt=""
set git_prefix=""
set git_tracking_stat=""
set git_repo=`git rev-parse --git-dir >& /dev/null`
set __res=$?
if( 0 == ${__res} ) then
set git_branch=`git branch --show-current -q` >& /dev/null
if( ! -z "${git_branch}" ) then
set branch_space=30
set branch_indent=16
#set git_branch_reserve=`echo ${git_branch} | wc -c` >& /dev/null
#set git_prompt="%{${csi}${branch_indent}C${csi}mBranch: ${csi}3;38;2;255;192;192m${git_branch}${csi}m${csi}${branch_space}C\n%}"
# If the font doesn't support the special branch symbol...
set branch_symbol=`printf "\uE0A0"`
# I could always fallback to this one... (keep padded spaces... for alignment)
set branch_symbol=`printf '\u2387\ \ '`
git rev-list --count --left-right \@\{upstream\}..HEAD>&/dev/null
set __res=$?
#echo "Got: ${git_counts}"
if( 0 == ${__res} ) then
set git_behind_count=`git rev-list --count --right-only HEAD..\@\{upstream\}`
#echo "Got: ${git_behind_count}"
set git_ahead_count=`git rev-list --count --right-only \@\{upstream\}..HEAD`
#echo "Got: ${git_ahead_count}"
if( 0 != ${git_behind_count} ) then
set git_tracking_stat=": -%{${behind_tracking_color_seq}%}${git_behind_count}%{${sgr_reset}%}"
if( 0 != ${git_ahead_count} ) then
set git_tracking_stat="${git_tracking_stat},+%{${ahead_tracking_color_seq}%}${git_ahead_count}%{${sgr_reset}%}"
endif
else
if( 0 != ${git_ahead_count} ) then
set git_tracking_stat=": +%{${ahead_tracking_color_seq}%}${git_ahead_count}%{${sgr_reset}%}"
endif
endif
endif
set git_prompt="%{${sgr_reset}%}(${branch_symbol} %{${branch_color_seq}%}${git_branch}%{${sgr_reset}%}${git_tracking_stat}) "
#set git_prompt="%{${csi}10D${csi}2D(xyz${git_branch})${csi}m%%}"
#set git_prompt="%{${csi}0;35m${csi}50D${git_branch} %}"
endif
else
endif
#set prompt_cool="%{\n%}${align_prefix}${battery_prefix}${battery_prompt}${date_prompt}${align_suffix}${git_prompt}${brace_color_seq}\[${prompt_reference}${line_prompt}${depth_prompt}${user_prompt}${at_color_seq}@${host_prompt}${text_color_seq}\: ${path_prompt}${brace_color_seq}\]${end_prompt}"
set prompt_reference_view=""
set line_prompt_view=""
set depth_prompt_view=""
set user_prompt_view=""
set at_view=""
set host_prompt_view=""
set git_prompt_view=""
set path_prompt_view=""
set line_spacer_view=""
set dirs_prompt_view=""
if( ! $?CSHENV_DISABLE_PROMPT_SIGIL ) then
set prompt_reference_view="${prompt_reference}"
endif
if( ! $?CSHENV_DISABLE_PROMPT_TTY ) then
set line_prompt_view="${line_color_seq}${line_prompt}"
set line_spacer_view="%{${text_color_seq}%}\- "
endif
if( ! $?CSHENV_DISABLE_PROMPT_NESTING ) then
set depth_prompt_spacing=""
if( ! $?CSHENV_DISABLE_PROMPT_TTY ) then
set depth_prompt_spacing=" "
endif
set depth_prompt_view="${depth_color_seq}${depth_prompt_spacing}${depth_prompt}"
if( $?CSHENV_HIDE_SHELL_LEVEL_AT_ONE ) then
if( ${shlvl} == 1 ) then
set depth_prompt_view=""
endif
endif
endif
if( ! $?CSHENV_DISABLE_PROMPT_USER ) then
set user_prompt_view="${user_color_seq}${user_prompt}%{${sgr_reset}%}"
if( ! $?CSHENV_DISABLE_PROMPT_HOST ) then
set at_view="${at_color_seq}@"
endif
endif
if( ! $?CSHENV_DISABLE_PROMPT_HOST ) then
set host_prompt_tail=": "
if( $?CSHENV_DISABLE_PROMPT_GIT && $?CSHENV_DISABLE_PROMPT_PATH ) then
set host_prompt_tail=""
endif
set host_prompt_view="${host_color_seq}${host_prompt}%{${text_color_seq}%}${host_prompt_tail}"
endif
if( ! $?CSHENV_DISABLE_PROMPT_GIT ) then
set git_prompt_view="${git_prompt}"
endif
if( ! $?CSHENV_DISABLE_PROMPT_PATH ) then
set path_prompt_view="%{${path_color_seq}%}${path_prompt}%{${sgr_reset}%}"
endif
if( ! $?CSHENV_DISABLE_PROMPT_DIRS ) then
set dirs_prompt=`dirs -v | wc -l`
if( ${dirs_prompt} > 1 ) then
set dirs_prompt_view=" {%{${dirs_color_seq}%}${dirs_prompt}%{${sgr_reset}%}}"
endif
endif
set prompt_cool="%{\n%}${align_prefix}${battery_prefix}${battery_prompt}${date_prompt_view}%{ %}${time_prompt_view}${align_suffix}${brace_color_seq}\[${prompt_reference_view}${line_prompt_view}${depth_prompt_view}${line_spacer_view}${user_prompt_view}${at_view}${host_prompt_view}${git_prompt_view}${path_prompt_view}${dirs_prompt_view}${brace_color_seq}\]${prompt_color_seq}${end_prompt}%{${text_color_seq}%} "
if( ! ${?cshenv_user_prompt_override} ) then
set prompt="$prompt_cool"
endif
###########################
# vim:filetype=tcsh
###########################