1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-11-26 05:50:07 +00:00

First try: Now joined segments are promoted to "full" segments, if their

predecessor was conditional and had no output.
This commit is contained in:
Dominik Ritter 2016-01-17 14:55:26 +01:00
parent 472fb6f674
commit cd78c66997

View file

@ -283,9 +283,11 @@ CURRENT_BG='NONE'
# AWS Profile # AWS Profile
prompt_aws() { prompt_aws() {
local aws_profile="$AWS_DEFAULT_PROFILE" local aws_profile="$AWS_DEFAULT_PROFILE"
if [[ -n "$aws_profile" ]];
then if [[ -n "$aws_profile" ]]; then
"$1_prompt_segment" "$0" "$2" red white "$aws_profile" 'AWS_ICON' "$1_prompt_segment" "$0" "$2" red white "$aws_profile" 'AWS_ICON'
else
last_had_output=false
fi fi
} }
@ -389,7 +391,11 @@ prompt_battery() {
fi fi
# Draw the prompt_segment # Draw the prompt_segment
[[ -n $bat_percent ]] && "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$message" 'BATTERY_ICON' if [[ -n $bat_percent ]]; then
"$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$message" 'BATTERY_ICON'
else
last_had_output=false
fi
} }
# Context: user@hostname (who am I and where am I) # Context: user@hostname (who am I and where am I)
@ -402,6 +408,8 @@ prompt_context() {
else else
"$1_prompt_segment" "$0_DEFAULT" "$2" "$DEFAULT_COLOR" "011" "$USER@%m" "$1_prompt_segment" "$0_DEFAULT" "$2" "$DEFAULT_COLOR" "011" "$USER@%m"
fi fi
else
last_had_output=false
fi fi
} }
@ -451,6 +459,8 @@ prompt_go_version() {
if [[ -n "$go_version" ]]; then if [[ -n "$go_version" ]]; then
"$1_prompt_segment" "$0" "$2" "green" "255" "$go_version" "$1_prompt_segment" "$0" "$2" "green" "255" "$go_version"
else
last_had_output=false
fi fi
} }
@ -618,6 +628,8 @@ prompt_rbenv() {
prompt_root_indicator() { prompt_root_indicator() {
if [[ "$UID" -eq 0 ]]; then if [[ "$UID" -eq 0 ]]; then
"$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "" 'ROOT_ICON' "$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "" 'ROOT_ICON'
else
last_had_output=false
fi fi
} }
@ -628,6 +640,8 @@ prompt_rust_version() {
if [[ -n "$rust_version" ]]; then if [[ -n "$rust_version" ]]; then
"$1_prompt_segment" "$0" "$2" "208" "$DEFAULT_COLOR" "Rust $rust_version" "$1_prompt_segment" "$0" "$2" "208" "$DEFAULT_COLOR" "Rust $rust_version"
else
last_had_output=false
fi fi
} }
# RSpec test ratio # RSpec test ratio
@ -665,6 +679,8 @@ prompt_status() {
else else
if [[ "$RETVAL" -ne 0 ]]; then if [[ "$RETVAL" -ne 0 ]]; then
"$1_prompt_segment" "$0_ERROR" "$2" "$DEFAULT_COLOR" "red" "" 'FAIL_ICON' "$1_prompt_segment" "$0_ERROR" "$2" "$DEFAULT_COLOR" "red" "" 'FAIL_ICON'
else
last_had_ouput=false
fi fi
fi fi
} }
@ -813,12 +829,22 @@ prompt_virtualenv() {
build_left_prompt() { build_left_prompt() {
defined POWERLEVEL9K_LEFT_PROMPT_ELEMENTS || POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs) defined POWERLEVEL9K_LEFT_PROMPT_ELEMENTS || POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs)
# Global variable to check if the last segment had output.
typeset -g last_had_output=true
for element in "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[@]}"; do for element in "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[@]}"; do
# Check if the segment should be joined with the previous one # Check if the segment should be joined with the previous one
local joined=false local joined=false
if [[ ${element[-7,-1]} == '_joined' ]]; then if [[ ${element[-7,-1]} == '_joined' ]]; then
element="${element[0,-8]}" element="${element[0,-8]}"
joined=true if [[ "$last_had_output" == false ]]; then
joined=false
# Reset variable
last_had_ouput=true
else
joined=true
fi
fi fi
# Check if it is a custom command, otherwise interpet it as # Check if it is a custom command, otherwise interpet it as
# a prompt. # a prompt.