98507d229b
* master: Move battery thresholds to static defs. Uncouple the "impossible" branch of changed colors.
320 lines
11 KiB
Tcsh
320 lines
11 KiB
Tcsh
############################
|
|
### 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
|
|
|
|
_debug "Setting up dynamic colour loading..."
|
|
|
|
|
|
|
|
# Recompute cached sgr codes from any configuration updates
|
|
set prompt_segment_kinds=( \
|
|
branch \
|
|
dirs \
|
|
ahead_tracking \
|
|
behind_tracking \
|
|
percent \
|
|
at \
|
|
depth \
|
|
line \
|
|
path \
|
|
host \
|
|
date \
|
|
time \
|
|
text \
|
|
brace \
|
|
user \
|
|
prompt \
|
|
)
|
|
|
|
# The algorithm is duplicated with less branching to make startup a bit faster.
|
|
if ( ! $?cshenv_prompt_first_cache ) then
|
|
foreach kind ( ${prompt_segment_kinds} )
|
|
eval 'set __new_this_color="${'"${kind}"'_color}"'
|
|
eval 'set curr_'"${kind}"'_color="'${__new_this_color}'"'
|
|
set __this_color_seq="%{[`__build_sgr_code no-csi reset ${__new_this_color}`m%}"
|
|
eval 'set '"${kind}"'_color_seq="'"${__this_color_seq}"'"'
|
|
end
|
|
set cshenv_prompt_first_cache=1
|
|
else
|
|
foreach kind ( ${prompt_segment_kinds} )
|
|
eval 'set __new_this_color="${'"${kind}"'_color}"'
|
|
eval 'set __curr_this_color="${curr_'"${kind}"'_color}"'
|
|
if( "${__new_this_color}" == "${__curr_this_color}" ) continue
|
|
|
|
eval 'set curr_'"${kind}"'_color="'${__new_this_color}'"'
|
|
set __this_color_seq="%{[`__build_sgr_code no-csi reset ${__new_this_color}`m%}"
|
|
eval 'set '"${kind}"'_color_seq="'"${__this_color_seq}"'"'
|
|
end
|
|
endif
|
|
|
|
_debug "Done with color cacheing loop"
|
|
|
|
_debug "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}
|
|
|
|
|
|
while( ${prompt_hcolor} == 0 )
|
|
_debug colorshuffle
|
|
#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 )
|
|
_debug symbolshuffle
|
|
#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
|
|
_debug ${prompt_hcolor} ${prompt_hsym}
|
|
_debug "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}`
|
|
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=${csi}33m
|
|
else if( ${battery_level} < ${medium_battery_level} ) then
|
|
set battery_color=${csi}93m
|
|
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( ! $?CSHENV_NO_UNICODE_PRINTF ) then
|
|
# 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\ \ '`
|
|
else
|
|
# Non unicode fallback 'X'
|
|
set branch_symbol='X'
|
|
endif
|
|
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=""
|
|
set time_prompt_view=""
|
|
set date_prompt_view=""
|
|
set battery_prompt_view=""
|
|
set internal_bracket_view=""
|
|
|
|
_debug "About to setup prompt members, with disable checks"
|
|
|
|
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_SHOW_SHELL_LEVEL_AT_ONE ) then
|
|
if( ${shlvl} == 1 ) then
|
|
set depth_prompt_view=""
|
|
endif
|
|
endif
|
|
endif
|
|
|
|
if( ! $?CSHENV_DISABLE_PROMPT_ENV_VIEW ) then
|
|
set cshenv_prompt_view="%{${cshenv_prompt}%}"
|
|
endif
|
|
|
|
_debug "Up to the user and host checks..."
|
|
set host_prompt_tail=": "
|
|
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}@"
|
|
else
|
|
set at_view="${host_prompt_tail}" # Hack
|
|
endif
|
|
endif
|
|
if( ! $?CSHENV_DISABLE_PROMPT_HOST ) then
|
|
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="${#dirstack}"
|
|
if( ${dirs_prompt} > 1 ) then
|
|
set dirs_prompt_view=" {%{${dirs_color_seq}%}${dirs_prompt}%{${sgr_reset}%}}"
|
|
endif
|
|
endif
|
|
|
|
_debug "Up to the time, date, and battery checks..."
|
|
if( ! $?CSHENV_DISABLE_PROMPT_TIME ) then
|
|
set time_prompt_view="${time_color_seq}${time_prompt}%{${sgr_reset}%}"
|
|
endif
|
|
if( ! $?CSHENV_DISABLE_PROMPT_DATE ) then
|
|
set date_prompt_view="${date_color_seq}${date_prompt}%{${sgr_reset}%}"
|
|
endif
|
|
if( ! $?CSHENV_DISABLE_PROMPT_BATTERY ) then
|
|
set battery_prompt_view="${battery_prefix}${battery_prompt}"
|
|
endif
|
|
|
|
_debug "Doing the internal bracket setup..."
|
|
set internal_bracket_prompt="${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}"
|
|
if( "" != "${internal_bracket_prompt}" ) then
|
|
#echo "I see scratch -${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}-"
|
|
#echo -n "${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}" | dd of=/home/adam/scratch
|
|
set internal_bracket_view="${brace_color_seq}\[${internal_bracket_prompt}${brace_color_seq}\]"
|
|
endif
|
|
|
|
set prompt_cool="%{\n%}${align_prefix}${battery_prompt_view}${date_prompt_view}%{ %}${time_prompt_view}${align_suffix}${internal_bracket_view}${prompt_color_seq}${end_prompt}%{${text_color_seq}%} "
|
|
|
|
|
|
if( ! ${?cshenv_user_prompt_override} ) then
|
|
set prompt="$prompt_cool"
|
|
endif
|
|
|
|
###########################
|
|
# vim:filetype=tcsh
|
|
###########################
|