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

Make prompt_custom not print the segment if empty

Currently you can't make a conditional custom segment. This changes the
prompt_custom function responsible for printing custom segments so that
it won't print the segment in case the content is empty.

With this it becomes possible to make conditional custom prompts simply
by making it not print anything when it's not supposed to be shown.
This commit is contained in:
Mateus "Doodad" Medeiros 2016-05-24 10:53:48 -03:00 committed by Ben Hilburn
parent 81c55b4b74
commit 20b4d2b43e

View file

@ -445,8 +445,11 @@ prompt_context() {
# the output in a segment.
prompt_custom() {
local command=POWERLEVEL9K_CUSTOM_$3:u
local segment_content="$(eval ${(P)command})"
"$1_prompt_segment" "${0}_${3:u}" "$2" $DEFAULT_COLOR_INVERTED $DEFAULT_COLOR "$(eval ${(P)command})"
if [[ -n $segment_content ]]; then
"$1_prompt_segment" "${0}_${3:u}" "$2" $DEFAULT_COLOR_INVERTED $DEFAULT_COLOR "$segment_content"
fi
}
# Dir: current working directory