From 89fdfa0148fe1c3360a9e2d09fe0f7a5e9b0ceec Mon Sep 17 00:00:00 2001 From: "Mateus \"Doodad\" Medeiros" Date: Tue, 24 May 2016 10:53:48 -0300 Subject: [PATCH] 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. --- powerlevel9k.zsh-theme | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index bf313b85..d5c2c8bb 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -444,8 +444,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