From 5fd171c33421fcea2af034e7a0083235f005b401 Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Sat, 5 May 2018 13:25:29 -0400 Subject: [PATCH 1/3] Fixed prompt_rust_version to avoid grep aliases --- powerlevel9k.zsh-theme | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 0e09ef03..c901103d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1104,10 +1104,14 @@ prompt_root_indicator() { # Print Rust version number prompt_rust_version() { local rust_version - rust_version=$(rustc --version 2>&1 | grep -oe "^rustc\s*[^ ]*" | grep -o '[0-9.a-z\\\-]*$') + rust_version=$(command rustc --version 2>&1) + # Remove "rustc " (including the whitespace) from the beginning + # of the version string and remove everything after the next + # whitespace. This way we'll end up with only the version. + rust_version=${${rust_version/rustc /}%% *} if [[ -n "$rust_version" ]]; then - "$1_prompt_segment" "$0" "$2" "208" "$DEFAULT_COLOR" "Rust $rust_version" 'RUST_ICON' + "$1_prompt_segment" "$0" "$2" "208" "$DEFAULT_COLOR" "$rust_version" 'RUST_ICON' fi } # RSpec test ratio From 9b0e0c786af71048c3f615e99de079d7ff86266e Mon Sep 17 00:00:00 2001 From: Daniel Kolsoi Date: Wed, 9 May 2018 23:37:32 -0400 Subject: [PATCH 2/3] Removed 'Rust' text from test; Silenced missing rustc warning --- powerlevel9k.zsh-theme | 2 +- test/segments/rust_version.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c901103d..530b0d9a 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1104,7 +1104,7 @@ prompt_root_indicator() { # Print Rust version number prompt_rust_version() { local rust_version - rust_version=$(command rustc --version 2>&1) + rust_version=$(command rustc --version 2>/dev/null) # Remove "rustc " (including the whitespace) from the beginning # of the version string and remove everything after the next # whitespace. This way we'll end up with only the version. diff --git a/test/segments/rust_version.spec b/test/segments/rust_version.spec index 49b06bcf..8274789f 100755 --- a/test/segments/rust_version.spec +++ b/test/segments/rust_version.spec @@ -19,7 +19,7 @@ function testRust() { alias rustc=mockRust POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(rust_version) - assertEquals "%K{208} %F{black}Rust 0.4.1a-alpha %k%F{208}%f " "$(build_left_prompt)" + assertEquals "%K{208} %F{black}0.4.1a-alpha %k%F{208}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unalias rustc From 27bd1cd65df8878812adefcf1ab6974660c2714d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 12 May 2018 23:17:49 +0200 Subject: [PATCH 3/3] Fix test for rust segment --- powerlevel9k.zsh-theme | 1 + test/segments/rust_version.spec | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 530b0d9a..2b21b3de 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1114,6 +1114,7 @@ prompt_rust_version() { "$1_prompt_segment" "$0" "$2" "208" "$DEFAULT_COLOR" "$rust_version" 'RUST_ICON' fi } + # RSpec test ratio prompt_rspec_stats() { if [[ (-d app && -d spec) ]]; then diff --git a/test/segments/rust_version.spec b/test/segments/rust_version.spec index 8274789f..85b4ec69 100755 --- a/test/segments/rust_version.spec +++ b/test/segments/rust_version.spec @@ -5,28 +5,39 @@ setopt shwordsplit SHUNIT_PARENT=$0 +TEST_BASE_FOLDER=/tmp/powerlevel9k-test +RUST_TEST_FOLDER="${TEST_BASE_FOLDER}/rust-test" + function setUp() { + OLDPATH="${PATH}" + mkdir -p "${RUST_TEST_FOLDER}" + PATH="${RUST_TEST_FOLDER}:${PATH}" + export TERM="xterm-256color" # Load Powerlevel9k source powerlevel9k.zsh-theme } +function tearDown() { + PATH="${OLDPATH}" + rm -fr "${TEST_BASE_FOLDER}" +} + function mockRust() { - echo 'rustc 0.4.1a-alpha' + echo "#!/bin/sh\n\necho 'rustc 0.4.1a-alpha'" > "${RUST_TEST_FOLDER}/rustc" + chmod +x "${RUST_TEST_FOLDER}/rustc" } function testRust() { - alias rustc=mockRust + mockRust POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(rust_version) assertEquals "%K{208} %F{black}0.4.1a-alpha %k%F{208}%f " "$(build_left_prompt)" unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS - unalias rustc } function testRustPrintsNothingIfRustIsNotAvailable() { - alias rustc=noRust POWERLEVEL9K_CUSTOM_WORLD='echo world' POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world rust_version) @@ -34,7 +45,6 @@ function testRustPrintsNothingIfRustIsNotAvailable() { unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS unset POWERLEVEL9K_CUSTOM_WORLD - unalias rustc } source shunit2/source/2.1/src/shunit2