From 877ef6177366ffdcb25dcb6dfac38eb899e2f4e4 Mon Sep 17 00:00:00 2001 From: Yang Tang Date: Wed, 22 Aug 2018 14:37:52 -0400 Subject: [PATCH 01/79] Fix icons cut off in RPROMPT segments --- powerlevel9k.zsh-theme | 4 ++-- test/powerlevel9k.spec | 6 +++--- test/segments/command_execution_time.spec | 12 ++++++------ test/segments/dir.spec | 10 +++++----- test/segments/go_version.spec | 2 +- test/segments/kubecontext.spec | 4 ++-- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0b2287ef9..1e9d1123b 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -163,7 +163,7 @@ left_prompt_segment() { # Allow users to overwrite the color for the visual identifier only. local visual_identifier_color_variable=POWERLEVEL9K_${(U)1#prompt_}_VISUAL_IDENTIFIER_COLOR set_default $visual_identifier_color_variable $4 - visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier%f" + visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier" fi fi @@ -256,7 +256,7 @@ right_prompt_segment() { # Allow users to overwrite the color for the visual identifier only. local visual_identifier_color_variable=POWERLEVEL9K_${(U)1#prompt_}_VISUAL_IDENTIFIER_COLOR set_default $visual_identifier_color_variable $4 - visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier%f" + visual_identifier="%F{${(P)visual_identifier_color_variable}%}$visual_identifier" fi fi diff --git a/test/powerlevel9k.spec b/test/powerlevel9k.spec index 0ddf36c10..75df29f8b 100755 --- a/test/powerlevel9k.spec +++ b/test/powerlevel9k.spec @@ -65,7 +65,7 @@ function testDynamicColoringOfVisualIdentifiersWork() { cd /tmp - assertEquals "%K{blue} %F{green%}icon-here %f%F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{green%}icon-here %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR @@ -86,7 +86,7 @@ function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() { cd /tmp - assertEquals "%K{yellow} %F{green%}icon-here %f%F{red}/tmp %k%F{yellow}%f " "$(build_left_prompt)" + assertEquals "%K{yellow} %F{green%}icon-here %F{red}/tmp %k%F{yellow}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_DIR_DEFAULT_VISUAL_IDENTIFIER_COLOR @@ -106,7 +106,7 @@ function testOverwritingIconsWork() { #cd ~/$testFolder cd /tmp - assertEquals "%K{blue} %F{black%}icon-here %f%F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}icon-here %F{black}/tmp %k%F{blue}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_DIR_FOLDER_ICON diff --git a/test/segments/command_execution_time.spec b/test/segments/command_execution_time.spec index d3588d83f..7ad2cb5c1 100755 --- a/test/segments/command_execution_time.spec +++ b/test/segments/command_execution_time.spec @@ -28,7 +28,7 @@ function testCommandExecutionTimeThresholdCouldBeChanged() { POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1 _P9K_COMMAND_DURATION=2.03 - assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}2.03 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{red} %F{yellow1%}Dur %F{yellow1}2.03 %k%F{red}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -40,7 +40,7 @@ function testCommandExecutionTimeThresholdCouldBeSetToZero() { POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0 _P9K_COMMAND_DURATION=0.03 - assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}0.03 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{red} %F{yellow1%}Dur %F{yellow1}0.03 %k%F{red}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -53,7 +53,7 @@ function testCommandExecutionTimePrecisionCouldBeChanged() { POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=4 _P9K_COMMAND_DURATION=0.0001 - assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}0.0001 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{red} %F{yellow1%}Dur %F{yellow1}0.0001 %k%F{red}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -66,7 +66,7 @@ function testCommandExecutionTimePrecisionCouldBeSetToZero() { POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0 _P9K_COMMAND_DURATION=23.5001 - assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}23 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{red} %F{yellow1%}Dur %F{yellow1}23 %k%F{red}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -77,7 +77,7 @@ function testCommandExecutionTimeIsFormattedHumandReadbleForMinuteLongCommand() POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) _P9K_COMMAND_DURATION=180 - assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}03:00 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{red} %F{yellow1%}Dur %F{yellow1}03:00 %k%F{red}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION @@ -87,7 +87,7 @@ function testCommandExecutionTimeIsFormattedHumandReadbleForHourLongCommand() { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(command_execution_time) _P9K_COMMAND_DURATION=7200 - assertEquals "%K{red} %F{yellow1%}Dur %f%F{yellow1}02:00:00 %k%F{red}%f " "$(build_left_prompt)" + assertEquals "%K{red} %F{yellow1%}Dur %F{yellow1}02:00:00 %k%F{red}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset _P9K_COMMAND_DURATION diff --git a/test/segments/dir.spec b/test/segments/dir.spec index b5fce59f3..046016228 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -329,7 +329,7 @@ function testHomeFolderDetectionWorks() { POWERLEVEL9K_HOME_ICON='home-icon' cd ~ - assertEquals "%K{blue} %F{black%}home-icon %f%F{black}~ %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}home-icon %F{black}~ %k%F{blue}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_HOME_ICON @@ -341,7 +341,7 @@ function testHomeSubfolderDetectionWorks() { FOLDER=~/powerlevel9k-test mkdir $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black%}sub-icon %f%F{black}~/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}sub-icon %F{black}~/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER @@ -355,7 +355,7 @@ function testOtherFolderDetectionWorks() { FOLDER=/tmp/powerlevel9k-test mkdir $FOLDER cd $FOLDER - assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}/tmp/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}folder-icon %F{black}/tmp/powerlevel9k-test %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr $FOLDER @@ -407,7 +407,7 @@ function testOmittingFirstCharacterWorks() { POWERLEVEL9K_FOLDER_ICON='folder-icon' cd /tmp - assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}tmp %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}folder-icon %F{black}tmp %k%F{blue}%f " "$(build_left_prompt)" cd - unset POWERLEVEL9K_FOLDER_ICON @@ -421,7 +421,7 @@ function testOmittingFirstCharacterWorksWithChangingPathSeparator() { mkdir -p /tmp/powerlevel9k-test/1/2 cd /tmp/powerlevel9k-test/1/2 - assertEquals "%K{blue} %F{black%}folder-icon %f%F{black}tmpxXxpowerlevel9k-testxXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" + assertEquals "%K{blue} %F{black%}folder-icon %F{black}tmpxXxpowerlevel9k-testxXx1xXx2 %k%F{blue}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test diff --git a/test/segments/go_version.spec b/test/segments/go_version.spec index 9104ac8b3..d8982e21b 100755 --- a/test/segments/go_version.spec +++ b/test/segments/go_version.spec @@ -40,7 +40,7 @@ function testGo() { PWD="$HOME/go/src/github.com/bhilburn/powerlevel9k" - assertEquals "%K{green} %F{grey93%} %f%F{grey93}go1.5.3 %k%F{green}%f " "$(build_left_prompt)" + assertEquals "%K{green} %F{grey93%} %F{grey93}go1.5.3 %k%F{green}%f " "$(build_left_prompt)" unset POWERLEVEL9K_GO_ICON unset PWD diff --git a/test/segments/kubecontext.spec b/test/segments/kubecontext.spec index 63810378e..5e8bbe828 100755 --- a/test/segments/kubecontext.spec +++ b/test/segments/kubecontext.spec @@ -69,7 +69,7 @@ function testKubeContext() { alias kubectl=mockKubectl POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) - assertEquals "%K{magenta} %F{white%}⎈ %f%F{white}minikube/default %k%F{magenta}%f " "$(build_left_prompt)" + assertEquals "%K{magenta} %F{white%}⎈ %F{white}minikube/default %k%F{magenta}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unalias kubectl @@ -78,7 +78,7 @@ function testKubeContextOtherNamespace() { alias kubectl=mockKubectlOtherNamespace POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext) - assertEquals "%K{magenta} %F{white%}⎈ %f%F{white}minikube/kube-system %k%F{magenta}%f " "$(build_left_prompt)" + assertEquals "%K{magenta} %F{white%}⎈ %F{white}minikube/kube-system %k%F{magenta}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unalias kubectl From 24bbbfc9bdbdc0666a53cd4a60a8b57551e9f0ca Mon Sep 17 00:00:00 2001 From: Yang Tang Date: Wed, 22 Aug 2018 15:01:04 -0400 Subject: [PATCH 02/79] Update unit tests for fixing RPROMPT icons cut off --- test/segments/laravel_version.spec | 2 +- test/segments/rust_version.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/segments/laravel_version.spec b/test/segments/laravel_version.spec index 6133b19a2..34b06cce5 100755 --- a/test/segments/laravel_version.spec +++ b/test/segments/laravel_version.spec @@ -32,7 +32,7 @@ function testLaravelVersionSegment() { POWERLEVEL9K_LARAVEL_ICON='x' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(laravel_version) - assertEquals "%K{001} %F{white%}x %f%F{white}5.4.23 %k%F{maroon}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{white%}x %F{white}5.4.23 %k%F{maroon}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_LARAVEL_ICON diff --git a/test/segments/rust_version.spec b/test/segments/rust_version.spec index 34883a10e..091d5217e 100755 --- a/test/segments/rust_version.spec +++ b/test/segments/rust_version.spec @@ -32,7 +32,7 @@ function testRust() { mockRust POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(rust_version) - assertEquals "%K{208} %F{black%}Rust %f%F{black}0.4.1a-alpha %k%F{darkorange}%f " "$(build_left_prompt)" + assertEquals "%K{208} %F{black%}Rust %F{black}0.4.1a-alpha %k%F{darkorange}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS } From 735994f82ea47118aa31278af1c9a596d35469ed Mon Sep 17 00:00:00 2001 From: Paul Gierz Date: Fri, 7 Sep 2018 11:52:21 +0200 Subject: [PATCH 03/79] Fix for #974 --- functions/utilities.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 127007fb1..cedf54938 100755 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -102,7 +102,9 @@ case $(uname) in ;; Linux) OS='Linux' - os_release_id="$(grep -E '^ID=([a-zA-Z]*)' /etc/os-release | cut -d '=' -f 2)" + if [ -f /etc/os-release ]; then + os_release_id="$(grep -E '^ID=([a-zA-Z]*)' /etc/os-release | cut -d '=' -f 2)" + fi case "$os_release_id" in *arch*) OS_ICON=$(print_icon 'LINUX_ARCH_ICON') From 5737ca6e81a3191cb232085877b5894be0a052ed Mon Sep 17 00:00:00 2001 From: Yang Tang Date: Fri, 12 Oct 2018 14:09:22 -0400 Subject: [PATCH 04/79] Remove extra %f in unit tests --- test/core/color_overriding.spec | 10 +++++----- test/core/visual_identifier.spec | 8 ++++---- test/segments/anaconda.spec | 6 +++--- test/segments/aws_eb_env.spec | 4 ++-- test/segments/background_jobs.spec | 6 +++--- test/segments/battery.spec | 26 +++++++++++++------------- test/segments/custom.spec | 4 ++-- test/segments/disk_usage.spec | 10 +++++----- test/segments/ip.spec | 12 ++++++------ test/segments/load.spec | 12 ++++++------ test/segments/node_version.spec | 2 +- test/segments/nodeenv.spec | 4 ++-- test/segments/nvm.spec | 2 +- test/segments/ram.spec | 6 +++--- test/segments/ssh.spec | 6 +++--- test/segments/status.spec | 12 ++++++------ test/segments/swap.spec | 4 ++-- test/segments/swift_version.spec | 2 +- test/segments/todo.spec | 2 +- test/segments/vcs-git.spec | 8 ++++---- test/segments/vcs-hg.spec | 2 +- 21 files changed, 74 insertions(+), 74 deletions(-) diff --git a/test/core/color_overriding.spec b/test/core/color_overriding.spec index f2c3d8910..e23d3aaa4 100755 --- a/test/core/color_overriding.spec +++ b/test/core/color_overriding.spec @@ -16,7 +16,7 @@ function testDynamicColoringOfSegmentsWork() { local POWERLEVEL9K_DATE_ICON="date-icon" local POWERLEVEL9K_DATE_BACKGROUND='red' - assertEquals "%K{001} %F{000}date-icon %f%F{000}%D{%d.%m.%y} %k%F{001}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{000}date-icon %F{000}%D{%d.%m.%y} %k%F{001}%f " "$(build_left_prompt)" } function testDynamicColoringOfVisualIdentifiersWork() { @@ -24,7 +24,7 @@ function testDynamicColoringOfVisualIdentifiersWork() { local POWERLEVEL9K_DATE_ICON="date-icon" local POWERLEVEL9K_DATE_VISUAL_IDENTIFIER_COLOR='green' - assertEquals "%K{007} %F{002}date-icon %f%F{000}%D{%d.%m.%y} %k%F{007}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{002}date-icon %F{000}%D{%d.%m.%y} %k%F{007}%f " "$(build_left_prompt)" } function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() { @@ -34,7 +34,7 @@ function testColoringOfVisualIdentifiersDoesNotOverwriteColoringOfSegment() { local POWERLEVEL9K_DATE_FOREGROUND='red' local POWERLEVEL9K_DATE_BACKGROUND='yellow' - assertEquals "%K{003} %F{002}date-icon %f%F{001}%D{%d.%m.%y} %k%F{003}%f " "$(build_left_prompt)" + assertEquals "%K{003} %F{002}date-icon %F{001}%D{%d.%m.%y} %k%F{003}%f " "$(build_left_prompt)" } function testColorOverridingOfStatefulSegment() { @@ -45,7 +45,7 @@ function testColorOverridingOfStatefulSegment() { # Provoke state local SSH_CLIENT="x" - assertEquals "%K{001} %F{002}ssh-icon %f%F{002}%m %k%F{001}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{002}ssh-icon %F{002}%m %k%F{001}%f " "$(build_left_prompt)" } function testColorOverridingOfCustomSegment() { @@ -56,7 +56,7 @@ function testColorOverridingOfCustomSegment() { local POWERLEVEL9K_CUSTOM_WORLD_FOREGROUND='red' local POWERLEVEL9K_CUSTOM_WORLD_BACKGROUND='red' - assertEquals "%K{001} %F{002}CW %f%F{001}world %k%F{001}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{002}CW %F{001}world %k%F{001}%f " "$(build_left_prompt)" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/core/visual_identifier.spec b/test/core/visual_identifier.spec index c6c6bef57..33815f79f 100755 --- a/test/core/visual_identifier.spec +++ b/test/core/visual_identifier.spec @@ -18,7 +18,7 @@ function testOverwritingIconsWork() { local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' local POWERLEVEL9K_CUSTOM_WORLD1_ICON='icon-here' - assertEquals "%K{007} %F{000}icon-here %f%F{000}world1 %k%F{007}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}icon-here %F{000}world1 %k%F{007}%f " "$(build_left_prompt)" } function testVisualIdentifierAppearsBeforeSegmentContentOnLeftSegments() { @@ -27,7 +27,7 @@ function testVisualIdentifierAppearsBeforeSegmentContentOnLeftSegments() { local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' local POWERLEVEL9K_CUSTOM_WORLD1_ICON='icon-here' - assertEquals "%K{007} %F{000}icon-here %f%F{000}world1 %k%F{007}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}icon-here %F{000}world1 %k%F{007}%f " "$(build_left_prompt)" } function testVisualIdentifierAppearsAfterSegmentContentOnRightSegments() { @@ -36,7 +36,7 @@ function testVisualIdentifierAppearsAfterSegmentContentOnRightSegments() { local POWERLEVEL9K_CUSTOM_WORLD1='echo world1' local POWERLEVEL9K_CUSTOM_WORLD1_ICON='icon-here' - assertEquals "%F{007}%f%K{007}%F{000} world1%F{000} icon-here%f%E" "$(build_right_prompt)" + assertEquals "%F{007}%f%K{007}%F{000} world1%F{000} icon-here%E" "$(build_right_prompt)" } function testVisualIdentifierPrintsNothingIfNotAvailable() { @@ -54,7 +54,7 @@ function testVisualIdentifierIsPrintedInNumericalColorCode() { local POWERLEVEL9K_CUSTOM_WORLD1_ICON="xxx" local POWERLEVEL9K_CUSTOM_WORLD1_VISUAL_IDENTIFIER_COLOR="purple3" - assertEquals "%K{007} %F{056}xxx %f%F{000}world1 %k%F{007}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{056}xxx %F{000}world1 %k%F{007}%f " "$(build_left_prompt)" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/anaconda.spec b/test/segments/anaconda.spec index efcfc0300..a25aed9bd 100755 --- a/test/segments/anaconda.spec +++ b/test/segments/anaconda.spec @@ -35,7 +35,7 @@ function testAnacondaSegmentWorksIfOnlyAnacondaPathIsSet() { CONDA_ENV_PATH=/tmp unset CONDA_PREFIX - assertEquals "%K{004} %F{000}icon-here %f%F{000}(tmp) %k%F{004}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}icon-here %F{000}(tmp) %k%F{004}%f " "$(build_left_prompt)" } function testAnacondaSegmentWorksIfOnlyAnacondaPrefixIsSet() { @@ -49,7 +49,7 @@ function testAnacondaSegmentWorksIfOnlyAnacondaPrefixIsSet() { unset CONDA_ENV_PATH local CONDA_PREFIX="test" - assertEquals "%K{004} %F{000}icon-here %f%F{000}(test) %k%F{004}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}icon-here %F{000}(test) %k%F{004}%f " "$(build_left_prompt)" } function testAnacondaSegmentWorks() { @@ -63,7 +63,7 @@ function testAnacondaSegmentWorks() { local CONDA_ENV_PATH=/tmp local CONDA_PREFIX="test" - assertEquals "%K{004} %F{000}icon-here %f%F{000}(tmptest) %k%F{004}%f " "$(build_left_prompt)" + assertEquals "%K{004} %F{000}icon-here %F{000}(tmptest) %k%F{004}%f " "$(build_left_prompt)" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/aws_eb_env.spec b/test/segments/aws_eb_env.spec index 99b418e0a..6cd8931ca 100755 --- a/test/segments/aws_eb_env.spec +++ b/test/segments/aws_eb_env.spec @@ -31,7 +31,7 @@ function testAwsEbEnvSegmentWorksIfElasticBeanstalkEnvironmentIsSet() { echo "test:\n environment: test" > /tmp/powerlevel9k-test/.elasticbeanstalk/config.yml cd /tmp/powerlevel9k-test - assertEquals "%K{000} %F{002}🌱 %f%F{002}test %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{002}🌱 %F{002}test %k%F{000}%f " "$(build_left_prompt)" rm -fr /tmp/powerlevel9k-test cd - @@ -52,7 +52,7 @@ function testAwsEbEnvSegmentWorksIfElasticBeanstalkEnvironmentIsSetInParentDirec echo "test:\n environment: test" > /tmp/powerlevel9k-test/.elasticbeanstalk/config.yml cd /tmp/powerlevel9k-test/1/12/123/1234/12345 - assertEquals "%K{000} %F{002}🌱 %f%F{002}test %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{002}🌱 %F{002}test %k%F{000}%f " "$(build_left_prompt)" rm -fr /tmp/powerlevel9k-test cd - diff --git a/test/segments/background_jobs.spec b/test/segments/background_jobs.spec index 3d83e171f..558ad1aab 100755 --- a/test/segments/background_jobs.spec +++ b/test/segments/background_jobs.spec @@ -34,7 +34,7 @@ function testBackgroundJobsSegmentWorksWithOneBackgroundJob() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{006}⚙%f %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{006}⚙ %k%F{000}%f " "$(build_left_prompt)" unfunction jobs } @@ -52,7 +52,7 @@ function testBackgroundJobsSegmentWorksWithMultipleBackgroundJobs() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{006}⚙%f %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{006}⚙ %k%F{000}%f " "$(build_left_prompt)" unfunction jobs } @@ -70,7 +70,7 @@ function testBackgroundJobsSegmentWithVerboseMode() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{006}⚙ %f%F{006}3 %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{006}⚙ %F{006}3 %k%F{000}%f " "$(build_left_prompt)" unfunction jobs } diff --git a/test/segments/battery.spec b/test/segments/battery.spec index 79e25d6f7..39437b7f7 100755 --- a/test/segments/battery.spec +++ b/test/segments/battery.spec @@ -69,7 +69,7 @@ function testBatterySegmentIfBatteryIsLowWhileDischargingOnOSX() { makeBatterySay "Now drawing from 'Battery Power' -InternalBattery-0 (id=1234567) 4%; discharging; 0:05 remaining present: true" - assertEquals "%K{000} %F{001}🔋 %f%F{001}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{001}🔋 %F{001}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsLowWhileChargingOnOSX() { @@ -77,7 +77,7 @@ function testBatterySegmentIfBatteryIsLowWhileChargingOnOSX() { makeBatterySay "Now drawing from 'Battery Power' -InternalBattery-0 (id=1234567) 4%; charging; 0:05 remaining present: true" - assertEquals "%K{000} %F{003}🔋 %f%F{003}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{003}🔋 %F{003}4%% (0:05) " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsAlmostFullWhileDischargingOnOSX() { @@ -85,7 +85,7 @@ function testBatterySegmentIfBatteryIsAlmostFullWhileDischargingOnOSX() { makeBatterySay "Now drawing from 'Battery Power' -InternalBattery-0 (id=1234567) 98%; discharging; 3:57 remaining present: true" - assertEquals "%K{000} %F{007}🔋 %f%F{007}98%% (3:57) " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{007}🔋 %F{007}98%% (3:57) " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsAlmostFullWhileChargingOnOSX() { @@ -93,7 +93,7 @@ function testBatterySegmentIfBatteryIsAlmostFullWhileChargingOnOSX() { makeBatterySay "Now drawing from 'Battery Power' -InternalBattery-0 (id=1234567) 98%; charging; 3:57 remaining present: true" - assertEquals "%K{000} %F{003}🔋 %f%F{003}98%% (3:57) " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{003}🔋 %F{003}98%% (3:57) " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsFullOnOSX() { @@ -101,7 +101,7 @@ function testBatterySegmentIfBatteryIsFullOnOSX() { makeBatterySay "Now drawing from 'AC Power' -InternalBattery-0 (id=1234567) 99%; charged; 0:00 remaining present: true" - assertEquals "%K{000} %F{002}🔋 %f%F{002}99%% " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{002}🔋 %F{002}99%% " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsCalculatingOnOSX() { @@ -109,42 +109,42 @@ function testBatterySegmentIfBatteryIsCalculatingOnOSX() { makeBatterySay "Now drawing from 'Battery Power' -InternalBattery-0 (id=1234567) 99%; discharging; (no estimate) present: true" - assertEquals "%K{000} %F{007}🔋 %f%F{007}99%% (...) " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{007}🔋 %F{007}99%% (...) " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsLowWhileDischargingOnLinux() { local OS='Linux' # Fake Linux makeBatterySay "4" "Discharging" - assertEquals "%K{000} %F{001}🔋 %f%F{001}4%% " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{001}🔋 %F{001}4%% " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsLowWhileChargingOnLinux() { local OS='Linux' # Fake Linux makeBatterySay "4" "Charging" - assertEquals "%K{000} %F{003}🔋 %f%F{003}4%% " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{003}🔋 %F{003}4%% " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsNormalWhileDischargingOnLinux() { local OS='Linux' # Fake Linux makeBatterySay "10" "Discharging" - assertEquals "%K{000} %F{007}🔋 %f%F{007}10%% " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{007}🔋 %F{007}10%% " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsNormalWhileChargingOnLinux() { local OS='Linux' # Fake Linux makeBatterySay "10" "Charging" - assertEquals "%K{000} %F{003}🔋 %f%F{003}10%% " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{003}🔋 %F{003}10%% " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsFullOnLinux() { local OS='Linux' # Fake Linux makeBatterySay "100" "Full" - assertEquals "%K{000} %F{002}🔋 %f%F{002}100%% " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{002}🔋 %F{002}100%% " "$(prompt_battery left 1 false ${FOLDER})" } function testBatterySegmentIfBatteryIsNormalWithAcpiEnabledOnLinux() { @@ -155,7 +155,7 @@ function testBatterySegmentIfBatteryIsNormalWithAcpiEnabledOnLinux() { # For running on Mac, we need to mock date :( [[ -f /usr/local/bin/gdate ]] && alias date=gdate - assertEquals "%K{000} %F{007}🔋 %f%F{007}50%% (1:38) " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{007}🔋 %F{007}50%% (1:38) " "$(prompt_battery left 1 false ${FOLDER})" unalias date &>/dev/null # unaliasing date fails where it was never aliased (e.g. on Linux). @@ -171,7 +171,7 @@ function testBatterySegmentIfBatteryIsCalculatingWithAcpiEnabledOnLinux() { echo "echo 'Batter 0: Discharging, 50%, rate remaining'" > ${FOLDER}/usr/bin/acpi chmod +x ${FOLDER}/usr/bin/acpi - assertEquals "%K{000} %F{007}🔋 %f%F{007}50%% (...) " "$(prompt_battery left 1 false ${FOLDER})" + assertEquals "%K{000} %F{007}🔋 %F{007}50%% (...) " "$(prompt_battery left 1 false ${FOLDER})" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/custom.spec b/test/segments/custom.spec index 0f66c82f7..7aef02b0d 100755 --- a/test/segments/custom.spec +++ b/test/segments/custom.spec @@ -67,7 +67,7 @@ function testSettingVisualIdentifierForCustomSegment() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{007} %F{000}hw %f%F{000}world %k%F{007}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{000}hw %F{000}world %k%F{007}%f " "$(build_left_prompt)" } function testSettingVisualIdentifierForegroundColorForCustomSegment() { @@ -80,7 +80,7 @@ function testSettingVisualIdentifierForegroundColorForCustomSegment() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{007} %F{001}hw %f%F{000}world %k%F{007}%f " "$(build_left_prompt)" + assertEquals "%K{007} %F{001}hw %F{000}world %k%F{007}%f " "$(build_left_prompt)" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/disk_usage.spec b/test/segments/disk_usage.spec index ebafe31d3..7858da4fb 100755 --- a/test/segments/disk_usage.spec +++ b/test/segments/disk_usage.spec @@ -40,7 +40,7 @@ function testDiskUsageSegmentWhenDiskIsAlmostFull() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{001} %F{007}hdd %f%F{007}97%% %k%F{001}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{007}hdd %F{007}97%% %k%F{001}%f " "$(build_left_prompt)" unfunction df } @@ -56,7 +56,7 @@ function testDiskUsageSegmentWhenDiskIsVeryFull() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{003} %F{000}hdd %f%F{000}94%% %k%F{003}%f " "$(build_left_prompt)" + assertEquals "%K{003} %F{000}hdd %F{000}94%% %k%F{003}%f " "$(build_left_prompt)" unfunction df } @@ -72,7 +72,7 @@ function testDiskUsageSegmentWhenDiskIsQuiteEmpty() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{000} %F{003}hdd %f%F{003}4%% %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{003}hdd %F{003}4%% %k%F{000}%f " "$(build_left_prompt)" unfunction df } @@ -105,7 +105,7 @@ function testDiskUsageSegmentWarningLevelCouldBeAdjusted() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{003} %F{000}hdd %f%F{000}11%% %k%F{003}%f " "$(build_left_prompt)" + assertEquals "%K{003} %F{000}hdd %F{000}11%% %k%F{003}%f " "$(build_left_prompt)" unfunction df } @@ -123,7 +123,7 @@ function testDiskUsageSegmentCriticalLevelCouldBeAdjusted() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{001} %F{007}hdd %f%F{007}11%% %k%F{001}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{007}hdd %F{007}11%% %k%F{001}%f " "$(build_left_prompt)" unfunction df } diff --git a/test/segments/ip.spec b/test/segments/ip.spec index 254f11c92..cd9f727d8 100755 --- a/test/segments/ip.spec +++ b/test/segments/ip.spec @@ -68,7 +68,7 @@ function testIpSegmentWorksOnOsxWithNoInterfaceSpecified() { source powerlevel9k.zsh-theme local OS='OSX' # Fake OSX - assertEquals "%K{006} %F{000}IP %f%F{000}1.2.3.4 %k%F{006}%f " "$(build_left_prompt)" + assertEquals "%K{006} %F{000}IP %F{000}1.2.3.4 %k%F{006}%f " "$(build_left_prompt)" unalias ipconfig unalias networksetup @@ -123,7 +123,7 @@ function testIpSegmentWorksOnOsxWithMultipleInterfacesSpecified() { source powerlevel9k.zsh-theme local OS='OSX' # Fake OSX - assertEquals "%K{006} %F{000}IP %f%F{000}1.2.3.4 %k%F{006}%f " "$(build_left_prompt)" + assertEquals "%K{006} %F{000}IP %F{000}1.2.3.4 %k%F{006}%f " "$(build_left_prompt)" unfunction ipconfig unalias networksetup @@ -139,7 +139,7 @@ function testIpSegmentWorksOnOsxWithInterfaceSpecified() { source powerlevel9k.zsh-theme local OS='OSX' # Fake OSX - assertEquals "%K{006} %F{000}IP %f%F{000}1.2.3.4 %k%F{006}%f " "$(build_left_prompt)" + assertEquals "%K{006} %F{000}IP %F{000}1.2.3.4 %k%F{006}%f " "$(build_left_prompt)" unalias ipconfig } @@ -169,7 +169,7 @@ function testIpSegmentWorksOnLinuxWithNoInterfaceSpecified() { source powerlevel9k.zsh-theme local OS='Linux' # Fake Linux - assertEquals "%K{006} %F{000}IP %f%F{000}10.0.2.15 %k%F{006}%f " "$(build_left_prompt)" + assertEquals "%K{006} %F{000}IP %F{000}10.0.2.15 %k%F{006}%f " "$(build_left_prompt)" unfunction ip } @@ -204,7 +204,7 @@ function testIpSegmentWorksOnLinuxWithMultipleInterfacesSpecified() { source powerlevel9k.zsh-theme local OS='Linux' # Fake Linux - assertEquals "%K{006} %F{000}IP %f%F{000}10.0.2.15 %k%F{006}%f " "$(build_left_prompt)" + assertEquals "%K{006} %F{000}IP %F{000}10.0.2.15 %k%F{006}%f " "$(build_left_prompt)" unfunction ip } @@ -223,7 +223,7 @@ inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 source powerlevel9k.zsh-theme local OS='Linux' # Fake Linux - assertEquals "%K{006} %F{000}IP %f%F{000}10.0.2.15 %k%F{006}%f " "$(build_left_prompt)" + assertEquals "%K{006} %F{000}IP %F{000}10.0.2.15 %k%F{006}%f " "$(build_left_prompt)" unfunction ip } diff --git a/test/segments/load.spec b/test/segments/load.spec index 0f8ee3329..5867b4195 100755 --- a/test/segments/load.spec +++ b/test/segments/load.spec @@ -42,7 +42,7 @@ function testLoadSegmentWorksOnOsx() { source ${P9K_HOME}/powerlevel9k.zsh-theme local OS="OSX" # Fake OSX - assertEquals "%K{002} %F{000}L %f%F{000}1.38 " "$(prompt_load left 1 false ${FOLDER})" + assertEquals "%K{002} %F{000}L %F{000}1.38 " "$(prompt_load left 1 false ${FOLDER})" unfunction sysctl } @@ -64,7 +64,7 @@ function testLoadSegmentWorksOnBsd() { source ${P9K_HOME}/powerlevel9k.zsh-theme local OS="BSD" # Fake BSD - assertEquals "%K{002} %F{000}L %f%F{000}1.38 " "$(prompt_load left 1 false ${FOLDER})" + assertEquals "%K{002} %F{000}L %F{000}1.38 " "$(prompt_load left 1 false ${FOLDER})" unfunction sysctl } @@ -81,7 +81,7 @@ function testLoadSegmentWorksOnLinux() { source ${P9K_HOME}/powerlevel9k.zsh-theme local OS="Linux" # Fake Linux - assertEquals "%K{002} %F{000}L %f%F{000}1.38 " "$(prompt_load left 1 false ${FOLDER})" + assertEquals "%K{002} %F{000}L %F{000}1.38 " "$(prompt_load left 1 false ${FOLDER})" unalias nproc } @@ -101,7 +101,7 @@ function testLoadSegmentNormalState() { source ${P9K_HOME}/powerlevel9k.zsh-theme local OS="Linux" # Fake Linux - assertEquals "%K{002} %F{000}L %f%F{000}1.00 " "$(prompt_load left 1 false ${FOLDER})" + assertEquals "%K{002} %F{000}L %F{000}1.00 " "$(prompt_load left 1 false ${FOLDER})" unalias nproc } @@ -121,7 +121,7 @@ function testLoadSegmentWarningState() { source ${P9K_HOME}/powerlevel9k.zsh-theme local OS="Linux" # Fake Linux - assertEquals "%K{003} %F{000}L %f%F{000}2.01 " "$(prompt_load left 1 false ${FOLDER})" + assertEquals "%K{003} %F{000}L %F{000}2.01 " "$(prompt_load left 1 false ${FOLDER})" unalias nproc } @@ -141,7 +141,7 @@ function testLoadSegmentCriticalState() { source ${P9K_HOME}/powerlevel9k.zsh-theme local OS="Linux" # Fake Linux - assertEquals "%K{001} %F{000}L %f%F{000}2.81 " "$(prompt_load left 1 false ${FOLDER})" + assertEquals "%K{001} %F{000}L %F{000}2.81 " "$(prompt_load left 1 false ${FOLDER})" unalias nproc } diff --git a/test/segments/node_version.spec b/test/segments/node_version.spec index 69b9cbb7f..764bfda2d 100755 --- a/test/segments/node_version.spec +++ b/test/segments/node_version.spec @@ -33,7 +33,7 @@ function testNodeVersionSegmentWorks() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{002} %F{007}⬢ %f%F{007}1.2.3 %k%F{002}%f " "$(build_left_prompt)" + assertEquals "%K{002} %F{007}⬢ %F{007}1.2.3 %k%F{002}%f " "$(build_left_prompt)" unfunction node } diff --git a/test/segments/nodeenv.spec b/test/segments/nodeenv.spec index 2e9d779e0..3764f1f06 100755 --- a/test/segments/nodeenv.spec +++ b/test/segments/nodeenv.spec @@ -73,7 +73,7 @@ function testNodeenvSegmentPrintsAtLeastNodeEnvWithoutNode() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{002}⬢ %f%F{002}[node-env] %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{002}⬢ %F{002}[node-env] %k%F{000}%f " "$(build_left_prompt)" unset NODE_VIRTUAL_ENV unalias node @@ -90,7 +90,7 @@ function testNodeenvSegmentWorks() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{002}⬢ %f%F{002}v1.2.3[node-env] %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{002}⬢ %F{002}v1.2.3[node-env] %k%F{000}%f " "$(build_left_prompt)" unfunction node unset NODE_VIRTUAL_ENV diff --git a/test/segments/nvm.spec b/test/segments/nvm.spec index c9ed430d2..b53bf22e3 100755 --- a/test/segments/nvm.spec +++ b/test/segments/nvm.spec @@ -51,7 +51,7 @@ function testNvmSegmentWorksWithoutHavingADefaultAlias() { [[ ${1} == 'current' ]] && echo 'v4.6.0' || echo 'v1.4.0' } - assertEquals "%K{005} %F{000}⬢ %f%F{000}4.6.0 %k%F{005}%f " "$(build_left_prompt)" + assertEquals "%K{005} %F{000}⬢ %F{000}4.6.0 %k%F{005}%f " "$(build_left_prompt)" } function testNvmSegmentPrintsNothingWhenOnDefaultVersion() { diff --git a/test/segments/ram.spec b/test/segments/ram.spec index 2c9f16934..292c784b3 100755 --- a/test/segments/ram.spec +++ b/test/segments/ram.spec @@ -36,7 +36,7 @@ Pages inactive: 1313411. source ${P9K_HOME}/powerlevel9k.zsh-theme local OS="OSX" # Fake OSX - assertEquals "%K{003} %F{000}RAM %f%F{000}6.15G " "$(prompt_ram left 1 false ${FOLDER})" + assertEquals "%K{003} %F{000}RAM %F{000}6.15G " "$(prompt_ram left 1 false ${FOLDER})" unalias vm_stat } @@ -49,7 +49,7 @@ function testRamSegmentWorksOnBsd() { source ${P9K_HOME}/powerlevel9k.zsh-theme local OS="BSD" # Fake BSD - assertEquals "%K{003} %F{000}RAM %f%F{000}0.29M " "$(prompt_ram left 1 false ${FOLDER})" + assertEquals "%K{003} %F{000}RAM %F{000}0.29M " "$(prompt_ram left 1 false ${FOLDER})" } function testRamSegmentWorksOnLinux() { @@ -60,7 +60,7 @@ function testRamSegmentWorksOnLinux() { source ${P9K_HOME}/powerlevel9k.zsh-theme local OS="Linux" # Fake Linux - assertEquals "%K{003} %F{000}RAM %f%F{000}0.29G " "$(prompt_ram left 1 false ${FOLDER})" + assertEquals "%K{003} %F{000}RAM %F{000}0.29G " "$(prompt_ram left 1 false ${FOLDER})" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/ssh.spec b/test/segments/ssh.spec index 3245231f0..40723ebde 100755 --- a/test/segments/ssh.spec +++ b/test/segments/ssh.spec @@ -37,7 +37,7 @@ function testSshSegmentWorksIfOnlySshClientIsSet() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{003}ssh-icon%f %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{003}ssh-icon %k%F{000}%f " "$(build_left_prompt)" unset SSH_CLIENT } @@ -54,7 +54,7 @@ function testSshSegmentWorksIfOnlySshTtyIsSet() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{003}ssh-icon%f %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{003}ssh-icon %k%F{000}%f " "$(build_left_prompt)" unset SSH_TTY } @@ -71,7 +71,7 @@ function testSshSegmentWorksIfAllNecessaryVariablesAreSet() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{003}ssh-icon%f %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{003}ssh-icon %k%F{000}%f " "$(build_left_prompt)" unset SSH_TTY unset SSH_CLIENT diff --git a/test/segments/status.spec b/test/segments/status.spec index 9fb34e095..839f30abe 100755 --- a/test/segments/status.spec +++ b/test/segments/status.spec @@ -37,7 +37,7 @@ function testStatusWorksAsExpectedIfReturnCodeIsZeroAndVerboseIsSet() { # Load Powerlevel9k source powerlevel9k.zsh-theme - assertEquals "%K{000} %F{002}✔%f %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{002}✔ %k%F{000}%f " "$(build_left_prompt)" } function testStatusInGeneralErrorCase() { @@ -50,7 +50,7 @@ function testStatusInGeneralErrorCase() { source powerlevel9k.zsh-theme local RETVAL=1 - assertEquals "%K{001} %F{226}↵ %f%F{226}1 %k%F{001}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{226}↵ %F{226}1 %k%F{001}%f " "$(build_left_prompt)" } function testPipestatusInErrorCase() { @@ -64,7 +64,7 @@ function testPipestatusInErrorCase() { local -a RETVALS RETVALS=(0 0 1 0) - assertEquals "%K{001} %F{226}↵ %f%F{226}0|0|1|0 %k%F{001}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{226}↵ %F{226}0|0|1|0 %k%F{001}%f " "$(build_left_prompt)" } function testStatusCrossWinsOverVerbose() { @@ -78,7 +78,7 @@ function testStatusCrossWinsOverVerbose() { source powerlevel9k.zsh-theme local RETVAL=1 - assertEquals "%K{000} %F{001}✘%f %k%F{000}%f " "$(build_left_prompt)" + assertEquals "%K{000} %F{001}✘ %k%F{000}%f " "$(build_left_prompt)" } function testStatusShowsSignalNameInErrorCase() { @@ -92,7 +92,7 @@ function testStatusShowsSignalNameInErrorCase() { source powerlevel9k.zsh-theme local RETVAL=132 - assertEquals "%K{001} %F{226}↵ %f%F{226}SIGILL(4) %k%F{001}%f " "$(build_left_prompt)" + assertEquals "%K{001} %F{226}↵ %F{226}SIGILL(4) %k%F{001}%f " "$(build_left_prompt)" } function testStatusSegmentIntegrated() { @@ -107,7 +107,7 @@ function testStatusSegmentIntegrated() { false; powerlevel9k_prepare_prompts - assertEquals "%f%b%k%K{000} %F{001}✘%f %k%F{000}%f " "${(e)PROMPT}" + assertEquals "%f%b%k%K{000} %F{001}✘ %k%F{000}%f " "${(e)PROMPT}" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/swap.spec b/test/segments/swap.spec index 7db5416b6..07b254be8 100755 --- a/test/segments/swap.spec +++ b/test/segments/swap.spec @@ -36,7 +36,7 @@ function testSwapSegmentWorksOnOsx() { source ${P9K_HOME}/powerlevel9k.zsh-theme local OS="OSX" # Fake OSX - assertEquals "%K{003} %F{000}SWP %f%F{000}1.58G " "$(prompt_swap left 1 false ${FOLDER})" + assertEquals "%K{003} %F{000}SWP %F{000}1.58G " "$(prompt_swap left 1 false ${FOLDER})" unfunction sysctl } @@ -52,7 +52,7 @@ function testSwapSegmentWorksOnLinux() { source ${P9K_HOME}/powerlevel9k.zsh-theme local OS="Linux" # Fake Linux - assertEquals "%K{003} %F{000}SWP %f%F{000}0.95G " "$(prompt_swap left 1 false ${FOLDER})" + assertEquals "%K{003} %F{000}SWP %F{000}0.95G " "$(prompt_swap left 1 false ${FOLDER})" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/swift_version.spec b/test/segments/swift_version.spec index 47fc0b7f2..57a2ef7bc 100755 --- a/test/segments/swift_version.spec +++ b/test/segments/swift_version.spec @@ -49,7 +49,7 @@ function testSwiftSegmentWorks() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{005} %F{007}Swift %f%F{007}3.0.1 %k%F{005}%f " "$(build_left_prompt)" + assertEquals "%K{005} %F{007}Swift %F{007}3.0.1 %k%F{005}%f " "$(build_left_prompt)" unfunction swift } diff --git a/test/segments/todo.spec b/test/segments/todo.spec index 875c45f85..21da2a92d 100755 --- a/test/segments/todo.spec +++ b/test/segments/todo.spec @@ -52,7 +52,7 @@ function testTodoSegmentWorksAsExpected() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{244} %F{000}☑ %f%F{000}100 %k%F{244}%f " "$(build_left_prompt)" + assertEquals "%K{244} %F{000}☑ %F{000}100 %k%F{244}%f " "$(build_left_prompt)" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/vcs-git.spec b/test/segments/vcs-git.spec index bddecf6c9..3c694d121 100755 --- a/test/segments/vcs-git.spec +++ b/test/segments/vcs-git.spec @@ -117,7 +117,7 @@ function testGitIconWorks() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{002} %F{000}Git-Icon %f%F{000} master %k%F{002}%f " "$(build_left_prompt)" + assertEquals "%K{002} %F{000}Git-Icon %F{000} master %k%F{002}%f " "$(build_left_prompt)" } function testGitlabIconWorks() { @@ -132,7 +132,7 @@ function testGitlabIconWorks() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{002} %F{000}GL-Icon %f%F{000} master %k%F{002}%f " "$(build_left_prompt)" + assertEquals "%K{002} %F{000}GL-Icon %F{000} master %k%F{002}%f " "$(build_left_prompt)" } function testBitbucketIconWorks() { @@ -147,7 +147,7 @@ function testBitbucketIconWorks() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{002} %F{000}BB-Icon %f%F{000} master %k%F{002}%f " "$(build_left_prompt)" + assertEquals "%K{002} %F{000}BB-Icon %F{000} master %k%F{002}%f " "$(build_left_prompt)" } function testGitHubIconWorks() { @@ -162,7 +162,7 @@ function testGitHubIconWorks() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{002} %F{000}GH-Icon %f%F{000} master %k%F{002}%f " "$(build_left_prompt)" + assertEquals "%K{002} %F{000}GH-Icon %F{000} master %k%F{002}%f " "$(build_left_prompt)" } function testUntrackedFilesIconWorks() { diff --git a/test/segments/vcs-hg.spec b/test/segments/vcs-hg.spec index 2903f5446..506bc0780 100755 --- a/test/segments/vcs-hg.spec +++ b/test/segments/vcs-hg.spec @@ -189,7 +189,7 @@ function testMercurialIconWorks() { # Load Powerlevel9k source ${P9K_HOME}/powerlevel9k.zsh-theme - assertEquals "%K{002} %F{000}HG-Icon %f%F{000} default %k%F{002}%f " "$(build_left_prompt)" + assertEquals "%K{002} %F{000}HG-Icon %F{000} default %k%F{002}%f " "$(build_left_prompt)" } function testBookmarkIconWorks() { From d1cd83bf0bd150c72e86de2f7b34e86f7865286d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 7 Oct 2018 00:01:45 +0200 Subject: [PATCH 05/79] Fix tests It seems like Travis changed their infrastructure. We need to unset SSH_TTY and SSH_CLIENT to get the tests working again. --- test/segments/context.spec | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/segments/context.spec b/test/segments/context.spec index 073003702..4dec526ab 100755 --- a/test/segments/context.spec +++ b/test/segments/context.spec @@ -21,6 +21,11 @@ function tearDown() { } function testContextSegmentDoesNotGetRenderedWithDefaultUser() { + # Fix leaked state for travis + unset POWERLEVEL9K_CONTEXT_ALWAYS_SHOW + unset SSH_CLIENT + unset SSH_TTY + local DEFAULT_USER=$(whoami) local POWERLEVEL9K_CUSTOM_WORLD='echo world' local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS @@ -99,6 +104,11 @@ function testContextSegmentIsShownIfDefaultUserIsSetWhenForced() { } function testContextSegmentIsShownIfForced() { + # Fix leaked state for travis + unset POWERLEVEL9K_CONTEXT_ALWAYS_SHOW + unset SSH_CLIENT + unset SSH_TTY + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context) local POWERLEVEL9K_ALWAYS_SHOW_USER=true From d831f12126374b0d1ba2207e24fa9749e795779f Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 7 Oct 2018 07:45:02 +0200 Subject: [PATCH 06/79] Do not throw away users configuration --- test/segments/context.spec | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/test/segments/context.spec b/test/segments/context.spec index 4dec526ab..25c355a75 100755 --- a/test/segments/context.spec +++ b/test/segments/context.spec @@ -11,21 +11,34 @@ function setUp() { # Test specific settings OLD_DEFAULT_USER=$DEFAULT_USER unset DEFAULT_USER + + # Fix leaked state for travis + OLD_POWERLEVEL9K_CONTEXT_ALWAYS_SHOW=$POWERLEVEL9K_CONTEXT_ALWAYS_SHOW + unset POWERLEVEL9K_CONTEXT_ALWAYS_SHOW + OLD_SSH_CLIENT=$SSH_CLIENT + unset SSH_CLIENT + OLD_SSH_TTY=$SSH_TTY + unset SSH_TTY } function tearDown() { # Restore old variables [[ -n "$OLD_DEFAULT_USER" ]] && DEFAULT_USER=$OLD_DEFAULT_USER + unset OLD_DEFAULT_USER + + [[ -n "$OLD_POWERLEVEL9K_CONTEXT_ALWAYS_SHOW" ]] && POWERLEVEL9K_CONTEXT_ALWAYS_SHOW=$OLD_POWERLEVEL9K_CONTEXT_ALWAYS_SHOW + unset OLD_POWERLEVEL9K_CONTEXT_ALWAYS_SHOW + + [[ -n "$OLD_SSH_CLIENT" ]] && SSH_CLIENT=$OLD_SSH_CLIENT + unset OLD_SSH_CLIENT + + [[ -n "$OLD_SSH_TTY" ]] && SSH_TTY=$OLD_SSH_TTY + unset OLD_SSH_TTY return 0 } function testContextSegmentDoesNotGetRenderedWithDefaultUser() { - # Fix leaked state for travis - unset POWERLEVEL9K_CONTEXT_ALWAYS_SHOW - unset SSH_CLIENT - unset SSH_TTY - local DEFAULT_USER=$(whoami) local POWERLEVEL9K_CUSTOM_WORLD='echo world' local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS @@ -104,11 +117,6 @@ function testContextSegmentIsShownIfDefaultUserIsSetWhenForced() { } function testContextSegmentIsShownIfForced() { - # Fix leaked state for travis - unset POWERLEVEL9K_CONTEXT_ALWAYS_SHOW - unset SSH_CLIENT - unset SSH_TTY - local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context) local POWERLEVEL9K_ALWAYS_SHOW_USER=true From dc731f10e6314922c08b3cfe9f060559ed87b921 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 25 Oct 2018 08:17:29 +0200 Subject: [PATCH 07/79] Make truncate with package name work without setting shorten length --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 3c3303faf..c8a984743 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -803,7 +803,7 @@ prompt_dir() { # if we are not in "~" or "/", split the paths into an array and exclude "~" (( ${#current_path} > 1 )) && paths=(${(s:/:)${current_path//"~\/"/}}) || paths=() # only run the code if SHORTEN_DIR_LENGTH is set, or we are using the two strategies that don't rely on it. - if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_to_last" ]]; then + if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_to_last" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_package_name" ]]; then set_default POWERLEVEL9K_SHORTEN_DELIMITER "\u2026" # convert delimiter from unicode to literal character, so that we can get the correct length later local delim=$(echo -n $POWERLEVEL9K_SHORTEN_DELIMITER) From 993de7aef93ecdab1c3046d185656e4200b77d76 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 25 Oct 2018 18:48:37 +0200 Subject: [PATCH 08/79] Fix vpn_ip segment --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 3c3303faf..416530771 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1134,7 +1134,7 @@ prompt_ip() { set_default POWERLEVEL9K_VPN_IP_INTERFACE "tun" # prompt if vpn active prompt_vpn_ip() { - for vpn_iface in $(/sbin/ifconfig | grep -e ^"$POWERLEVEL9K_VPN_IP_INTERFACE" | cut -d":" -f1) + for vpn_iface in $(/sbin/ifconfig | grep -e "^${POWERLEVEL9K_VPN_IP_INTERFACE}" | cut -d":" -f1) do ip=$(/sbin/ifconfig "$vpn_iface" | grep -o "inet\s.*" | cut -d' ' -f2) "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'VPN_ICON' From cd0ad84b0100ca14ddb30d93a53094c0e9343e40 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 3 Nov 2018 03:06:49 +0100 Subject: [PATCH 09/79] Get rid of wc dependency when showing ahead/behind info --- functions/vcs.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index b99e7c863..1478e0e25 100755 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -33,12 +33,12 @@ function +vi-git-aheadbehind() { # for git prior to 1.7 # ahead=$(command git rev-list origin/${branch_name}..HEAD | wc -l) - ahead=$(command git rev-list "${branch_name}"@{upstream}..HEAD 2>/dev/null | wc -l) + ahead=$(command git rev-list --count "${branch_name}"@{upstream}..HEAD 2>/dev/null) (( ahead )) && gitstatus+=( " $(print_icon 'VCS_OUTGOING_CHANGES_ICON')${ahead// /}" ) # for git prior to 1.7 # behind=$(command git rev-list HEAD..origin/${branch_name} | wc -l) - behind=$(command git rev-list HEAD.."${branch_name}"@{upstream} 2>/dev/null | wc -l) + behind=$(command git rev-list --count HEAD.."${branch_name}"@{upstream} 2>/dev/null) (( behind )) && gitstatus+=( " $(print_icon 'VCS_INCOMING_CHANGES_ICON')${behind// /}" ) hook_com[misc]+=${(j::)gitstatus} From fea5f616d17b11446a48327b6719180adf577425 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 3 Nov 2018 03:08:32 +0100 Subject: [PATCH 10/79] Get branch name from VCS_INFO subsystem when collecting ahead/behind info --- functions/vcs.zsh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 1478e0e25..50a77d49a 100755 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -26,19 +26,17 @@ function +vi-git-untracked() { } function +vi-git-aheadbehind() { - local ahead behind branch_name + local ahead behind local -a gitstatus - branch_name=$(command git symbolic-ref --short HEAD 2>/dev/null) - # for git prior to 1.7 - # ahead=$(command git rev-list origin/${branch_name}..HEAD | wc -l) - ahead=$(command git rev-list --count "${branch_name}"@{upstream}..HEAD 2>/dev/null) + # ahead=$(command git rev-list origin/${hook_com[branch]}..HEAD | wc -l) + ahead=$(command git rev-list --count "${hook_com[branch]}"@{upstream}..HEAD 2>/dev/null) (( ahead )) && gitstatus+=( " $(print_icon 'VCS_OUTGOING_CHANGES_ICON')${ahead// /}" ) # for git prior to 1.7 - # behind=$(command git rev-list HEAD..origin/${branch_name} | wc -l) - behind=$(command git rev-list --count HEAD.."${branch_name}"@{upstream} 2>/dev/null) + # behind=$(command git rev-list HEAD..origin/${hook_com[branch]} | wc -l) + behind=$(command git rev-list --count HEAD.."${hook_com[branch]}"@{upstream} 2>/dev/null) (( behind )) && gitstatus+=( " $(print_icon 'VCS_INCOMING_CHANGES_ICON')${behind// /}" ) hook_com[misc]+=${(j::)gitstatus} From 9a67ca5bc37a0dc6a397e59fb89b8565fcb468c4 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 3 Nov 2018 03:10:53 +0100 Subject: [PATCH 11/79] Get branch name from VCS_INFO subsystem when collecting remote branch --- functions/vcs.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 50a77d49a..23b2b661c 100755 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -43,11 +43,11 @@ function +vi-git-aheadbehind() { } function +vi-git-remotebranch() { - local remote branch_name + local remote + local branch_name="${hook_com[branch]}" # Are we on a remote-tracking branch? remote=${$(command git rev-parse --verify HEAD@{upstream} --symbolic-full-name 2>/dev/null)/refs\/(remotes|heads)\/} - branch_name=$(command git symbolic-ref --short HEAD 2>/dev/null) if [[ -n "$POWERLEVEL9K_VCS_SHORTEN_LENGTH" ]] && [[ -n "$POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH" ]]; then set_default POWERLEVEL9K_VCS_SHORTEN_DELIMITER $'\U2026' From d07507c1ebf60d1d71ba491d0358b312e3e44807 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 3 Nov 2018 03:11:51 +0100 Subject: [PATCH 12/79] Make use of git dir determined by VCS_INFO subsystem instead of determine the git dir manually. --- functions/vcs.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 23b2b661c..cfc62a6d9 100755 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -104,7 +104,7 @@ function +vi-git-tagname() { function +vi-git-stash() { local -a stashes - if [[ -s $(command git rev-parse --git-dir)/refs/stash ]] ; then + if [[ -s "${vcs_comm[gitdir]}/refs/stash" ]] ; then stashes=$(command git stash list 2>/dev/null | wc -l) hook_com[misc]+=" $(print_icon 'VCS_STASH_ICON')${stashes// /}" fi From 44b4b669258f0854e17e439337a8a8fdf1dea5df Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 3 Nov 2018 03:21:47 +0100 Subject: [PATCH 13/79] Speedup VCS segment Now the untracked files are detected via `git ls-files`, which is much faster than `git status`. Additionally, we flipped the default for checking submodules. They are now NOT checked by default, as most users probably do not use git submodules. --- functions/vcs.zsh | 16 +++++----------- test/segments/vcs-git.spec | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index cfc62a6d9..6cc467d75 100755 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -6,18 +6,12 @@ # https://github.com/bhilburn/powerlevel9k ################################################################ -set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY true +set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY false function +vi-git-untracked() { - # TODO: check git >= 1.7.2 - see function git_compare_version() - local FLAGS - FLAGS=('--porcelain') - - if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "false" ]]; then - FLAGS+='--ignore-submodules=dirty' - fi - - if [[ $(command git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' && \ - -n $(command git status ${FLAGS} | \grep -E '^\?\?' 2> /dev/null | tail -n1) ]]; then + if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" && "$(command git submodule foreach 'git ls-files --others --exclude-standard')" != "" ]]; then + hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" + VCS_WORKDIR_HALF_DIRTY=true + elif [[ "$(command git ls-files --others --exclude-standard)" != "" ]]; then hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" VCS_WORKDIR_HALF_DIRTY=true else diff --git a/test/segments/vcs-git.spec b/test/segments/vcs-git.spec index bddecf6c9..21bdc892c 100755 --- a/test/segments/vcs-git.spec +++ b/test/segments/vcs-git.spec @@ -375,4 +375,29 @@ function testShorteningCommitHashIsNotShownIfShowChangesetIsFalse() { assertEquals "%K{002} %F{000} master %k%F{002}%f " "$(build_left_prompt)" } +function testDetectingUntrackedFilesInSubmodulesWork() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true" + unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND + + mkdir ../submodule + cd ../submodule + git init 1>/dev/null + touch "i-am-tracked.txt" + git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null + # Create untracked file + touch "i-am-untracked.txt" + + local submodulePath="${PWD}" + + cd - + git submodule add "${submodulePath}" 2>/dev/null + git commit -m "Add submodule" 1>/dev/null + + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" +} + source shunit2/shunit2 \ No newline at end of file From c3f9d04354b53dd88bcaff790fca371b810054d6 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 3 Nov 2018 03:23:23 +0100 Subject: [PATCH 14/79] When checking for untracked or modified files, take submodules into account --- functions/vcs.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 6cc467d75..3b3b938f5 100755 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -8,7 +8,7 @@ set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY false function +vi-git-untracked() { - if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" && "$(command git submodule foreach 'git ls-files --others --exclude-standard')" != "" ]]; then + if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" && "$(command git submodule foreach --quiet --recursive 'git ls-files --others --exclude-standard')" != "" ]]; then hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" VCS_WORKDIR_HALF_DIRTY=true elif [[ "$(command git ls-files --others --exclude-standard)" != "" ]]; then From 9d84e6fb6a87748b48056cab46f505fa32cbbfa1 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 3 Nov 2018 03:45:05 +0100 Subject: [PATCH 15/79] Add tests for complex git submodule scenarios --- test/segments/vcs-git.spec | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/test/segments/vcs-git.spec b/test/segments/vcs-git.spec index 21bdc892c..fed1df191 100755 --- a/test/segments/vcs-git.spec +++ b/test/segments/vcs-git.spec @@ -386,8 +386,35 @@ function testDetectingUntrackedFilesInSubmodulesWork() { git init 1>/dev/null touch "i-am-tracked.txt" git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null + + local submodulePath="${PWD}" + + cd - + git submodule add "${submodulePath}" 2>/dev/null + git commit -m "Add submodule" 1>/dev/null + + # Go into checked-out submodule path + cd submodule # Create untracked file touch "i-am-untracked.txt" + cd - + + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" +} + +function testDetectinUntrackedFilesInMainRepoWithDirtySubmodulesWork() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true" + unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND + + mkdir ../submodule + cd ../submodule + git init 1>/dev/null + touch "i-am-tracked.txt" + git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null local submodulePath="${PWD}" @@ -395,6 +422,52 @@ function testDetectingUntrackedFilesInSubmodulesWork() { git submodule add "${submodulePath}" 2>/dev/null git commit -m "Add submodule" 1>/dev/null + # Create untracked file + touch "i-am-untracked.txt" + + source ${P9K_HOME}/powerlevel9k.zsh-theme + + assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" +} + +function testDetectingUntrackedFilesInNestedSubmodulesWork() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true" + unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND + + local mainRepo="${PWD}" + + mkdir ../submodule + cd ../submodule + git init 1>/dev/null + touch "i-am-tracked.txt" + git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null + + local submodulePath="${PWD}" + + mkdir ../subsubmodule + cd ../subsubmodule + git init 1>/dev/null + touch "i-am-tracked-too.txt" + git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null + + local subsubmodulePath="${PWD}" + + cd "${submodulePath}" + git submodule add "${subsubmodulePath}" 2>/dev/null + git commit -m "Add subsubmodule" 1>/dev/null + cd "${mainRepo}" + git submodule add "${submodulePath}" 2>/dev/null + git commit -m "Add submodule" 1>/dev/null + + git submodule update --init --recursive 2>/dev/null + + cd submodule/subsubmodule + # Create untracked file + touch "i-am-untracked.txt" + cd - + source ${P9K_HOME}/powerlevel9k.zsh-theme assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" From 3d960a51692a40f99cbf3f4bcdbcb5aa11f0a1f5 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 5 Nov 2018 02:19:06 +0100 Subject: [PATCH 16/79] Protect users locale --- functions/icons.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/functions/icons.zsh b/functions/icons.zsh index d8661e6fc..28cbb7093 100755 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -13,6 +13,7 @@ # Initialize the icon list according to the user's `POWERLEVEL9K_MODE`. typeset -gAH icons +() { # add scope to protect the users locale and not overwrite LC_CTYPE! case $POWERLEVEL9K_MODE in 'flat'|'awesome-patched') # Awesome-Patched Font required! See: @@ -528,6 +529,7 @@ esac if [[ "$POWERLEVEL9K_HIDE_BRANCH_ICON" == true ]]; then icons[VCS_BRANCH_ICON]='' fi +} # Safety function for printing icons # Prints the named icon, or if that icon is undefined, the string name. From 48f0cc11effbeff3e8cc3c80736d789c78905083 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 6 Nov 2018 01:11:31 +0100 Subject: [PATCH 17/79] Get rid of externals when truncating branch name --- functions/vcs.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 3b3b938f5..2b1a7296a 100755 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -46,13 +46,13 @@ function +vi-git-remotebranch() { if [[ -n "$POWERLEVEL9K_VCS_SHORTEN_LENGTH" ]] && [[ -n "$POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH" ]]; then set_default POWERLEVEL9K_VCS_SHORTEN_DELIMITER $'\U2026' - if [ ${#hook_com[branch]} -gt $POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH ] && [ ${#hook_com[branch]} -gt $POWERLEVEL9K_VCS_SHORTEN_LENGTH ]; then + if [ ${#hook_com[branch]} -gt ${POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH} ] && [ ${#hook_com[branch]} -gt ${POWERLEVEL9K_VCS_SHORTEN_LENGTH} ]; then case "$POWERLEVEL9K_VCS_SHORTEN_STRATEGY" in truncate_middle) - hook_com[branch]="$(echo "${branch_name:0:$POWERLEVEL9K_VCS_SHORTEN_LENGTH}")$POWERLEVEL9K_VCS_SHORTEN_DELIMITER$(echo "${branch_name: -$POWERLEVEL9K_VCS_SHORTEN_LENGTH}")" + hook_com[branch]="${branch_name:0:$POWERLEVEL9K_VCS_SHORTEN_LENGTH}${POWERLEVEL9K_VCS_SHORTEN_DELIMITER}${branch_name: -$POWERLEVEL9K_VCS_SHORTEN_LENGTH}" ;; truncate_from_right) - hook_com[branch]="$(echo "${branch_name:0:$POWERLEVEL9K_VCS_SHORTEN_LENGTH}")$POWERLEVEL9K_VCS_SHORTEN_DELIMITER" + hook_com[branch]="${branch_name:0:$POWERLEVEL9K_VCS_SHORTEN_LENGTH}${POWERLEVEL9K_VCS_SHORTEN_DELIMITER}" ;; esac fi From 2038e2650cf40ce6ad6959a6fd5fa9c52863b2cb Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 6 Nov 2018 01:12:19 +0100 Subject: [PATCH 18/79] Avoid aliases --- functions/vcs.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 2b1a7296a..321a15027 100755 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -8,7 +8,7 @@ set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY false function +vi-git-untracked() { - if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" && "$(command git submodule foreach --quiet --recursive 'git ls-files --others --exclude-standard')" != "" ]]; then + if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" && "$(command git submodule foreach --quiet --recursive 'command git ls-files --others --exclude-standard')" != "" ]]; then hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" VCS_WORKDIR_HALF_DIRTY=true elif [[ "$(command git ls-files --others --exclude-standard)" != "" ]]; then From 3256258ebfc04f34116b84b0af83e27e2dfb7400 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 11 Nov 2018 23:08:40 +0100 Subject: [PATCH 19/79] Count stashes via ZSH --- functions/vcs.zsh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 321a15027..bb877bec7 100755 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -96,11 +96,9 @@ function +vi-git-tagname() { # Show count of stashed changes # Port from https://github.com/whiteinge/dotfiles/blob/5dfd08d30f7f2749cfc60bc55564c6ea239624d9/.zsh_shouse_prompt#L268 function +vi-git-stash() { - local -a stashes - - if [[ -s "${vcs_comm[gitdir]}/refs/stash" ]] ; then - stashes=$(command git stash list 2>/dev/null | wc -l) - hook_com[misc]+=" $(print_icon 'VCS_STASH_ICON')${stashes// /}" + if [[ -s "${vcs_comm[gitdir]}/logs/refs/stash" ]] ; then + local -a stashes=( "${(@f)"$(<${vcs_comm[gitdir]}/logs/refs/stash)"}" ) + hook_com[misc]+=" $(print_icon 'VCS_STASH_ICON')${#stashes}" fi } From a90258a9ee6f2aa6e8b7d54c85499756fe5b4003 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 11 Nov 2018 23:17:33 +0100 Subject: [PATCH 20/79] Avoid warning when inside of .git dir We cannot detect untracked files when we are inside of a .git directory. --- functions/vcs.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index bb877bec7..d525f8150 100755 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -8,6 +8,8 @@ set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY false function +vi-git-untracked() { + [[ -z "${vcs_comm[gitdir]}" || "${vcs_comm[gitdir]}" == "." ]] && return + if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" && "$(command git submodule foreach --quiet --recursive 'command git ls-files --others --exclude-standard')" != "" ]]; then hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" VCS_WORKDIR_HALF_DIRTY=true From 645b9746772a977c7ae03d5ed1d990e5e3ee9f3e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 12 Nov 2018 00:13:35 +0100 Subject: [PATCH 21/79] Fix error if user cds into a .git directory In this case is was previously not possible to get the untracked status. Now we temporarily change the directory to the repo root folder and then get the list of untracked files. --- functions/vcs.zsh | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index d525f8150..321424c63 100755 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -8,17 +8,35 @@ set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY false function +vi-git-untracked() { - [[ -z "${vcs_comm[gitdir]}" || "${vcs_comm[gitdir]}" == "." ]] && return - - if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" && "$(command git submodule foreach --quiet --recursive 'command git ls-files --others --exclude-standard')" != "" ]]; then + [[ -z "${vcs_comm[gitdir]}" ]] && return + + # If we are in a repos root folder, vcs_comm[gitdir] yields ".git". + # Inside the .git dir itself (and not a subdir of it) the variable + # yields ".". In any other case (either a subdirectory of .git or + # the repo itself), the value of vcs_comm[gitdir] is the absolute + # path to the .git directory. + # Therefore we can step up a directory, if we are inside the .git + # folder. And in any other case, use the parent directory of the + # gitdir. + local repoDir="." + # Getting the parent dir of the current dir "." is still ".", so + # is is safe to do this always. + [[ "${vcs_comm[gitdir]}" != ".git" ]] && repoDir="${vcs_comm[gitdir]:h}" + [[ "${vcs_comm[gitdir]}" == "." ]] && repoDir=".." + + if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" && "$(cd ${repoDir} && command git submodule foreach --quiet --recursive 'command git ls-files --others --exclude-standard')" != "" ]]; then hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" VCS_WORKDIR_HALF_DIRTY=true - elif [[ "$(command git ls-files --others --exclude-standard)" != "" ]]; then + elif [[ "$(cd ${repoDir} && command git ls-files --others --exclude-standard)" != "" ]]; then hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" VCS_WORKDIR_HALF_DIRTY=true else VCS_WORKDIR_HALF_DIRTY=false fi + + # If we are in any other directory than the repo root, we want + # to go back a directory. + [[ "${vcs_comm[gitdir]}" != ".git" ]] && cd - >/dev/null } function +vi-git-aheadbehind() { From a6e60def4ba8b5f97e1ae4af8147a61b321d5dbf Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 12 Nov 2018 00:15:52 +0100 Subject: [PATCH 22/79] Fix stashes display Changing directories while checking for untracked files broke the display of git stashes. The hook was not called any more. This is why we disabled checking for untracked files within a .git folder. --- functions/vcs.zsh | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 321424c63..4cd778a44 100755 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -8,35 +8,19 @@ set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY false function +vi-git-untracked() { - [[ -z "${vcs_comm[gitdir]}" ]] && return - - # If we are in a repos root folder, vcs_comm[gitdir] yields ".git". - # Inside the .git dir itself (and not a subdir of it) the variable - # yields ".". In any other case (either a subdirectory of .git or - # the repo itself), the value of vcs_comm[gitdir] is the absolute - # path to the .git directory. - # Therefore we can step up a directory, if we are inside the .git - # folder. And in any other case, use the parent directory of the - # gitdir. - local repoDir="." - # Getting the parent dir of the current dir "." is still ".", so - # is is safe to do this always. - [[ "${vcs_comm[gitdir]}" != ".git" ]] && repoDir="${vcs_comm[gitdir]:h}" - [[ "${vcs_comm[gitdir]}" == "." ]] && repoDir=".." - - if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" && "$(cd ${repoDir} && command git submodule foreach --quiet --recursive 'command git ls-files --others --exclude-standard')" != "" ]]; then + [[ -z "${vcs_comm[gitdir]}" || "${vcs_comm[gitdir]}" == "." ]] && return + # If we are in a .git folder, do not check for untracked files. + [[ "${PWD:A}" =~ "\.git/" ]] && return + + if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" && "$(command git submodule foreach --quiet --recursive 'command git ls-files --others --exclude-standard')" != "" ]]; then hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" VCS_WORKDIR_HALF_DIRTY=true - elif [[ "$(cd ${repoDir} && command git ls-files --others --exclude-standard)" != "" ]]; then + elif [[ "$(command git ls-files --others --exclude-standard)" != "" ]]; then hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" VCS_WORKDIR_HALF_DIRTY=true else VCS_WORKDIR_HALF_DIRTY=false fi - - # If we are in any other directory than the repo root, we want - # to go back a directory. - [[ "${vcs_comm[gitdir]}" != ".git" ]] && cd - >/dev/null } function +vi-git-aheadbehind() { From fd660f4b92dd255a785a444394a00e09589b873c Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 12 Nov 2018 00:24:29 +0100 Subject: [PATCH 23/79] Fix checking for untracked files Now the untracked files are always checked from the root folder of the repo. --- functions/vcs.zsh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 4cd778a44..6c9bd055c 100755 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -12,10 +12,24 @@ function +vi-git-untracked() { # If we are in a .git folder, do not check for untracked files. [[ "${PWD:A}" =~ "\.git/" ]] && return + # If we are in a repos root folder, vcs_comm[gitdir] yields ".git". + # Inside the .git dir itself (and not a subdir of it) the variable + # yields ".". In any other case (either a subdirectory of .git or + # the repo itself), the value of vcs_comm[gitdir] is the absolute + # path to the .git directory. + # Therefore we can step up a directory, if we are inside the .git + # folder. And in any other case, use the parent directory of the + # gitdir. + local repoDir="." + # Getting the parent dir of the current dir "." is still ".", so + # is is safe to do this always. + [[ "${vcs_comm[gitdir]}" != ".git" ]] && repoDir="${vcs_comm[gitdir]:A:h}" + [[ "${vcs_comm[gitdir]}" == "." ]] && repoDir="${PWD:A:h}" + if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" && "$(command git submodule foreach --quiet --recursive 'command git ls-files --others --exclude-standard')" != "" ]]; then hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" VCS_WORKDIR_HALF_DIRTY=true - elif [[ "$(command git ls-files --others --exclude-standard)" != "" ]]; then + elif [[ "$(command git ls-files --others --exclude-standard "${repoDir}")" != "" ]]; then hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" VCS_WORKDIR_HALF_DIRTY=true else From 6cfe8f8d965bfb6a1314b907e4ab970dd42d4188 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 12 Nov 2018 00:37:34 +0100 Subject: [PATCH 24/79] Add test for detecting untracked files from sibling folder --- test/segments/vcs-git.spec | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/segments/vcs-git.spec b/test/segments/vcs-git.spec index fed1df191..17a277fb3 100755 --- a/test/segments/vcs-git.spec +++ b/test/segments/vcs-git.spec @@ -473,4 +473,21 @@ function testDetectingUntrackedFilesInNestedSubmodulesWork() { assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" } -source shunit2/shunit2 \ No newline at end of file +function testDetectingUntrackedFilesInCleanSubdirectoryWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true" + unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND + mkdir clean-folder + touch clean-folder/file.txt + mkdir dirty-folder + touch dirty-folder/file.txt + git add . 2>/dev/null + git commit -m "Initial commit" >/dev/null + touch dirty-folder/new-file.txt + cd clean-folder + source ${P9K_HOME}/powerlevel9k.zsh-theme + assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" +} + +source shunit2/shunit2 From 4ebb9f92a1b7e27595db6dd9e05981ac6e0d4bbf Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 14 Nov 2018 23:27:05 +0100 Subject: [PATCH 25/79] Ensure that LC_CTYPE IS NOT overwritten by P9K --- test/functions/icons.spec | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/test/functions/icons.spec b/test/functions/icons.spec index ec0cb1fa5..8083c0954 100755 --- a/test/functions/icons.spec +++ b/test/functions/icons.spec @@ -17,52 +17,58 @@ function tearDown() { LC_CTYPE="${_OLD_LC_CTYPE}" } -function testLcCtypeIsSetCorrectlyInDefaultMode() { +function testLcCtypeIsNotOverwrittenInDefaultMode() { local POWERLEVEL9K_MODE="default" + local LC_CTYPE="my-locale" # Load Powerlevel9k source functions/icons.zsh - assertEquals 'en_US.UTF-8' "${LC_CTYPE}" + assertEquals 'my-locale' "${LC_CTYPE}" } -function testLcCtypeIsSetCorrectlyInAwesomePatchedMode() { +function testLcCtypeIsNotOverwrittenInAwesomePatchedMode() { local POWERLEVEL9K_MODE="awesome-patched" + local LC_CTYPE="my-locale" # Load Powerlevel9k source functions/icons.zsh - assertEquals 'en_US.UTF-8' "${LC_CTYPE}" + assertEquals 'my-locale' "${LC_CTYPE}" } -function testLcCtypeIsSetCorrectlyInAwesomeFontconfigMode() { +function testLcCtypeIsNotOverwrittenInAwesomeFontconfigMode() { local POWERLEVEL9K_MODE="awesome-fontconfig" + local LC_CTYPE="my-locale" # Load Powerlevel9k source functions/icons.zsh - assertEquals 'en_US.UTF-8' "${LC_CTYPE}" + assertEquals 'my-locale' "${LC_CTYPE}" } -function testLcCtypeIsSetCorrectlyInNerdfontFontconfigMode() { +function testLcCtypeIsNotOverwrittenInNerdfontFontconfigMode() { local POWERLEVEL9K_MODE="nerdfont-fontconfig" + local LC_CTYPE="my-locale" # Load Powerlevel9k source functions/icons.zsh - assertEquals 'en_US.UTF-8' "${LC_CTYPE}" + assertEquals 'my-locale' "${LC_CTYPE}" } -function testLcCtypeIsSetCorrectlyInFlatMode() { +function testLcCtypeIsNotOverwrittenInFlatMode() { local POWERLEVEL9K_MODE="flat" + local LC_CTYPE="my-locale" # Load Powerlevel9k source functions/icons.zsh - assertEquals 'en_US.UTF-8' "${LC_CTYPE}" + assertEquals 'my-locale' "${LC_CTYPE}" } -function testLcCtypeIsSetCorrectlyInCompatibleMode() { +function testLcCtypeIsNotOverwrittenInCompatibleMode() { local POWERLEVEL9K_MODE="compatible" + local LC_CTYPE="my-locale" # Load Powerlevel9k source functions/icons.zsh - assertEquals 'en_US.UTF-8' "${LC_CTYPE}" + assertEquals 'my-locale' "${LC_CTYPE}" } # Go through all icons defined in default mode, and From faa4cb23af1d7dffa8f5114ee9916c41c44bd222 Mon Sep 17 00:00:00 2001 From: Evan Schiewe Date: Thu, 15 Nov 2018 15:41:56 -0600 Subject: [PATCH 26/79] Uniformly apply inline code formatting All POWERLEVEL variables and directory paths should be formatted with backticks for inline code. If not marked as code, the ~ home directory can unintentionally apply strikethrough. --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2ecf29723..ebcdd4549 100644 --- a/README.md +++ b/README.md @@ -410,10 +410,10 @@ Customizations available are: |Default|Truncate whole directories from left. How many is defined by `POWERLEVEL9K_SHORTEN_DIR_LENGTH`| |`truncate_absolute_chars`|Truncates an absolute number of characters from the left such that the number of characters that your path displays (with or without `POWERLEVEL9K_SHORTEN_DELIMITER`) is no more than `POWERLEVEL9K_SHORTEN_DIR_LENGTH` + the length of `POWERLEVEL9K_SHORTEN_DELIMITER` | |`truncate_middle`|Truncates the middle part of a folder. E.g. you are in a folder named `~/MySuperProjects/AwesomeFiles/BoringOffice`, then it will truncated to `~/MyS..cts/Awe..les/BoringOffice`, if `POWERLEVEL9K_SHORTEN_DIR_LENGTH=3` is also set (controls the amount of characters to be left).| -|`truncate_from_right`|Just leaves the beginning of a folder name untouched. E.g. your folders will be truncated like so: "/ro../Pr../office". How many characters will be untouched is controlled by `POWERLEVEL9K_SHORTEN_DIR_LENGTH`.| -|`truncate_absolute`|Truncates everything exept the last few characters in the path. E.g. if you are in a folder named "~/Projects/powerlevel9k" and you have set `POWERLEVEL9K_SHORTEN_DIR_LENGTH=3`, you will get "..l9k".| +|`truncate_from_right`|Just leaves the beginning of a folder name untouched. E.g. your folders will be truncated like so: `/ro../Pr../office`. How many characters will be untouched is controlled by `POWERLEVEL9K_SHORTEN_DIR_LENGTH`.| +|`truncate_absolute`|Truncates everything exept the last few characters in the path. E.g. if you are in a folder named `~/Projects/powerlevel9k` and you have set `POWERLEVEL9K_SHORTEN_DIR_LENGTH=3`, you will get `..l9k`.| |`truncate_to_last`|Truncates everything before the last folder in the path.| -|`truncate_to_first_and_last`|Truncate middle directories from the path. How many directories will be untouched is controlled by POWERLEVEL9K_SHORTER_DIR_LENGTH. E.g. if you are in a folder named "~/Projects/powerlevel9k" and you have set `POWERLEVEL9K_SHORTEN_DIR_LENGTH=1`, you will get "~/../powerlevel9k".|| +|`truncate_to_first_and_last`|Truncate middle directories from the path. How many directories will be untouched is controlled by `POWERLEVEL9K_SHORTEN_DIR_LENGTH`. E.g. if you are in a folder named `~/Projects/powerlevel9k` and you have set `POWERLEVEL9K_SHORTEN_DIR_LENGTH=1`, you will get `~/../powerlevel9k`.|| |`truncate_to_unique`|Parse all parent path components and truncate them to the shortest unique length. If you copy & paste the result to a shell, after hitting `TAB` it should expand to the original path unambiguously.| |`truncate_with_package_name`|Search for a `package.json` or `composer.json` and prints the `name` field to abbreviate the directory path. The precedence and/or files could be set by `POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json)`. If you have [jq](https://stedolan.github.io/jq/) installed, it will dramatically improve the speed of this strategy.| |`truncate_with_folder_marker`|Search for a file that is specified by `POWERLEVEL9K_SHORTEN_FOLDER_MARKER` and truncate everything before that (if found, otherwise stop on $HOME and ROOT).| @@ -468,9 +468,9 @@ The `disk_usage` segment will show the usage level of the partition that your cu | Variable | Default Value | Description | |----------|---------------|-------------| -|POWERLEVEL9K_DISK_USAGE_ONLY_WARNING|false|Hide the segment except when usage levels have hit warning or critical levels.| -|POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL|90|The usage level that triggers a warning state.| -|POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL|95|The usage level that triggers a critical state.| +|`POWERLEVEL9K_DISK_USAGE_ONLY_WARNING`|false|Hide the segment except when usage levels have hit warning or critical levels.| +|`POWERLEVEL9K_DISK_USAGE_WARNING_LEVEL`|90|The usage level that triggers a warning state.| +|`POWERLEVEL9K_DISK_USAGE_CRITICAL_LEVEL`|95|The usage level that triggers a critical state.| ##### host From 7bc5366af1abb572238aa24dfe2552aed1fab966 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 15 Nov 2018 01:18:46 +0100 Subject: [PATCH 27/79] Add tests for branch name vulnerability --- test/segments/vcs-git.spec | 11 +++++++++++ test/segments/vcs-hg.spec | 13 ++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/test/segments/vcs-git.spec b/test/segments/vcs-git.spec index 17a277fb3..bb51766c4 100755 --- a/test/segments/vcs-git.spec +++ b/test/segments/vcs-git.spec @@ -490,4 +490,15 @@ function testDetectingUntrackedFilesInCleanSubdirectoryWorks() { assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)" } +function testBranchNameScriptingVulnerability() { + echo "#!/bin/sh\n\necho 'hacked'\n" > evil_script.sh + chmod +x evil_script.sh + + git checkout -b "$(./evil_script.sh)" 2>/dev/null + git add . 2>/dev/null + git commit -m "Initial commit" >/dev/null + + assertEquals "%K{002} %F{000} %f%F{000} \$(./evil_script.sh) %k%F{002}%f " "$(__p9k_build_left_prompt)" +} + source shunit2/shunit2 diff --git a/test/segments/vcs-hg.spec b/test/segments/vcs-hg.spec index 2903f5446..53afbaacd 100755 --- a/test/segments/vcs-hg.spec +++ b/test/segments/vcs-hg.spec @@ -204,4 +204,15 @@ function testBookmarkIconWorks() { assertEquals "%K{002} %F{000} default Binitial %k%F{002}%f " "$(build_left_prompt)" } -source shunit2/shunit2 \ No newline at end of file +function testBranchNameScriptingVulnerability() { + echo "#!/bin/sh\n\necho 'hacked'\n" > evil_script.sh + chmod +x evil_script.sh + + hg branch '$(./evil_script.sh)' >/dev/null + hg add . >/dev/null + hg commit -m "Initial commit" >/dev/null + + assertEquals "%K{002} %F{000} %f%F{000} \$(./evil_script.sh) %k%F{002}%f " "$(build_left_prompt)" +} + +source shunit2/shunit2 From 1b7e41964c84b124e91fafec66230c7c678a4145 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 15 Nov 2018 01:55:42 +0100 Subject: [PATCH 28/79] Fix configuration errors in the tests --- test/segments/vcs-git.spec | 4 +++- test/segments/vcs-hg.spec | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test/segments/vcs-git.spec b/test/segments/vcs-git.spec index bb51766c4..bb2aef5b3 100755 --- a/test/segments/vcs-git.spec +++ b/test/segments/vcs-git.spec @@ -491,6 +491,8 @@ function testDetectingUntrackedFilesInCleanSubdirectoryWorks() { } function testBranchNameScriptingVulnerability() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) echo "#!/bin/sh\n\necho 'hacked'\n" > evil_script.sh chmod +x evil_script.sh @@ -498,7 +500,7 @@ function testBranchNameScriptingVulnerability() { git add . 2>/dev/null git commit -m "Initial commit" >/dev/null - assertEquals "%K{002} %F{000} %f%F{000} \$(./evil_script.sh) %k%F{002}%f " "$(__p9k_build_left_prompt)" + assertEquals "%K{002} %F{000} %f%F{000} \$(./evil_script.sh) %k%F{002}%f " "$(build_left_prompt)" } source shunit2/shunit2 diff --git a/test/segments/vcs-hg.spec b/test/segments/vcs-hg.spec index 53afbaacd..de7c5d38d 100755 --- a/test/segments/vcs-hg.spec +++ b/test/segments/vcs-hg.spec @@ -205,6 +205,8 @@ function testBookmarkIconWorks() { } function testBranchNameScriptingVulnerability() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) echo "#!/bin/sh\n\necho 'hacked'\n" > evil_script.sh chmod +x evil_script.sh @@ -212,7 +214,7 @@ function testBranchNameScriptingVulnerability() { hg add . >/dev/null hg commit -m "Initial commit" >/dev/null - assertEquals "%K{002} %F{000} %f%F{000} \$(./evil_script.sh) %k%F{002}%f " "$(build_left_prompt)" + assertEquals "%K{002} %F{000} \$(./evil_script.sh) %k%F{002}%f " "$(build_left_prompt)" } source shunit2/shunit2 From 24818eff794f32fea5a87a9d4c9e042534da272d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 15 Nov 2018 13:12:37 +0100 Subject: [PATCH 29/79] Fix test The branch name must not be expanded. --- test/segments/vcs-git.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/segments/vcs-git.spec b/test/segments/vcs-git.spec index bb2aef5b3..f5777a1e0 100755 --- a/test/segments/vcs-git.spec +++ b/test/segments/vcs-git.spec @@ -496,7 +496,7 @@ function testBranchNameScriptingVulnerability() { echo "#!/bin/sh\n\necho 'hacked'\n" > evil_script.sh chmod +x evil_script.sh - git checkout -b "$(./evil_script.sh)" 2>/dev/null + git checkout -b '$(./evil_script.sh)' 2>/dev/null git add . 2>/dev/null git commit -m "Initial commit" >/dev/null From a72a82b4b1641cde227a403add758d49c2782914 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 15 Nov 2018 13:17:40 +0100 Subject: [PATCH 30/79] Fix tests --- test/segments/vcs-git.spec | 2 +- test/segments/vcs-hg.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/segments/vcs-git.spec b/test/segments/vcs-git.spec index f5777a1e0..ab2962c88 100755 --- a/test/segments/vcs-git.spec +++ b/test/segments/vcs-git.spec @@ -500,7 +500,7 @@ function testBranchNameScriptingVulnerability() { git add . 2>/dev/null git commit -m "Initial commit" >/dev/null - assertEquals "%K{002} %F{000} %f%F{000} \$(./evil_script.sh) %k%F{002}%f " "$(build_left_prompt)" + assertEquals '%K{002} %F{000} $(./evil_script.sh) %k%F{002}%f ' "$(build_left_prompt)" } source shunit2/shunit2 diff --git a/test/segments/vcs-hg.spec b/test/segments/vcs-hg.spec index de7c5d38d..c4289cefa 100755 --- a/test/segments/vcs-hg.spec +++ b/test/segments/vcs-hg.spec @@ -214,7 +214,7 @@ function testBranchNameScriptingVulnerability() { hg add . >/dev/null hg commit -m "Initial commit" >/dev/null - assertEquals "%K{002} %F{000} \$(./evil_script.sh) %k%F{002}%f " "$(build_left_prompt)" + assertEquals '%K{002} %F{000} $(./evil_script.sh) %k%F{002}%f ' "$(build_left_prompt)" } source shunit2/shunit2 From 574ee6dc1cf64950f1632e3f2fa017b3d34a3e27 Mon Sep 17 00:00:00 2001 From: Matthew Judy Date: Sat, 17 Nov 2018 17:13:25 -0500 Subject: [PATCH 31/79] Port #1071 to `master` (fatal errors emitted by untracked file check in vcs.zsh) --- functions/vcs.zsh | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index 6c9bd055c..cb53dd3e8 100755 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -8,33 +8,23 @@ set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY false function +vi-git-untracked() { - [[ -z "${vcs_comm[gitdir]}" || "${vcs_comm[gitdir]}" == "." ]] && return - # If we are in a .git folder, do not check for untracked files. - [[ "${PWD:A}" =~ "\.git/" ]] && return - - # If we are in a repos root folder, vcs_comm[gitdir] yields ".git". - # Inside the .git dir itself (and not a subdir of it) the variable - # yields ".". In any other case (either a subdirectory of .git or - # the repo itself), the value of vcs_comm[gitdir] is the absolute - # path to the .git directory. - # Therefore we can step up a directory, if we are inside the .git - # folder. And in any other case, use the parent directory of the - # gitdir. - local repoDir="." - # Getting the parent dir of the current dir "." is still ".", so - # is is safe to do this always. - [[ "${vcs_comm[gitdir]}" != ".git" ]] && repoDir="${vcs_comm[gitdir]:A:h}" - [[ "${vcs_comm[gitdir]}" == "." ]] && repoDir="${PWD:A:h}" - - if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" && "$(command git submodule foreach --quiet --recursive 'command git ls-files --others --exclude-standard')" != "" ]]; then - hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" - VCS_WORKDIR_HALF_DIRTY=true - elif [[ "$(command git ls-files --others --exclude-standard "${repoDir}")" != "" ]]; then - hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" - VCS_WORKDIR_HALF_DIRTY=true - else - VCS_WORKDIR_HALF_DIRTY=false - fi + [[ -z "${vcs_comm[gitdir]}" || "${vcs_comm[gitdir]}" == "." ]] && return + + # get the root for the current repo or submodule + local repoTopLevel="$(command git rev-parse --show-toplevel 2> /dev/null)" + # dump out if we're outside a git repository (which includes being in the .git folder) + [[ $? != 0 || -z $repoTopLevel ]] && return + + local untrackedFiles=$(command git ls-files --others --exclude-standard "${repoTopLevel}") + + if [[ -z $untrackedFiles && "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" ]]; then + untrackedFiles+=$(command git submodule foreach --quiet --recursive 'command git ls-files --others --exclude-standard') + fi + + [[ -z $untrackedFiles ]] && return + + hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')" + VCS_WORKDIR_HALF_DIRTY=true } function +vi-git-aheadbehind() { From 6df2ba0ae02e585c557b2ff2ccb9f6f207a7c6b8 Mon Sep 17 00:00:00 2001 From: Matthew Judy Date: Sat, 17 Nov 2018 17:41:55 -0500 Subject: [PATCH 32/79] Port git submodule test from `next`. --- test/segments/vcs-git.spec | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/segments/vcs-git.spec b/test/segments/vcs-git.spec index ab2962c88..da28b9559 100755 --- a/test/segments/vcs-git.spec +++ b/test/segments/vcs-git.spec @@ -503,4 +503,33 @@ function testBranchNameScriptingVulnerability() { assertEquals '%K{002} %F{000} $(./evil_script.sh) %k%F{002}%f ' "$(build_left_prompt)" } +function testGitSubmoduleWorks() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs) + local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true" + unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND + + mkdir ../submodule + cd ../submodule + git init 1>/dev/null + touch "i-am-tracked.txt" + git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null + + local submodulePath="${PWD}" + + cd - + git submodule add "${submodulePath}" 2>/dev/null + git commit -m "Add submodule" 1>/dev/null + + cd submodule + + source "${P9K_HOME}/powerlevel9k.zsh-theme" + + local result="$(build_left_prompt)" + [[ "$result" =~ ".*(is outside repository)+" ]] && return 1 + + assertEquals "%K{002} %F{000} master %k%F{002}%f " "$result" +} + + source shunit2/shunit2 From 5c412b4d420a2226cbf8af4ab38c61154df858e4 Mon Sep 17 00:00:00 2001 From: Josselin Auguste Date: Sat, 17 Nov 2018 22:52:06 +0100 Subject: [PATCH 33/79] Update VIRTUAL_ENV_DISABLE_PROMPT value Following prezto update --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 7077bfc8c..79237385a 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1648,7 +1648,7 @@ prompt_vi_mode() { # https://virtualenv.pypa.io/en/latest/ prompt_virtualenv() { local virtualenv_path="$VIRTUAL_ENV" - if [[ -n "$virtualenv_path" && "$VIRTUAL_ENV_DISABLE_PROMPT" != true ]]; then + if [[ -n "$virtualenv_path" && -z "$VIRTUAL_ENV_DISABLE_PROMPT" ]]; then "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$(basename "$virtualenv_path")" 'PYTHON_ICON' fi } From a8fa0332d28713ad43b9258ad9b7cf0e3de8e1fb Mon Sep 17 00:00:00 2001 From: Shini31 Date: Sun, 30 Dec 2018 11:26:04 +0100 Subject: [PATCH 34/79] Use ip command for VPN segment - fix #1125 --- powerlevel9k.zsh-theme | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 79237385a..65147c634 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -597,11 +597,19 @@ prompt_public_ip() { icon='PUBLIC_IP_ICON' # Check VPN is on if VPN interface is set if [[ -n $POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE ]]; then - for vpn_iface in $(/sbin/ifconfig | grep -e ^"$POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE" | cut -d":" -f1) - do - icon='VPN_ICON' - break - done + if [[ "$OS" == "OSX" ]]; then + for vpn_iface in $(/sbin/ifconfig | grep -e ^"$POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE" | cut -d":" -f1) + do + icon='VPN_ICON' + break + done + else + for vpn_iface in $(ip link ls up | grep -o -E ":\s+[a-z0-9]+:" | grep -v "lo" | grep -o -E "[a-z0-9]+" | grep -o -E "^$POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE.*") + do + icon='VPN_ICON' + break + done + fi fi $1_prompt_segment "$0" "$2" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "${public_ip}" "$icon" fi @@ -1134,11 +1142,19 @@ prompt_ip() { set_default POWERLEVEL9K_VPN_IP_INTERFACE "tun" # prompt if vpn active prompt_vpn_ip() { - for vpn_iface in $(/sbin/ifconfig | grep -e "^${POWERLEVEL9K_VPN_IP_INTERFACE}" | cut -d":" -f1) - do - ip=$(/sbin/ifconfig "$vpn_iface" | grep -o "inet\s.*" | cut -d' ' -f2) - "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'VPN_ICON' - done + if [[ "$OS" == "OSX" ]]; then + for vpn_iface in $(/sbin/ifconfig | grep -e "^${POWERLEVEL9K_VPN_IP_INTERFACE}" | cut -d":" -f1) + do + ip=$(/sbin/ifconfig "$vpn_iface" | grep -o "inet\s.*" | cut -d' ' -f2) + "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'VPN_ICON' + done + else + for vpn_iface in $(ip link ls up | grep -o -E ":\s+[a-z0-9]+:" | grep -v "lo" | grep -o -E "[a-z0-9]+" | grep -o -E "^${POWERLEVEL9K_VPN_IP_INTERFACE}.*") + do + ip=$(/sbin/ip -4 a show "$vpn_iface" | grep -o "inet\s*[0-9.]*" | grep -o -E "[0-9.]+") + "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'VPN_ICON' + done + fi } ################################################################ From a8db401808f6daf16710118bd7fb37f6b30b261a Mon Sep 17 00:00:00 2001 From: Ymage Date: Thu, 3 Jan 2019 12:07:27 +0100 Subject: [PATCH 35/79] [Bugfix] virtualenv prompt displaying Fix #1127 --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 79237385a..7077bfc8c 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1648,7 +1648,7 @@ prompt_vi_mode() { # https://virtualenv.pypa.io/en/latest/ prompt_virtualenv() { local virtualenv_path="$VIRTUAL_ENV" - if [[ -n "$virtualenv_path" && -z "$VIRTUAL_ENV_DISABLE_PROMPT" ]]; then + if [[ -n "$virtualenv_path" && "$VIRTUAL_ENV_DISABLE_PROMPT" != true ]]; then "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$(basename "$virtualenv_path")" 'PYTHON_ICON' fi } From 12e972486055dbb37279ef81ae4d2114e8221f19 Mon Sep 17 00:00:00 2001 From: Ymage Date: Mon, 7 Jan 2019 09:18:34 +0100 Subject: [PATCH 36/79] Merge with @dritter proposal --- powerlevel9k.zsh-theme | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 7077bfc8c..472dd949d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1648,7 +1648,12 @@ prompt_vi_mode() { # https://virtualenv.pypa.io/en/latest/ prompt_virtualenv() { local virtualenv_path="$VIRTUAL_ENV" - if [[ -n "$virtualenv_path" && "$VIRTUAL_ENV_DISABLE_PROMPT" != true ]]; then + + # Early exit; $virtualenv_path must always be set. + [[ -z "$virtualenv_path" ]] && return + + # Check if VIRTUAL_ENV_DISABLE_PROMPT is set to false, or is a numerical value + if [[ "$VIRTUAL_ENV_DISABLE_PROMPT" == "false" ]] || (( VIRTUAL_ENV_DISABLE_PROMPT )); then "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$(basename "$virtualenv_path")" 'PYTHON_ICON' fi } From ee7416962d80dfaaed7efd57511d5aa568480d21 Mon Sep 17 00:00:00 2001 From: Ymage Date: Wed, 9 Jan 2019 17:00:05 +0100 Subject: [PATCH 37/79] Remove $VIRTUAL_ENV_DISABLE_PROMPT testing --- powerlevel9k.zsh-theme | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 472dd949d..60c16b5a8 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1652,10 +1652,7 @@ prompt_virtualenv() { # Early exit; $virtualenv_path must always be set. [[ -z "$virtualenv_path" ]] && return - # Check if VIRTUAL_ENV_DISABLE_PROMPT is set to false, or is a numerical value - if [[ "$VIRTUAL_ENV_DISABLE_PROMPT" == "false" ]] || (( VIRTUAL_ENV_DISABLE_PROMPT )); then - "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$(basename "$virtualenv_path")" 'PYTHON_ICON' - fi + "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$(basename "$virtualenv_path")" 'PYTHON_ICON' } ################################################################ From 9b73c8bd9c40be4101e6cd7edb09754e5d85c27a Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 21 Jan 2019 19:46:53 +0100 Subject: [PATCH 38/79] Add tests --- powerlevel9k.zsh-theme | 15 +-- test/segments/public_ip.spec | 83 ++++++++++++++++ test/segments/vpn_ip.spec | 181 +++++++++++++++++++++++++++++++++++ 3 files changed, 273 insertions(+), 6 deletions(-) create mode 100755 test/segments/vpn_ip.spec diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 65147c634..2f90581a0 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -533,7 +533,9 @@ prompt_battery() { # * $1 Alignment: string - left|right # * $2 Index: integer # * $3 Joined: bool - If the segment should be joined +# * $4 Root Prefix: string - Root prefix for testing purposes prompt_public_ip() { + local ROOT_PREFIX="${4}" # set default values for segment set_default POWERLEVEL9K_PUBLIC_IP_TIMEOUT "300" set_default POWERLEVEL9K_PUBLIC_IP_NONE "" @@ -561,7 +563,7 @@ prompt_public_ip() { # grab a fresh IP if needed local fresh_ip - if [[ $refresh_ip =~ true && -w $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then + if [[ $refresh_ip == true && -w $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then for method in "${POWERLEVEL9K_PUBLIC_IP_METHODS[@]}"; do case $method in 'dig') @@ -598,7 +600,7 @@ prompt_public_ip() { # Check VPN is on if VPN interface is set if [[ -n $POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE ]]; then if [[ "$OS" == "OSX" ]]; then - for vpn_iface in $(/sbin/ifconfig | grep -e ^"$POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE" | cut -d":" -f1) + for vpn_iface in $(${ROOT_PREFIX}/sbin/ifconfig | grep -e ^"$POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE" | cut -d":" -f1) do icon='VPN_ICON' break @@ -1142,16 +1144,17 @@ prompt_ip() { set_default POWERLEVEL9K_VPN_IP_INTERFACE "tun" # prompt if vpn active prompt_vpn_ip() { + local ROOT_PREFIX="${4}" if [[ "$OS" == "OSX" ]]; then - for vpn_iface in $(/sbin/ifconfig | grep -e "^${POWERLEVEL9K_VPN_IP_INTERFACE}" | cut -d":" -f1) + for vpn_iface in $(${ROOT_PREFIX}/sbin/ifconfig | grep -e "^${POWERLEVEL9K_VPN_IP_INTERFACE}" | cut -d":" -f1) do - ip=$(/sbin/ifconfig "$vpn_iface" | grep -o "inet\s.*" | cut -d' ' -f2) + ip=$(${ROOT_PREFIX}/sbin/ifconfig "$vpn_iface" | grep -o "inet\s.*" | cut -d' ' -f2) "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'VPN_ICON' done else - for vpn_iface in $(ip link ls up | grep -o -E ":\s+[a-z0-9]+:" | grep -v "lo" | grep -o -E "[a-z0-9]+" | grep -o -E "^${POWERLEVEL9K_VPN_IP_INTERFACE}.*") + for vpn_iface in $(${ROOT_PREFIX}/sbin/ip link ls up | grep -o -E ":\s+[a-z0-9]+:" | grep -v "lo" | grep -o -E "[a-z0-9]+" | grep -o -E "^${POWERLEVEL9K_VPN_IP_INTERFACE}.*") do - ip=$(/sbin/ip -4 a show "$vpn_iface" | grep -o "inet\s*[0-9.]*" | grep -o -E "[0-9.]+") + ip=$(${ROOT_PREFIX}/sbin/ip -4 a show "$vpn_iface" | grep -o "inet\s*[0-9.]*" | grep -o -E "[0-9.]+") "$1_prompt_segment" "$0" "$2" "cyan" "$DEFAULT_COLOR" "$ip" 'VPN_ICON' done fi diff --git a/test/segments/public_ip.spec b/test/segments/public_ip.spec index 334a6423f..abfecbcb2 100755 --- a/test/segments/public_ip.spec +++ b/test/segments/public_ip.spec @@ -12,6 +12,8 @@ function setUp() { P9K_HOME=$(pwd) FOLDER=/tmp/powerlevel9k-test mkdir -p $FOLDER + mkdir $FOLDER/bin + mkdir $FOLDER/sbin cd $FOLDER # Change cache file, so that the users environment don't @@ -219,4 +221,85 @@ function testPublicIpSegmentWhenGoingOnline() { unfunction dig } +function testPublicIpSegmentWithVPNTurnedOnLinux() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) + local OS='linux' + + echo "1.2.3.4" > $POWERLEVEL9K_PUBLIC_IP_FILE + local POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE="tun1" + + ip() { + cat < mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 + link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 +2: enp0s31f6: mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000 + link/ether 8c:16:45:7d:0c:9a brd ff:ff:ff:ff:ff:ff +3: tun1: mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000 + link/ether b4:6b:fc:9d:c6:bc brd ff:ff:ff:ff:ff:ff +5: docker0: mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default + link/ether 02:42:8f:5c:ed:39 brd ff:ff:ff:ff:ff:ff +EOF + } + + assertEquals "%K{000} %F{007}(vpn) %f%F{007}1.2.3.4 " "$(prompt_public_ip left 1 false "$FOLDER")" + + unfunction ip + rm -f $POWERLEVEL9K_PUBLIC_IP_FILE +} + +function testPublicIpSegmentWithVPNTurnedOnOsx() { + typeset -F now + now=$(date +%s) + + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) + local OS='OSX' + + echo "1.2.3.4" > $POWERLEVEL9K_PUBLIC_IP_FILE + local POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE="tun1" + + # Fake stat call + function stat() { + echo $now + } + + # Fake ifconfig + cat > $FOLDER/sbin/ifconfig < mtu 1500 + inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 + ether 02:42:8f:5c:ed:51 txqueuelen 0 (Ethernet) + RX packets 0 bytes 0 (0.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 0 bytes 0 (0.0 B) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + +tun1: flags=4099 mtu 1500 + ether 8c:16:45:7d:0c:9a txqueuelen 1000 (Ethernet) + RX packets 0 bytes 0 (0.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 0 bytes 0 (0.0 B) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + device interrupt 16 memory 0xe8200000-e8220000 + +lo: flags=73 mtu 65536 + inet 127.0.0.1 netmask 255.0.0.0 + inet6 ::1 prefixlen 128 scopeid 0x10 + loop txqueuelen 1000 (Local Loopback) + RX packets 5136 bytes 328651 (320.9 KiB) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 5136 bytes 328651 (320.9 KiB) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 +INNER +EOF + chmod +x $FOLDER/sbin/ifconfig + + assertEquals "%K{000} %F{007}(vpn) %f%F{007}1.2.3.4 " "$(prompt_public_ip left 1 false "$FOLDER")" + + rm -f $POWERLEVEL9K_PUBLIC_IP_FILE + unfunction stat +} + source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/vpn_ip.spec b/test/segments/vpn_ip.spec new file mode 100755 index 000000000..b213202e9 --- /dev/null +++ b/test/segments/vpn_ip.spec @@ -0,0 +1,181 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + + # Test specific + P9K_HOME=$(pwd) + FOLDER=/tmp/powerlevel9k-test + mkdir -p $FOLDER + mkdir $FOLDER/bin + mkdir $FOLDER/sbin +} + +function tearDown() { + # Go back to powerlevel9k folder + cd "${P9K_HOME}" + # Remove eventually created test-specific folder + rm -fr "${FOLDER}" + + unset FOLDER + unset P9K_HOME +} + +function fakeIfconfig() { + # Fake ifconfig + cat > $FOLDER/sbin/ifconfig < mtu 1500 + inet 1.2.3.4 txqueuelen 1000 (Ethernet) + RX packets 0 bytes 0 (0.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 0 bytes 0 (0.0 B) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + device interrupt 16 memory 0xe8200000-e8220000 +INNER + exit 0 +fi + + cat < mtu 1500 + inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 + ether 02:42:8f:5c:ed:51 txqueuelen 0 (Ethernet) + RX packets 0 bytes 0 (0.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 0 bytes 0 (0.0 B) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + +tun1: flags=4099 mtu 1500 + inet 1.2.3.4 txqueuelen 1000 (Ethernet) + RX packets 0 bytes 0 (0.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 0 bytes 0 (0.0 B) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + device interrupt 16 memory 0xe8200000-e8220000 + +lo: flags=73 mtu 65536 + inet 127.0.0.1 netmask 255.0.0.0 + inet6 ::1 prefixlen 128 scopeid 0x10 + loop txqueuelen 1000 (Local Loopback) + RX packets 5136 bytes 328651 (320.9 KiB) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 5136 bytes 328651 (320.9 KiB) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 +INNER +EOF + chmod +x $FOLDER/sbin/ifconfig +} + +function fakeIp() { + local INTERFACE1="${1}" + [[ -z "${INTERFACE1}" ]] && INTERFACE1="tun0" + local INTERFACE2="${2}" + [[ -z "${INTERFACE2}" ]] && INTERFACE2="disabled-if2" + cat > $FOLDER/sbin/ip < mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default + link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 +2: ${INTERFACE1}: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 + link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff +3: ${INTERFACE2}: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 + link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff +4: wlan0: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 + link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff +INNER + fi + + if [[ "\$*" =~ 'show ${INTERFACE1}' ]]; then + cat < mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 + inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 + valid_lft forever preferred_lft forever +INNER + fi + + if [[ "\$*" =~ 'show ${INTERFACE2}' ]]; then + cat < mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 + inet 1.2.3.4 brd 10.0.2.255 scope global eth0 + valid_lft forever preferred_lft forever +INNER + fi +EOF + + chmod +x $FOLDER/sbin/ip +} + +function testVpnIpSegmentPrintsNothingOnOsxIfNotConnected() { + alias ifconfig='echo "not connected"' + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS="OSX" # Fake OSX + + assertEquals "" "$(prompt_vpn_ip left 1 false "$FOLDER")" + + unalias ifconfig +} + +function testVpnIpSegmentPrintsNothingOnLinuxIfNotConnected() { + alias ip='echo "not connected"' + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS="Linux" # Fake Linux + + assertEquals "" "$(prompt_vpn_ip left 1 false "$FOLDER")" + + unalias ip +} + +function testVpnIpSegmentWorksOnOsxWithInterfaceSpecified() { + local POWERLEVEL9K_VPN_IP_INTERFACE='tun1' + + fakeIfconfig + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS='OSX' # Fake OSX + + assertEquals "%K{006} %F{000}(vpn) %f%F{000}1.2.3.4 " "$(prompt_vpn_ip left 1 false "$FOLDER")" +} + +function testVpnIpSegmentWorksOnLinuxWithInterfaceSpecified() { + local POWERLEVEL9K_VPN_IP_INTERFACE='tun1' + + fakeIp "tun1" + + # Load Powerlevel9k + source powerlevel9k.zsh-theme + local OS='Linux' # Fake Linux + + assertEquals "%K{006} %F{000}(vpn) %f%F{000}10.0.2.15 " "$(prompt_vpn_ip left 1 false "$FOLDER")" +} + +# vpn_ip is not capable of handling multiple vpn interfaces ATM. +# function testVpnIpSegmentWorksOnLinuxWithMultipleInterfacesSpecified() { +# local POWERLEVEL9K_VPN_IP_INTERFACE=(tun0 tun1) + +# fakeIp "tun0" "tun1" + +# # Load Powerlevel9k +# source powerlevel9k.zsh-theme +# local OS='Linux' # Fake Linux + +# setopt xtrace +# assertEquals "%K{006} %F{000}(vpn) %f%F{000}10.0.2.15 " "$(prompt_vpn_ip left 1 false "$FOLDER")" +# unsetopt xtrace +# } + +source shunit2/shunit2 \ No newline at end of file From da50151d2487b3fb4a54a6ae101971605dde66ee Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 21 Jan 2019 19:48:28 +0100 Subject: [PATCH 39/79] Fix regular expression --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 2f90581a0..e7b1b882a 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -600,7 +600,7 @@ prompt_public_ip() { # Check VPN is on if VPN interface is set if [[ -n $POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE ]]; then if [[ "$OS" == "OSX" ]]; then - for vpn_iface in $(${ROOT_PREFIX}/sbin/ifconfig | grep -e ^"$POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE" | cut -d":" -f1) + for vpn_iface in $(${ROOT_PREFIX}/sbin/ifconfig | grep -e "^$POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE" | cut -d":" -f1) do icon='VPN_ICON' break From 32d3216bde4c22721ba7e4cb7ff39f12b5f3b2a4 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 22 Jan 2019 19:18:09 +0100 Subject: [PATCH 40/79] Fix tests --- test/segments/public_ip.spec | 2 +- test/segments/vpn_ip.spec | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/segments/public_ip.spec b/test/segments/public_ip.spec index abfecbcb2..a3f41e614 100755 --- a/test/segments/public_ip.spec +++ b/test/segments/public_ip.spec @@ -266,7 +266,7 @@ function testPublicIpSegmentWithVPNTurnedOnOsx() { # Fake ifconfig cat > $FOLDER/sbin/ifconfig < mtu 1500 inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 diff --git a/test/segments/vpn_ip.spec b/test/segments/vpn_ip.spec index b213202e9..3333fd07d 100755 --- a/test/segments/vpn_ip.spec +++ b/test/segments/vpn_ip.spec @@ -29,7 +29,7 @@ function tearDown() { function fakeIfconfig() { # Fake ifconfig cat > $FOLDER/sbin/ifconfig < $FOLDER/sbin/ip < Date: Wed, 23 Jan 2019 01:01:49 +0100 Subject: [PATCH 41/79] Improve tests --- powerlevel9k.zsh-theme | 2 +- test/segments/public_ip.spec | 142 +++++++++++++++++++++++------------ 2 files changed, 93 insertions(+), 51 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index e7b1b882a..6902ed100 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -606,7 +606,7 @@ prompt_public_ip() { break done else - for vpn_iface in $(ip link ls up | grep -o -E ":\s+[a-z0-9]+:" | grep -v "lo" | grep -o -E "[a-z0-9]+" | grep -o -E "^$POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE.*") + for vpn_iface in $(${ROOT_PREFIX}/sbin/ip link ls up | grep -o -E ":\s+[a-z0-9]+:" | grep -v "lo" | grep -o -E "[a-z0-9]+" | grep -o -E "^$POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE.*") do icon='VPN_ICON' break diff --git a/test/segments/public_ip.spec b/test/segments/public_ip.spec index a3f41e614..eeb505961 100755 --- a/test/segments/public_ip.spec +++ b/test/segments/public_ip.spec @@ -35,6 +35,95 @@ function tearDown() { unset POWERLEVEL9K_PUBLIC_IP_FILE } +function fakeIfconfig() { + # Fake ifconfig + cat > $FOLDER/sbin/ifconfig < mtu 1500 + inet 1.2.3.4 txqueuelen 1000 (Ethernet) + RX packets 0 bytes 0 (0.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 0 bytes 0 (0.0 B) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + device interrupt 16 memory 0xe8200000-e8220000 +INNER + exit 0 +fi + + cat < mtu 1500 + inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 + ether 02:42:8f:5c:ed:51 txqueuelen 0 (Ethernet) + RX packets 0 bytes 0 (0.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 0 bytes 0 (0.0 B) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + +tun1: flags=4099 mtu 1500 + inet 1.2.3.4 txqueuelen 1000 (Ethernet) + RX packets 0 bytes 0 (0.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 0 bytes 0 (0.0 B) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + device interrupt 16 memory 0xe8200000-e8220000 + +lo: flags=73 mtu 65536 + inet 127.0.0.1 netmask 255.0.0.0 + inet6 ::1 prefixlen 128 scopeid 0x10 + loop txqueuelen 1000 (Local Loopback) + RX packets 5136 bytes 328651 (320.9 KiB) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 5136 bytes 328651 (320.9 KiB) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 +INNER +EOF + chmod +x $FOLDER/sbin/ifconfig +} + +function fakeIp() { + local INTERFACE1="${1}" + [[ -z "${INTERFACE1}" ]] && INTERFACE1="tun0" + local INTERFACE2="${2}" + [[ -z "${INTERFACE2}" ]] && INTERFACE2="disabled-if2" + cat > $FOLDER/sbin/ip < mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default + link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 +2: ${INTERFACE1}: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 + link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff +3: ${INTERFACE2}: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 + link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff +4: wlan0: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 + link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff +INNER + fi + + if [[ "\$*" =~ 'show ${INTERFACE1}' ]]; then + cat < mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 + inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 + valid_lft forever preferred_lft forever +INNER + fi + + if [[ "\$*" =~ 'show ${INTERFACE2}' ]]; then + cat < mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 + inet 1.2.3.4 brd 10.0.2.255 scope global eth0 + valid_lft forever preferred_lft forever +INNER + fi +EOF + + chmod +x $FOLDER/sbin/ip +} + function testPublicIpSegmentPrintsNothingByDefaultIfHostIsNotAvailable() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip custom_world) @@ -222,38 +311,21 @@ function testPublicIpSegmentWhenGoingOnline() { } function testPublicIpSegmentWithVPNTurnedOnLinux() { - local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) local OS='linux' echo "1.2.3.4" > $POWERLEVEL9K_PUBLIC_IP_FILE local POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE="tun1" - ip() { - cat < mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 - link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 -2: enp0s31f6: mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000 - link/ether 8c:16:45:7d:0c:9a brd ff:ff:ff:ff:ff:ff -3: tun1: mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000 - link/ether b4:6b:fc:9d:c6:bc brd ff:ff:ff:ff:ff:ff -5: docker0: mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default - link/ether 02:42:8f:5c:ed:39 brd ff:ff:ff:ff:ff:ff -EOF - } + # Fake ip command + fakeIp "tun1" assertEquals "%K{000} %F{007}(vpn) %f%F{007}1.2.3.4 " "$(prompt_public_ip left 1 false "$FOLDER")" - - unfunction ip - rm -f $POWERLEVEL9K_PUBLIC_IP_FILE } function testPublicIpSegmentWithVPNTurnedOnOsx() { typeset -F now now=$(date +%s) - local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(public_ip) local OS='OSX' echo "1.2.3.4" > $POWERLEVEL9K_PUBLIC_IP_FILE @@ -265,40 +337,10 @@ function testPublicIpSegmentWithVPNTurnedOnOsx() { } # Fake ifconfig - cat > $FOLDER/sbin/ifconfig < mtu 1500 - inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 - ether 02:42:8f:5c:ed:51 txqueuelen 0 (Ethernet) - RX packets 0 bytes 0 (0.0 B) - RX errors 0 dropped 0 overruns 0 frame 0 - TX packets 0 bytes 0 (0.0 B) - TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 - -tun1: flags=4099 mtu 1500 - ether 8c:16:45:7d:0c:9a txqueuelen 1000 (Ethernet) - RX packets 0 bytes 0 (0.0 B) - RX errors 0 dropped 0 overruns 0 frame 0 - TX packets 0 bytes 0 (0.0 B) - TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 - device interrupt 16 memory 0xe8200000-e8220000 - -lo: flags=73 mtu 65536 - inet 127.0.0.1 netmask 255.0.0.0 - inet6 ::1 prefixlen 128 scopeid 0x10 - loop txqueuelen 1000 (Local Loopback) - RX packets 5136 bytes 328651 (320.9 KiB) - RX errors 0 dropped 0 overruns 0 frame 0 - TX packets 5136 bytes 328651 (320.9 KiB) - TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 -INNER -EOF - chmod +x $FOLDER/sbin/ifconfig + fakeIfconfig assertEquals "%K{000} %F{007}(vpn) %f%F{007}1.2.3.4 " "$(prompt_public_ip left 1 false "$FOLDER")" - rm -f $POWERLEVEL9K_PUBLIC_IP_FILE unfunction stat } From 54a985cb11861f3857daa7001558f015d971dc3d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 23 Jan 2019 01:02:42 +0100 Subject: [PATCH 42/79] Simplify code that checks if a VPN is running --- powerlevel9k.zsh-theme | 15 +++++---------- test/segments/public_ip.spec | 8 +++++--- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 6902ed100..7437fe32a 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -600,17 +600,12 @@ prompt_public_ip() { # Check VPN is on if VPN interface is set if [[ -n $POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE ]]; then if [[ "$OS" == "OSX" ]]; then - for vpn_iface in $(${ROOT_PREFIX}/sbin/ifconfig | grep -e "^$POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE" | cut -d":" -f1) - do - icon='VPN_ICON' - break - done + local interface="$(${ROOT_PREFIX}/sbin/ifconfig $POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE)" + # Check if interface is UP. + [[ "$interface" =~ " $FOLDER/sbin/ifconfig < mtu 1500 +${INTERFACE}: flags=4099 mtu 1500 inet 1.2.3.4 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 @@ -62,7 +64,7 @@ docker0: flags=4099 mtu 1500 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 -tun1: flags=4099 mtu 1500 +${INTERFACE}: flags=4099 mtu 1500 inet 1.2.3.4 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 @@ -337,7 +339,7 @@ function testPublicIpSegmentWithVPNTurnedOnOsx() { } # Fake ifconfig - fakeIfconfig + fakeIfconfig "tun1" assertEquals "%K{000} %F{007}(vpn) %f%F{007}1.2.3.4 " "$(prompt_public_ip left 1 false "$FOLDER")" From bde4337992e01738e72ef589c321299193580838 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 23 Jan 2019 18:56:07 +0100 Subject: [PATCH 43/79] Match VPN Interface fuzzy --- powerlevel9k.zsh-theme | 22 +++++++++++++++++++--- test/segments/public_ip.spec | 31 ++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 7437fe32a..081562b51 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -600,9 +600,25 @@ prompt_public_ip() { # Check VPN is on if VPN interface is set if [[ -n $POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE ]]; then if [[ "$OS" == "OSX" ]]; then - local interface="$(${ROOT_PREFIX}/sbin/ifconfig $POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE)" - # Check if interface is UP. - [[ "$interface" =~ " $FOLDER/sbin/ifconfig < mtu 1500 inet 1.2.3.4 txqueuelen 1000 (Ethernet) @@ -55,6 +60,7 @@ INNER exit 0 fi +if [[ "\$#" == "0" ]]; then cat < mtu 1500 inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 @@ -81,6 +87,7 @@ lo: flags=73 mtu 65536 TX packets 5136 bytes 328651 (320.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 INNER +fi EOF chmod +x $FOLDER/sbin/ifconfig } @@ -346,4 +353,26 @@ function testPublicIpSegmentWithVPNTurnedOnOsx() { unfunction stat } +function testPublicIpSegmentWithVPNTurnedOnAndFuzzyMatchingOnOsx() { + typeset -F now + now=$(date +%s) + + local OS='OSX' + + echo "1.2.3.4" > $POWERLEVEL9K_PUBLIC_IP_FILE + local POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE="tun" + + # Fake stat call + function stat() { + echo $now + } + + # Fake ifconfig + fakeIfconfig "tun3" + + assertEquals "%K{000} %F{007}(vpn) %f%F{007}1.2.3.4 " "$(prompt_public_ip left 1 false "$FOLDER")" + + unfunction stat +} + source shunit2/shunit2 \ No newline at end of file From 747b94b1b6b8450375a2b1619d8a5c7336be1852 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 23 Jan 2019 19:10:46 +0100 Subject: [PATCH 44/79] Match VPN interface fuzzy on Linux --- powerlevel9k.zsh-theme | 11 +++++++++-- test/segments/public_ip.spec | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 081562b51..3db360507 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -620,8 +620,15 @@ prompt_public_ip() { fi done else - local interface=$(${ROOT_PREFIX}/sbin/ip -brief -4 a show "${POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE}") - [[ -n "$interface" ]] && icon='VPN_ICON' + local -a interfaces + interfaces=( "${(f)$(${ROOT_PREFIX}/sbin/ip -brief -4 a show)}" ) + local pattern="^${POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE}[ ]+UP[ ]+" + for interface in "${(@)interfaces}"; do + if [[ "$interface" =~ $pattern ]]; then + icon='VPN_ICON' + break + fi + done fi fi $1_prompt_segment "$0" "$2" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "${public_ip}" "$icon" diff --git a/test/segments/public_ip.spec b/test/segments/public_ip.spec index 39b0243c9..5ae623218 100755 --- a/test/segments/public_ip.spec +++ b/test/segments/public_ip.spec @@ -113,6 +113,15 @@ function fakeIp() { INNER fi + if [[ "\$*" =~ '-brief.*show' ]]; then + cat < mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 From 8b4bed99df95cfc3e3ad80f500098bab1c9cdb7b Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 23 Jan 2019 22:37:45 +0100 Subject: [PATCH 45/79] Add documentation about VIRTUAL_ENV_DISABLE_PROMPT #1128 --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ebcdd4549..33d787bbd 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ The segments that are currently available are: * [`symfony2_tests`](#symfony2_tests) - Show a ratio of test classes vs code classes for Symfony2. * `symfony2_version` - Show the current Symfony2 version, if you are in a Symfony2-Project dir. * **Python Segments:** - * `virtualenv` - Your Python [VirtualEnv](https://virtualenv.pypa.io/en/latest/). + * [`virtualenv`](#virtualenv) - Your Python [VirtualEnv](https://virtualenv.pypa.io/en/latest/). * [`anaconda`](#anaconda) - Your active [Anaconda](https://www.continuum.io/why-anaconda) environment. * `pyenv` - Your active python version as reported by the first word of [`pyenv version`](https://github.com/yyuu/pyenv). Note that the segment is not displayed if that word is _system_ i.e. the segment is inactive if you are using system python. * **Ruby Segments:** @@ -725,6 +725,12 @@ you are using the [ZSH Line Editor](http://zsh.sourceforge.net/Doc/Release/Zsh-L To hide the segment entirely when in `INSERT` mode, set `POWERLEVEL9K_VI_INSERT_MODE_STRING=''` +##### virtualenv + +This segment shows your Python [VirtualEnv](https://virtualenv.pypa.io/en/latest/). To avoid +VirtualEnvs activate command from interfering with Powerlevel9k, you should set +`VIRTUAL_ENV_DISABLE_PROMPT=1` in your `~/.zshrc`. + #### Unit Test Ratios The `symfony2_tests` and `rspec_stats` segments both show a ratio of "real" From 081000c49e3792a9d2877344650011a7b38a30c3 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 23 Jan 2019 22:47:10 +0100 Subject: [PATCH 46/79] Replace call to basename with ZSH internals #1128 --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 60c16b5a8..383a3b91e 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1652,7 +1652,7 @@ prompt_virtualenv() { # Early exit; $virtualenv_path must always be set. [[ -z "$virtualenv_path" ]] && return - "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$(basename "$virtualenv_path")" 'PYTHON_ICON' + "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "${virtualenv_path:t}" 'PYTHON_ICON' } ################################################################ From 938b0d49a13c2d69181595234e9eda4d72049396 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 23 Jan 2019 23:11:01 +0100 Subject: [PATCH 47/79] Avoid externals when parsing the os release on linux --- functions/utilities.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/utilities.zsh b/functions/utilities.zsh index cedf54938..95f89d995 100755 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -103,7 +103,7 @@ case $(uname) in Linux) OS='Linux' if [ -f /etc/os-release ]; then - os_release_id="$(grep -E '^ID=([a-zA-Z]*)' /etc/os-release | cut -d '=' -f 2)" + [[ ${(f)"$((/dev/null)"} =~ "ID=([A-Za-z]+)" ]] && os_release_id="${match[1]}" fi case "$os_release_id" in *arch*) From 1da5fd2ed79df388bd1b601e5b27f6447e2075f7 Mon Sep 17 00:00:00 2001 From: HaoZeke Date: Wed, 9 May 2018 13:02:48 +0530 Subject: [PATCH 48/79] Revert "Huge performance improvement if you use `rvm` segment." This reverts commit 643555a30c9576838157e04d45632080472e1b8b. This does allow rvm to be detected even without using the depreciated gemset settings. --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 383a3b91e..a0869f196 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1365,10 +1365,10 @@ prompt_rspec_stats() { ################################################################ # Segment to display Ruby Version Manager information prompt_rvm() { - local version_and_gemset=${rvm_env_string/ruby-} + local version_and_gemset=${$(rvm-prompt)/ruby-} if [[ -n "$version_and_gemset" ]]; then - "$1_prompt_segment" "$0" "$2" "grey35" "$DEFAULT_COLOR" "$version_and_gemset" 'RUBY_ICON' + "$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$version_and_gemset" 'RUBY_ICON' fi } From a41f2e81ae30a5e64269c8079e75acfd878a6cb8 Mon Sep 17 00:00:00 2001 From: HaoZeke Date: Fri, 4 Jan 2019 08:44:32 +0530 Subject: [PATCH 49/79] rvm: Only show version and patchset --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index a0869f196..bed5b9cc6 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1365,7 +1365,7 @@ prompt_rspec_stats() { ################################################################ # Segment to display Ruby Version Manager information prompt_rvm() { - local version_and_gemset=${$(rvm-prompt)/ruby-} + local version_and_gemset=${$(rvm-prompt v p)/ruby-} if [[ -n "$version_and_gemset" ]]; then "$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$version_and_gemset" 'RUBY_ICON' From 58f70e57e65097e73604e35b8e8334a8e34afbee Mon Sep 17 00:00:00 2001 From: HaoZeke Date: Sat, 5 Jan 2019 02:29:05 +0530 Subject: [PATCH 50/79] rvm: Use @natemccurdy review suggestions --- powerlevel9k.zsh-theme | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index bed5b9cc6..fc8c47039 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1365,10 +1365,12 @@ prompt_rspec_stats() { ################################################################ # Segment to display Ruby Version Manager information prompt_rvm() { - local version_and_gemset=${$(rvm-prompt v p)/ruby-} + if [ $commands[rvm-prompt] ]; then + local version_and_gemset=${$(rvm-prompt v p)/ruby-} - if [[ -n "$version_and_gemset" ]]; then - "$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$version_and_gemset" 'RUBY_ICON' + if [[ -n "$version_and_gemset" ]]; then + "$1_prompt_segment" "$0" "$2" "240" "$DEFAULT_COLOR" "$version_and_gemset" 'RUBY_ICON' + fi fi } From 1a1572669ce946a095bc27d3d7b175ba83fab7b5 Mon Sep 17 00:00:00 2001 From: Ythildir Date: Thu, 6 Sep 2018 20:30:24 +0200 Subject: [PATCH 51/79] Fix white arrow on newline --- powerlevel9k.zsh-theme | 1 + 1 file changed, 1 insertion(+) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 383a3b91e..4f2caae53 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -364,6 +364,7 @@ prompt_newline() { "$0" \ "$2" \ "NONE" "NONE" "${newline}" + CURRENT_BG='NONE' POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS=$lws } From 020287dd75343e1afca4ee3c87398a0ea08d3a6f Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 1 Feb 2019 11:01:59 +0100 Subject: [PATCH 52/79] Fix Segment endings if followed by newline --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 4f2caae53..ce49db7a4 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -363,7 +363,7 @@ prompt_newline() { "$1_prompt_segment" \ "$0" \ "$2" \ - "NONE" "NONE" "${newline}" + "" "" "${newline}" CURRENT_BG='NONE' POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS=$lws } From 2f05bbbb475fb032b9881a859ef4257c23274e8d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 1 Feb 2019 11:09:42 +0100 Subject: [PATCH 53/79] Remove checking for NODEENV_DISABLE_PROMPT This variable is none of our buisness. --- powerlevel9k.zsh-theme | 5 ++--- test/segments/nodeenv.spec | 20 -------------------- 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 383a3b91e..a4ac080a9 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1238,9 +1238,8 @@ prompt_nvm() { ################################################################ # Segment to display NodeEnv prompt_nodeenv() { - local nodeenv_path="$NODE_VIRTUAL_ENV" - if [[ -n "$nodeenv_path" && "$NODE_VIRTUAL_ENV_DISABLE_PROMPT" != true ]]; then - local info="$(node -v)[$(basename "$nodeenv_path")]" + if [[ -n "$NODE_VIRTUAL_ENV" ]]; then + local info="$(node -v)[${NODE_VIRTUAL_ENV:t}]" "$1_prompt_segment" "$0" "$2" "black" "green" "$info" 'NODE_ICON' fi } diff --git a/test/segments/nodeenv.spec b/test/segments/nodeenv.spec index 2e9d779e0..1a9aaba88 100755 --- a/test/segments/nodeenv.spec +++ b/test/segments/nodeenv.spec @@ -44,26 +44,6 @@ function testNodeenvSegmentPrintsNothingIfNodeVirtualEnvIsNotSet() { unfunction node } -function testNodeenvSegmentPrintsNothingIfNodeVirtualEnvDisablePromptIsSet() { - local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv custom_world) - local POWERLEVEL9K_CUSTOM_WORLD='echo world' - node() { - echo "v1.2.3" - } - NODE_VIRTUAL_ENV="node-env" - NODE_VIRTUAL_ENV_DISABLE_PROMPT=true - - # Load Powerlevel9k - source powerlevel9k.zsh-theme - - assertEquals "%K{007} %F{000}world %k%F{007}%f " "$(build_left_prompt)" - - unset NODE_VIRTUAL_ENV_DISABLE_PROMPT - unset NODE_VIRTUAL_ENV - unfunction node -} - function testNodeenvSegmentPrintsAtLeastNodeEnvWithoutNode() { local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(nodeenv) From c56cbb800aceb56f3cf56dfb6e32527fec7e4c2e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 1 Feb 2019 14:13:02 +0100 Subject: [PATCH 54/79] Add documentation --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 33d787bbd..c440ef2fd 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ The segments that are currently available are: * `go_version` - Show the current GO version. * **Javascript / Node.js Segments:** * `node_version` - Show the version number of the installed Node.js. - * `nodeenv` - [nodeenv](https://github.com/ekalinin/nodeenv) prompt for displaying node version and environment name. + * [`nodeenv`](#nodeenv) - [nodeenv](https://github.com/ekalinin/nodeenv) prompt for displaying node version and environment name. * `nvm` - Show the version of Node that is currently active, if it differs from the version used by NVM * **PHP Segments:** * `php_version` - Show the current PHP version. @@ -557,6 +557,12 @@ prompt itself. This only works on the left side. On the right side it does nothing. +##### nodeenv + +Shows the currently used [nodeenv](https://github.com/ekalinin/nodeenv). To avoid +Nodeenvs activate command from interfering with Powerlevel9k, you should set +`NODE_VIRTUAL_ENV_DISABLE_PROMPT=1` in your `~/.zshrc`. + ##### rbenv This segment shows the version of Ruby being used when using `rbenv` to change your current Ruby stack. From f42214e44b8fa00b766ea2839b79160f0e804a34 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 1 Feb 2019 14:37:17 +0100 Subject: [PATCH 55/79] Add tests for newline segment --- test/segments/newline.spec | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 test/segments/newline.spec diff --git a/test/segments/newline.spec b/test/segments/newline.spec new file mode 100755 index 000000000..7cd00a89e --- /dev/null +++ b/test/segments/newline.spec @@ -0,0 +1,42 @@ +#!/usr/bin/env zsh +#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8 + +# Required for shunit2 to run correctly +setopt shwordsplit +SHUNIT_PARENT=$0 + +function setUp() { + export TERM="xterm-256color" + + P9K_HOME=$(pwd) + ### Test specific +} + +function testNewlineDoesNotCreateExtraSegmentSeparator() { + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local POWERLEVEL9K_CUSTOM_WORLD2="echo world2" + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 newline newline newline custom_world2) + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="OSX" # Fake OSX + + local newline=$'\n' + + assertEquals "%K{007} %F{000}world1 %k%F{007}%f${newline}%k%f${newline}%k%f${newline}%K{007} %F{000}world2 %k%F{007}%f " "$(build_left_prompt)" +} + +function testNewlineMakesPreviousSegmentEndWell() { + local POWERLEVEL9K_CUSTOM_WORLD1="echo world1" + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 newline) + + # Load Powerlevel9k + source ${P9K_HOME}/powerlevel9k.zsh-theme + local OS="OSX" # Fake OSX + + local newline=$'\n' + + assertEquals "%K{007} %F{000}world1 %k%F{007}%f${newline}%k%F{none}%f " "$(build_left_prompt)" +} + +source shunit2/shunit2 \ No newline at end of file From 8f603093862d519caad072e102d22c515e8847b5 Mon Sep 17 00:00:00 2001 From: Wuestengecko <1579756+Wuestengecko@users.noreply.github.com> Date: Fri, 1 Feb 2019 17:43:52 +0100 Subject: [PATCH 56/79] Only abbreviate $HOME at the beginning of cwd Fixes #1150 --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 637248233..43d423a0b 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -797,7 +797,7 @@ prompt_dir() { # using $PWD instead of "$(print -P '%~')" to allow use of POWERLEVEL9K_DIR_PATH_ABSOLUTE local current_path=$PWD # WAS: local current_path="$(print -P '%~')" # check if the user wants to use absolute paths or "~" paths - [[ ${(L)POWERLEVEL9K_DIR_PATH_ABSOLUTE} != "true" ]] && current_path=${current_path//$HOME/"~"} + [[ ${(L)POWERLEVEL9K_DIR_PATH_ABSOLUTE} != "true" ]] && current_path=${current_path/#$HOME/"~"} # declare all local variables local paths directory test_dir test_dir_length trunc_path threshhold # if we are not in "~" or "/", split the paths into an array and exclude "~" From 8bb86908d74097cda237115273acfdbaa5f39ea1 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 1 Feb 2019 23:48:39 +0100 Subject: [PATCH 57/79] Add tests --- test/segments/dir.spec | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/segments/dir.spec b/test/segments/dir.spec index 46e0cfb89..d75ca42f8 100755 --- a/test/segments/dir.spec +++ b/test/segments/dir.spec @@ -768,4 +768,22 @@ function testDirSeparatorColorRootSubSubdirWorks() { rm -fr /tmp/powerlevel9k-test } +function testDirHomeTruncationWorksOnlyAtTheBeginning() { + local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS + POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir) + + local FOLDER=/tmp/p9ktest + local SAVED_HOME="${HOME}" + HOME="/p9ktest" + + mkdir -p $FOLDER + # Setup folder marker + cd $FOLDER + assertEquals "%K{004} %F{000}/tmp/p9ktest %k%F{004}%f " "$(build_left_prompt)" + + cd - + rm -fr $FOLDER + HOME="${SAVED_HOME}" +} + source shunit2/shunit2 From 4b9ccc33bf9279b9bcb575f5088d0a139aeef71e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 3 Feb 2019 01:36:22 +0100 Subject: [PATCH 58/79] Fix issues with debug/fonts script in Konsole --- debug/font-issues.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/debug/font-issues.zsh b/debug/font-issues.zsh index 82f8e60b8..6b505d369 100755 --- a/debug/font-issues.zsh +++ b/debug/font-issues.zsh @@ -222,13 +222,13 @@ END # Get Process ID of current konsole window / tab child="$(get_ppid "$$")" - IFS=$'\n' read -d "" -ra konsole_instances < <(qdbus | grep -F 'org.kde.konsole') + declare -a konsole_instances; konsole_instances=( "${(@f)"$(qdbus | grep -F 'org.kde.konsole')"/ /}" ) for i in "${konsole_instances[@]}"; do - IFS=$'\n' read -d "" -ra konsole_sessions < <(qdbus "$i" | grep -F '/Sessions/') + declare -a konsole_sessions; konsole_sessions=( "${(@f)"$(qdbus "$i" | grep -F '/Sessions/')"}" ) for session in "${konsole_sessions[@]}"; do - if ((child == "$(qdbus "$i" "$session" processId)")); then + if ((child == $(qdbus "$i" "$session" processId))); then profile="$(qdbus "$i" "$session" environment |\ awk -F '=' '/KONSOLE_PROFILE_NAME/ {print $2}')" break From 0081152c28edb96bd12d943803cd01cc5ac6e497 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 3 Feb 2019 08:35:46 +0100 Subject: [PATCH 59/79] Fix parsing font for Kitty --- debug/font-issues.zsh | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/debug/font-issues.zsh b/debug/font-issues.zsh index 6b505d369..6b663514b 100755 --- a/debug/font-issues.zsh +++ b/debug/font-issues.zsh @@ -201,21 +201,13 @@ END ;; "kitty"*) - shopt -s nullglob - confs=({$KITTY_CONFIG_DIRECTORY,$XDG_CONFIG_HOME,~/Library/Preferences}/kitty/kitty.con?) - shopt -u nullglob - - [[ -f "${confs[0]}" ]] || return + kitty_config="$(kitty --debug-config)" + [[ "$kitty_config" != *font_family* ]] && return - term_font="$(awk '/^([[:space:]]*|[^#_])font_family[[:space:]]+/ { - $1 = ""; - gsub(/^[[:space:]]/, ""); - font = $0 - } - /^([[:space:]]*|[^#_])font_size[[:space:]]+/ { - size = $2 - } - END { print font " " size}' "${confs[0]}")" + term_font_size="${kitty_config/*font_size}" + term_font_size="${term_font_size/$'\n'*}" + term_font="${kitty_config/*font_family}" + term_font="${term_font/$'\n'*} $term_font_size" ;; "konsole"*) From 933e95d31c0fec2fbd3e4e3151337ac8293d7d49 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 3 Feb 2019 08:41:32 +0100 Subject: [PATCH 60/79] Use Konsole/Yakuake detection from upstream --- debug/font-issues.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debug/font-issues.zsh b/debug/font-issues.zsh index 6b663514b..c97ea34d2 100755 --- a/debug/font-issues.zsh +++ b/debug/font-issues.zsh @@ -210,7 +210,7 @@ END term_font="${term_font/$'\n'*} $term_font_size" ;; - "konsole"*) + "konsole" | "yakuake") # Get Process ID of current konsole window / tab child="$(get_ppid "$$")" @@ -234,7 +234,7 @@ END profile_filename="${profile_filename/$'\n'*}" [[ "$profile_filename" ]] && \ - term_font="$(awk -F '=|,' '/Font=/ {print $2 " " $3}' "$profile_filename")" + term_font="$(awk -F '=|,' '/Font=/ {print $2,$3}' "$profile_filename")" ;; "lxterminal"*) From d83aacfb3ff01bf1839cf23e96ac9e6878663daa Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 9 Oct 2018 20:05:38 +0200 Subject: [PATCH 61/79] Fix font-debugging script for alacritty --- debug/font-issues.zsh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/debug/font-issues.zsh b/debug/font-issues.zsh index c97ea34d2..135a63491 100755 --- a/debug/font-issues.zsh +++ b/debug/font-issues.zsh @@ -118,13 +118,13 @@ get_term_font() { case "$term" in "alacritty"*) - shopt -s nullglob + setopt nullglob confs=({$XDG_CONFIG_HOME,$HOME}/{alacritty,}/{.,}alacritty.ym?) - shopt -u nullglob + unsetopt nullglob - [[ -f "${confs[0]}" ]] || return + [[ -f "${confs[1]}" ]] || return - term_font="$(awk -F ':|#' '/normal:/ {getline; print}' "${confs[0]}")" + term_font="$(awk -F ':|#' '/normal:/ {getline; print}' "${confs[1]}")" term_font="${term_font/*family:}" term_font="${term_font/$'\n'*}" term_font="${term_font/\#*}" From 0207182eb900a812ed42f47feadc7e24f43960ba Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 4 Dec 2018 08:28:07 +0100 Subject: [PATCH 62/79] Add missing function --- debug/font-issues.zsh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debug/font-issues.zsh b/debug/font-issues.zsh index 135a63491..9fd9be158 100755 --- a/debug/font-issues.zsh +++ b/debug/font-issues.zsh @@ -16,6 +16,12 @@ trim() { set +f } +trim_quotes() { + trim_output="${1//\'}" + trim_output="${trim_output//\"}" + printf "%s" "$trim_output" +} + get_ppid() { # Get parent process ID of PID. case "$os" in From cdf3fa51f21d3ec39cc9a54a9e6271dab11c8741 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 4 Dec 2018 08:28:27 +0100 Subject: [PATCH 63/79] Make variables optional --- debug/font-issues.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/debug/font-issues.zsh b/debug/font-issues.zsh index 9fd9be158..7435e9fe2 100755 --- a/debug/font-issues.zsh +++ b/debug/font-issues.zsh @@ -119,6 +119,7 @@ get_term() { } get_term_font() { + local confs term_font mateterm_config role profile xrdb child profile_filename local term="${1}" # ((term_run != 1)) && get_term From 2fbdb8c982db7af4bec91ed6569351b18d5325b4 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 4 Dec 2018 08:32:04 +0100 Subject: [PATCH 64/79] Mute errors when detecting font --- debug/font-issues.zsh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/debug/font-issues.zsh b/debug/font-issues.zsh index 7435e9fe2..dfd1f90e9 100755 --- a/debug/font-issues.zsh +++ b/debug/font-issues.zsh @@ -163,26 +163,26 @@ END font_file="${HOME}/Library/Preferences/com.googlecode.iterm2.plist" # Count Guids in "New Bookmarks"; they should be unique - profiles_count="$(/usr/libexec/PlistBuddy -c "Print ':New Bookmarks:'" "$font_file" | \ + profiles_count="$(/usr/libexec/PlistBuddy -c "Print ':New Bookmarks:'" "$font_file" 2>/dev/null | \ grep -w -c "Guid")" for ((i=0; i/dev/null)" if [[ "$profile_name" == "$current_profile_name" ]]; then # "Normal Font" term_font="$(/usr/libexec/PlistBuddy -c "Print ':New Bookmarks:${i}:Normal Font:'" \ - "$font_file")" + "$font_file" 2>/dev/null)" # Font for non-ascii characters # Only check for a different non-ascii font, if the user checked # the "use a different font for non-ascii text" switch. diff_font="$(/usr/libexec/PlistBuddy -c "Print ':New Bookmarks:${i}:Use Non-ASCII Font:'" \ - "$font_file")" + "$font_file" 2>/dev/null)" if [[ "$diff_font" == "true" ]]; then non_ascii="$(/usr/libexec/PlistBuddy -c "Print ':New Bookmarks:${i}:Non Ascii Font:'" \ - "$font_file")" + "$font_file" 2>/dev/null)" [[ "$term_font" != "$non_ascii" ]] && \ term_font="$term_font (normal) / $non_ascii (non-ascii)" From 0334f4c2659f413eb38ca52037c00d3823745d35 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 3 Feb 2019 08:58:46 +0100 Subject: [PATCH 65/79] Merge from upstream --- debug/font-issues.zsh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/debug/font-issues.zsh b/debug/font-issues.zsh index dfd1f90e9..5712fc6d6 100755 --- a/debug/font-issues.zsh +++ b/debug/font-issues.zsh @@ -192,13 +192,13 @@ END ;; "deepin-terminal"*) - term_font="$(awk -F '=' '/font=/ {a=$2} /font_size/ {b=$2} END {print a " " b}' \ + term_font="$(awk -F '=' '/font=/ {a=$2} /font_size/ {b=$2} END {print a,b}' \ "${XDG_CONFIG_HOME}/deepin/deepin-terminal/config.conf")" ;; "GNUstep_Terminal") term_font="$(awk -F '>|<' '/>TerminalFontTerminalFontSizeTerminalFontSize Date: Sun, 3 Feb 2019 19:20:14 +0100 Subject: [PATCH 66/79] Parse IPs properly This is done if we want to show a public IP, internal IP, or a VPN. In the VPN case, what we actually want is to display an indicator that a VPN is active, instead of the VPN IP itself. We parse the IP here anyway, because we want to save some specific code there. --- functions/utilities.zsh | 48 ++++++ powerlevel9k.zsh-theme | 76 +-------- test/segments/ip.spec | 351 ++++++++++++++++++++------------------ test/segments/vpn_ip.spec | 33 +++- 4 files changed, 262 insertions(+), 246 deletions(-) diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 127007fb1..a15bf6501 100755 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -371,3 +371,51 @@ function upsearch () { popd > /dev/null fi } + +# Parse IP address from ifconfig on OSX and from IP on Linux +# Parameters: +# $1 - string The desired Interface +# $2 - string A root prefix for testing purposes +function p9k::parseIp() { + local desiredInterface="${1}" + + if [[ -z "${desiredInterface}" ]]; then + desiredInterface="^[^ ]+" + fi + + local ROOT_PREFIX="${2}" + if [[ "$OS" == "OSX" ]]; then + # Get a plain list of all interfaces + local rawInterfaces="$(${ROOT_PREFIX}/sbin/ifconfig -l 2>/dev/null)" + # Parse into array (split by whitespace) + local -a interfaces + interfaces=(${=rawInterfaces}) + # Parse only relevant interface names + local pattern="${desiredInterface}[^ ]?" + local -a relevantInterfaces + for rawInterface in $interfaces; do + [[ "$rawInterface" =~ $pattern ]] && relevantInterfaces+=( $MATCH ) + done + local newline=$'\n' + for interfaceName in $relevantInterfaces; do + local interface="$(${ROOT_PREFIX}/sbin/ifconfig $interfaceName 2>/dev/null)" + # Check if interface is UP. + if [[ "${interface/${newline}/}" =~ "]*>(.*?)inet[ ]*([^ ]*)" ]]; then + echo "${match[3]}" + return 0 + fi + done + else + local -a interfaces + interfaces=( "${(f)$(${ROOT_PREFIX}/sbin/ip -brief -4 a show 2>/dev/null)}" ) + local pattern="^${desiredInterface}[ ]+UP[ ]+([^/ ]+)" + for interface in "${(@)interfaces}"; do + if [[ "$interface" =~ $pattern ]]; then + echo "${match[1]}" + return 0 + fi + done + fi + + return 1 +} diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 3db360507..d114fcc89 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -599,36 +599,9 @@ prompt_public_ip() { icon='PUBLIC_IP_ICON' # Check VPN is on if VPN interface is set if [[ -n $POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE ]]; then - if [[ "$OS" == "OSX" ]]; then - # Get a plain list of all interfaces - local rawInterfaces="$(${ROOT_PREFIX}/sbin/ifconfig -l)" - # Parse into array (split by whitespace) - local -a interfaces - interfaces=(${=rawInterfaces}) - # Parse only relevant interface names - local pattern="${POWERLEVEL9K_PUBLIC_IP_VPN_INTERFACE}[^ ]?" - local -a relevantInterfaces - for rawInterface in $interfaces; do - [[ "$rawInterface" =~ $pattern ]] && relevantInterfaces+=( $MATCH ) - done - for interfaceName in $relevantInterfaces; do - local interface="$(${ROOT_PREFIX}/sbin/ifconfig $interfaceName)" - # Check if interface is UP. - if [[ "$interface" =~ " $FOLDER/sbin/ifconfig < mtu 1500 + inet ${INTERFACE1_IP} txqueuelen 1000 (Ethernet) + RX packets 0 bytes 0 (0.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 0 bytes 0 (0.0 B) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + device interrupt 16 memory 0xe8200000-e8220000 +INNER + exit 0 +fi + +if [[ "\$*" =~ '${INTERFACE2}' ]]; then + cat < mtu 1500 + inet ${INTERFACE2_IP} txqueuelen 1000 (Ethernet) + RX packets 0 bytes 0 (0.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 0 bytes 0 (0.0 B) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + device interrupt 16 memory 0xe8200000-e8220000 +INNER + exit 0 +fi + + +# If neither INTERFACE1 nor INTERFACE2 is queried, fake a offline (DOWN) interface. +# We assume if there is at least one argument, we queried for a specific interface. +if [[ "\$#" -gt 0 ]]; then + cat < mtu 1500 + inet 5.5.5.5 txqueuelen 1000 (Ethernet) + RX packets 0 bytes 0 (0.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 0 bytes 0 (0.0 B) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + device interrupt 16 memory 0xe8200000-e8220000 +INNER + exit 0 +fi + +if [[ "\$#" -eq 0 ]]; then + cat < mtu 1500 + inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 + ether 02:42:8f:5c:ed:51 txqueuelen 0 (Ethernet) + RX packets 0 bytes 0 (0.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 0 bytes 0 (0.0 B) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + +tun1: flags=4099 mtu 1500 + inet 10.20.30.40 txqueuelen 1000 (Ethernet) + RX packets 0 bytes 0 (0.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 0 bytes 0 (0.0 B) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + device interrupt 16 memory 0xe8200000-e8220000 + +${INTERFACE1}: flags=4099 mtu 1500 + inet ${INTERFACE1_IP} txqueuelen 1000 (Ethernet) + RX packets 0 bytes 0 (0.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 0 bytes 0 (0.0 B) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + device interrupt 16 memory 0xe8200000-e8220000 + +${INTERFACE2}: flags=4099 mtu 1500 + inet ${INTERFACE2_IP} txqueuelen 1000 (Ethernet) + RX packets 0 bytes 0 (0.0 B) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 0 bytes 0 (0.0 B) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 + device interrupt 16 memory 0xe8200000-e8220000 + +lo: flags=73 mtu 65536 + inet 127.0.0.1 netmask 255.0.0.0 + inet6 ::1 prefixlen 128 scopeid 0x10 + loop txqueuelen 1000 (Local Loopback) + RX packets 5136 bytes 328651 (320.9 KiB) + RX errors 0 dropped 0 overruns 0 frame 0 + TX packets 5136 bytes 328651 (320.9 KiB) + TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 +INNER +exit 0 +fi +EOF + chmod +x $FOLDER/sbin/ifconfig } -function testIpSegmentWorksOnOsxWithNoInterfaceSpecified() { - local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) - alias networksetup="echo 'An asterisk (*) denotes that a network service is disabled. -(1) Ethernet -(Hardware Port: Ethernet, Device: en0) - -(2) FireWire -(Hardware Port: FireWire, Device: fw0) +function fakeIp() { + local INTERFACE1="${1}" + [[ -z "${INTERFACE1}" ]] && INTERFACE1="eth0" + local INTERFACE2="${2}" + [[ -z "${INTERFACE2}" ]] && INTERFACE2="disabled-if2" + cat > $FOLDER/sbin/ip < mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 + inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 + valid_lft forever preferred_lft forever +INNER + fi + + if [[ "\$*" =~ 'show ${INTERFACE2}' ]]; then + cat < mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 + inet 1.2.3.4 brd 10.0.2.255 scope global eth0 + valid_lft forever preferred_lft forever +INNER + fi +EOF + + chmod +x $FOLDER/sbin/ip +} -(4) Bluetooth PAN -(Hardware Port: Bluetooth PAN, Device: en3) +function testIpSegmentPrintsNothingOnOsxIfNotConnected() { + cat > $FOLDER/sbin/ifconfig < $FOLDER/sbin/ip < mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default - link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 -2: eth0: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 - link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff"; - fi - - if [[ "$*" == '-4 a show eth0' ]]; then - echo '2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 - inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 - valid_lft forever preferred_lft forever'; - fi - } - - # Load Powerlevel9k - source powerlevel9k.zsh-theme - local OS='Linux' # Fake Linux - - assertEquals "%K{006} %F{000}IP %f%F{000}10.0.2.15 %k%F{006}%f " "$(build_left_prompt)" - - unfunction ip -} - -function testIpSegmentWorksOnLinuxWithMultipleInterfacesSpecified() { - setopt aliases - local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) - # That command is harder to test, as it is used at first - # to get all relevant network interfaces and then for - # getting the configuration of that segment.. - ip(){ - if [[ "$*" == 'link ls up' ]]; then - echo "1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default - link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 -2: eth0: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 - link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff -3: eth1: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 - link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff -4: wlan0: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 - link/ether 08:00:27:7e:84:45 brd ff:ff:ff:ff:ff:ff"; - fi - - if [[ "$*" == '-4 a show eth1' ]]; then - echo '3: eth1: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 - inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 - valid_lft forever preferred_lft forever'; - fi - } - # Load Powerlevel9k source powerlevel9k.zsh-theme local OS='Linux' # Fake Linux - assertEquals "%K{006} %F{000}IP %f%F{000}10.0.2.15 %k%F{006}%f " "$(build_left_prompt)" + fakeIp "eth0" - unfunction ip + assertEquals "%K{006} %F{000}IP %f%F{000}1.2.3.4 " "$(prompt_ip left 1 false "$FOLDER")" } function testIpSegmentWorksOnLinuxWithInterfaceSpecified() { - local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ip) - local POWERLEVEL9K_IP_INTERFACE='xxx' - ip(){ - echo '2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 -inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 - valid_lft forever preferred_lft forever'; - } + fakeIp "eth3" # Load Powerlevel9k source powerlevel9k.zsh-theme local OS='Linux' # Fake Linux - assertEquals "%K{006} %F{000}IP %f%F{000}10.0.2.15 %k%F{006}%f " "$(build_left_prompt)" - - unfunction ip + assertEquals "%K{006} %F{000}IP %f%F{000}1.2.3.4 " "$(prompt_ip left 1 false "$FOLDER")" } source shunit2/shunit2 \ No newline at end of file diff --git a/test/segments/vpn_ip.spec b/test/segments/vpn_ip.spec index 3333fd07d..13a3e60a4 100755 --- a/test/segments/vpn_ip.spec +++ b/test/segments/vpn_ip.spec @@ -95,6 +95,15 @@ function fakeIp() { INNER fi + if [[ "\$*" =~ '-brief.*show' ]]; then + cat < mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 @@ -116,27 +125,33 @@ EOF } function testVpnIpSegmentPrintsNothingOnOsxIfNotConnected() { - alias ifconfig='echo "not connected"' - # Load Powerlevel9k source powerlevel9k.zsh-theme local OS="OSX" # Fake OSX - assertEquals "" "$(prompt_vpn_ip left 1 false "$FOLDER")" + cat > $FOLDER/sbin/ifconfig < $FOLDER/sbin/ip < Date: Mon, 4 Feb 2019 15:40:31 +0100 Subject: [PATCH 67/79] Fix regular expression and test --- functions/utilities.zsh | 2 +- test/segments/ip.spec | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 9a72eab85..5532eef6e 100755 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -402,7 +402,7 @@ function p9k::parseIp() { for interfaceName in $relevantInterfaces; do local interface="$(${ROOT_PREFIX}/sbin/ifconfig $interfaceName 2>/dev/null)" # Check if interface is UP. - if [[ "${interface/${newline}/}" =~ "]*>(.*?)inet[ ]*([^ ]*)" ]]; then + if [[ "${interface/${newline}/}" =~ "]*>(.*)inet[ ]*([^ ]*)" ]]; then echo "${match[3]}" return 0 fi diff --git a/test/segments/ip.spec b/test/segments/ip.spec index 9fb0bddba..2dce55f79 100755 --- a/test/segments/ip.spec +++ b/test/segments/ip.spec @@ -212,6 +212,8 @@ function testIpSegmentWorksOnOsxWithNoInterfaceSpecified() { function testIpSegmentWorksOnOsxWithInterfaceSpecified() { fakeIfconfig "eth1" + local POWERLEVEL9K_IP_INTERFACE="eth1" + # Load Powerlevel9k source powerlevel9k.zsh-theme local OS='OSX' # Fake OSX @@ -232,6 +234,8 @@ function testIpSegmentWorksOnLinuxWithNoInterfaceSpecified() { function testIpSegmentWorksOnLinuxWithInterfaceSpecified() { fakeIp "eth3" + local POWERLEVEL9K_IP_INTERFACE="eth3" + # Load Powerlevel9k source powerlevel9k.zsh-theme local OS='Linux' # Fake Linux From 9f9bc62dc9c934fadd799c6942cc4099228b07be Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 6 Feb 2019 08:53:46 +0100 Subject: [PATCH 68/79] Avoid loopback interfaces and parse IPv4 on OSX --- functions/utilities.zsh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 5532eef6e..13a7b82d1 100755 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -401,8 +401,11 @@ function p9k::parseIp() { local newline=$'\n' for interfaceName in $relevantInterfaces; do local interface="$(${ROOT_PREFIX}/sbin/ifconfig $interfaceName 2>/dev/null)" + if [[ "${interface}" =~ "lo[0-9]*" ]]; then + continue + fi # Check if interface is UP. - if [[ "${interface/${newline}/}" =~ "]*>(.*)inet[ ]*([^ ]*)" ]]; then + if [[ "${interface/${newline}/}" =~ "]*>(.*)inet[ ]+([^ ]*)" ]]; then echo "${match[3]}" return 0 fi From d1fbc1b889f63f6ea3e9672b7069133493ccab8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=90=88?= <88maomao@gmail.com> Date: Wed, 6 Feb 2019 11:51:41 +0200 Subject: [PATCH 69/79] Hide errors from git ls-files --- functions/vcs.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/vcs.zsh b/functions/vcs.zsh index cb53dd3e8..04a07e5df 100755 --- a/functions/vcs.zsh +++ b/functions/vcs.zsh @@ -15,10 +15,10 @@ function +vi-git-untracked() { # dump out if we're outside a git repository (which includes being in the .git folder) [[ $? != 0 || -z $repoTopLevel ]] && return - local untrackedFiles=$(command git ls-files --others --exclude-standard "${repoTopLevel}") + local untrackedFiles=$(command git ls-files --others --exclude-standard "${repoTopLevel}" 2> /dev/null) if [[ -z $untrackedFiles && "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" ]]; then - untrackedFiles+=$(command git submodule foreach --quiet --recursive 'command git ls-files --others --exclude-standard') + untrackedFiles+=$(command git submodule foreach --quiet --recursive 'command git ls-files --others --exclude-standard' 2> /dev/null) fi [[ -z $untrackedFiles ]] && return From 1ab6a32c4b4871e4161cd75e485c203d0c2111e7 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 21 Feb 2019 18:32:17 +0100 Subject: [PATCH 70/79] Interface States can be unsorted --- functions/utilities.zsh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 13a7b82d1..069fb1a80 100755 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -405,9 +405,13 @@ function p9k::parseIp() { continue fi # Check if interface is UP. - if [[ "${interface/${newline}/}" =~ "]*>(.*)inet[ ]+([^ ]*)" ]]; then - echo "${match[3]}" - return 0 + if [[ "${interface/${newline}/}" =~ "<([^>]*)>(.*?)inet[ ]+([^ ]*)" ]]; then + local ipFound="${match[3]}" + local -a interfaceStates=(${(s:,:)match[1]}) + if [[ "${interfaceStates[(r)UP]}" == "UP" ]]; then + echo "${ipFound}" + return 0 + fi fi done else From fef639eb488fb99007526cfa2d1d09c901fca3cc Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 22 Feb 2019 18:16:15 +0100 Subject: [PATCH 71/79] Fix regex --- functions/utilities.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 069fb1a80..2e6d98dd3 100755 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -405,7 +405,7 @@ function p9k::parseIp() { continue fi # Check if interface is UP. - if [[ "${interface/${newline}/}" =~ "<([^>]*)>(.*?)inet[ ]+([^ ]*)" ]]; then + if [[ "${interface/${newline}/}" =~ "<([^>]*)>(.*)inet[ ]+([^ ]*)" ]]; then local ipFound="${match[3]}" local -a interfaceStates=(${(s:,:)match[1]}) if [[ "${interfaceStates[(r)UP]}" == "UP" ]]; then From 1049bca47373e1d8700dc81d2c61a30d83cbb899 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 22 Feb 2019 18:16:33 +0100 Subject: [PATCH 72/79] Strip all newlines from ifconfig output --- functions/utilities.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 2e6d98dd3..8c18bb44d 100755 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -405,7 +405,7 @@ function p9k::parseIp() { continue fi # Check if interface is UP. - if [[ "${interface/${newline}/}" =~ "<([^>]*)>(.*)inet[ ]+([^ ]*)" ]]; then + if [[ "${interface//${newline}/}" =~ "<([^>]*)>(.*)inet[ ]+([^ ]*)" ]]; then local ipFound="${match[3]}" local -a interfaceStates=(${(s:,:)match[1]}) if [[ "${interfaceStates[(r)UP]}" == "UP" ]]; then From 0dbfa4e1e4bfd65311403884168b7cddb17cdbdc Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 25 Feb 2019 18:22:59 +0100 Subject: [PATCH 73/79] Add small changes suggested by @Syphdias --- test/segments/ip.spec | 3 +-- test/segments/public_ip.spec | 3 +-- test/segments/vpn_ip.spec | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/test/segments/ip.spec b/test/segments/ip.spec index 2dce55f79..86819e19d 100755 --- a/test/segments/ip.spec +++ b/test/segments/ip.spec @@ -12,7 +12,6 @@ function setUp() { P9K_HOME=$(pwd) FOLDER=/tmp/powerlevel9k-test mkdir -p $FOLDER - mkdir $FOLDER/bin mkdir $FOLDER/sbin } @@ -152,7 +151,7 @@ INNER if [[ "\$*" =~ 'show ${INTERFACE1}' ]]; then cat < mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 +2: ${INTERFACE1}: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 valid_lft forever preferred_lft forever INNER diff --git a/test/segments/public_ip.spec b/test/segments/public_ip.spec index 2c7a00e94..19c3adbc6 100755 --- a/test/segments/public_ip.spec +++ b/test/segments/public_ip.spec @@ -12,7 +12,6 @@ function setUp() { P9K_HOME=$(pwd) FOLDER=/tmp/powerlevel9k-test mkdir -p $FOLDER - mkdir $FOLDER/bin mkdir $FOLDER/sbin cd $FOLDER @@ -124,7 +123,7 @@ INNER if [[ "\$*" =~ 'show ${INTERFACE1}' ]]; then cat < mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 +2: ${INTERFACE1}: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 valid_lft forever preferred_lft forever INNER diff --git a/test/segments/vpn_ip.spec b/test/segments/vpn_ip.spec index 870126e58..fe5b5fbc1 100755 --- a/test/segments/vpn_ip.spec +++ b/test/segments/vpn_ip.spec @@ -12,7 +12,6 @@ function setUp() { P9K_HOME=$(pwd) FOLDER=/tmp/powerlevel9k-test mkdir -p $FOLDER - mkdir $FOLDER/bin mkdir $FOLDER/sbin } @@ -106,7 +105,7 @@ INNER if [[ "\$*" =~ 'show ${INTERFACE1}' ]]; then cat < mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 +2: ${INTERFACE1}: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 valid_lft forever preferred_lft forever INNER From 3057e8fc07374e9c580790a023cb85998ca91fc8 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Fri, 1 Mar 2019 23:31:21 +0100 Subject: [PATCH 74/79] Backport @wrboyce fix for truncating dir with package name from #1158 --- powerlevel9k.zsh-theme | 2 ++ 1 file changed, 2 insertions(+) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 427e9b009..4939cb354 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -905,6 +905,8 @@ prompt_dir() { package_path=${$(pwd)%%/.git*} fi + [[ ${(L)POWERLEVEL9K_DIR_PATH_ABSOLUTE} != "true" ]] && package_path=${package_path/$HOME/"~"} + # Replace the shortest possible match of the marked folder from # the current path. Remove the amount of characters up to the # folder marker from the left. Count only the visible characters From 72991dd9e7fb465e53981f076ec5e44bc4f3bbb3 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 5 Mar 2019 21:57:37 +0100 Subject: [PATCH 75/79] Improve code style --- .github/ISSUE_TEMPLATE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 01fbc4132..8f6b31646 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -14,11 +14,11 @@ Most issues are best explained with a screenshot. Please share one if you can! #### Have you tried to debug or fix it? - Have you tinkered with your settings, and what happened when you did? Did you find a bit of code that you think might be the culprit? Let us know what you've done so far! #### Environment Information -This information will help us understand your configuration. + +This information will help us understand your configuration. - What version of ZSH are you using? You can use `zsh --version` to see this. - Do you use a ZSH framework (e.g., Oh-My-ZSH, Antigen)? From e5990572a34a767f321187ffc070ba34027a0d63 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 5 Mar 2019 22:30:30 +0100 Subject: [PATCH 76/79] Improve code style --- .github/PULL_REQUEST_TEMPLATE.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 4ade8059e..76b1fac95 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -14,19 +14,20 @@ Once you have submitted your PR, P9k core contributors will review the code and Please follow this template for creating your PR: #### Title + Please make the title of your PR descriptive! If appropriate, please prefix the title with one of these tags: - - [Bugfix] - - [New Segment] - - [Docs] - - [Enhancement] - +- [Bugfix] +- [New Segment] +- [Docs] +- [Enhancement] + #### Description + Please describe the contribution your PR makes! Screenshots are especially helpful, here, if it's a new segment. If your PR is addressing an issue, please reference the Issue number here. #### Questions -Is there something in your PR you're not sure about or need help with? Is there a particular piece of code you would like feedback on? Let us know here! - +Is there something in your PR you're not sure about or need help with? Is there a particular piece of code you would like feedback on? Let us know here! From 6bf7498b544115cfa67330e6a03b371261872f21 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 5 Mar 2019 22:52:48 +0100 Subject: [PATCH 77/79] Add Performance Issue Template --- .../{ => ISSUE_TEMPLATE}/ISSUE_TEMPLATE.md | 9 +++++ .../PERFORMANCE_ISSUE_TEMPLATE.md | 38 +++++++++++++++++++ 2 files changed, 47 insertions(+) rename .github/{ => ISSUE_TEMPLATE}/ISSUE_TEMPLATE.md (95%) create mode 100644 .github/ISSUE_TEMPLATE/PERFORMANCE_ISSUE_TEMPLATE.md diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md similarity index 95% rename from .github/ISSUE_TEMPLATE.md rename to .github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md index 8f6b31646..5070d714e 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md @@ -1,3 +1,12 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + Thanks for opening an issue! For a project that deals with as many different things as P9k, debugging problems can be difficult. Please follow the guide, below, to create a bug report that will help us help you! ### Before Opening a Bug diff --git a/.github/ISSUE_TEMPLATE/PERFORMANCE_ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE/PERFORMANCE_ISSUE_TEMPLATE.md new file mode 100644 index 000000000..9d852db06 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/PERFORMANCE_ISSUE_TEMPLATE.md @@ -0,0 +1,38 @@ +--- +name: Performance Issue +about: For performance Issues +title: "[Performance]" +labels: performance +assignees: '' + +--- + +Sorry to hear that the performance of P9K is not adequate. To fix this, please provide us with some hints. + +### Your Hardware + +Disk I/O is critical for P9K, so do you use a spinning disk, or a SSD? + +### Virtualization + +Do you use P9K in some sort of virtualization? This is also the case, if you use WSL on Windows.. + +### How Fast is Fast + +Could you quantify how fast the specific segment is, that you think is slow? +For example, if you think the `vcs` segment is slow, could you execute this command in the directory, where the segment is slow: + +```zsh +time (repeat 10; do; prompt_vcs left 1 false >/dev/null; done;) +``` + +Also, please provide us with some context around the segment. In the `vcs` example: + +- How big is the repo? +- Does it contain a lot of untracked files? +- Does it contain a lot of git submodules? +- Does it contain a lot of files in general? + +Additionally, you could install [zsh-prompt-benchmark](https://github.com/romkatv/zsh-prompt-benchmark), to benchmark the general performance of ZSH and P9K. + +If you don't know which segment is slow, could you remove one by one, and spot the one that made the greatest impact? \ No newline at end of file From a1747327fed78c1b9122643b635cf8b914b8b427 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 6 Mar 2019 00:19:58 +0100 Subject: [PATCH 78/79] Add changelog for v0.6.7 --- CHANGELOG.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b40ce50b3..271ae9ed7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,29 @@ +## v0.6.7 + +- PR #1175 - Fix home dir shortening when using package_name truncation strategy +- PR #1158 - [Bugfix] dir: Fix package name path truncation inside home dir +- PR #1157 - Hide stderr from git ls-files +- PR #1154 - Fix issues with debug/fonts script in Konsole +- PR #1151 - [Bugfix] Only abbreviate $HOME at the beginning of cwd +- PR #1148 - Remove checking for NODEENV_DISABLE_PROMPT +- PR #1147 - Fix newlines in ZSH 5.7 +- PR #1149 - Fix RVM +- PR #1128 - [Bugfix] virtualenv prompt displaying +- PR #981 - [Bugfix] Fix for #974 +- PR #1126 - Use ip command for VPN segment +- PR #1079 - [Bugfix] Update VIRTUAL_ENV_DISABLE_PROMPT value +- PR #1080 - [Bugfix] Port #1071 to `master` (Fix fatal errors emitted by untracked file check in vcs.zsh) +- PR #1074 - Add vcs vulnerability tests master +- PR #1070 - [Docs] Uniformly apply inline code formatting in README +- PR #1065 - Protect locale +- PR #1048 - Speedup Improvements in `vcs` segment +- PR #1037 - Fix vpn_ip segment +- PR #1036 - Make truncate with package name work without setting shorten length +- PR #1020 - Fix context spec +- PR #990 - [Docs] Add forgotten backtick +- PR #981 - Avoid error if `/etc/os-release` does not exist +- PR #966 - [Bugfix] Fix icons cut off in RPROMPT segments + ## v0.6.6 - The `rbenv` segment is no longer a default segment in the LPROMPT. From 7554ae9d6784aaa46514930488e1ac80d0394d8f Mon Sep 17 00:00:00 2001 From: Nicolas Badoux Date: Fri, 8 Mar 2019 16:56:31 +0100 Subject: [PATCH 79/79] doc battery threshold --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c440ef2fd..b4e5fb2c8 100644 --- a/README.md +++ b/README.md @@ -208,6 +208,7 @@ systems without a battery). It is supported on both OSX and Linux (note that it |`POWERLEVEL9K_BATTERY_LOW_THRESHOLD`|`10`|Threshold to consider battery level critical.| |`POWERLEVEL9K_BATTERY_LOW_COLOR`|`"red"`|Color to indicate critically low charge level.| |`POWERLEVEL9K_BATTERY_VERBOSE`|`true`|Display time remaining next to battery level.| +|`POWERLEVEL9K_BATTERY_HIDE_ABOVE_THRESHOLD`|`unset`|Threshold from which the battery segment should not be displayed.| Note that you can [modify the `_FOREGROUND` color](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt#segment-color-customization)