Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Added changes from Spaceship upstream! 🚀⭐ #79

Merged
merged 2 commits into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ Rust section is shown only in directories that contain `Cargo.toml` or any other
| `SPACEFISH_RUST_SUFFIX` | `$SPACEFISH_PROMPT_DEFAULT_SUFFIX` | Suffix after the Rust section |
| `SPACEFISH_RUST_SYMBOL` | `𝗥·` | Character to be shown before Rust version |
| `SPACEFISH_RUST_COLOR` | `red` | Color of Rust section |
| `SPACEFISH_RUST_VERBOSE_VERSION` | `false` | Show what branch is being used, if any. (Beta, Nightly) |

### Kubectl context \(`kubecontext`\)

Expand Down
7 changes: 6 additions & 1 deletion functions/__sf_section_rust.fish
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function __sf_section_rust -d "Display the current Rust version"
__sf_util_set_default SPACEFISH_RUST_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX
__sf_util_set_default SPACEFISH_RUST_SYMBOL "𝗥 "
__sf_util_set_default SPACEFISH_RUST_COLOR red
__sf_util_set_default SPACEFISH_RUST_VERBOSE_VERSION false

# ------------------------------------------------------------------------------
# Section
Expand All @@ -30,7 +31,11 @@ function __sf_section_rust -d "Display the current Rust version"
return
end

set -l rust_version (rustc --version | cut -d' ' -f2)
set -l rust_version (rustc --version | string split ' ')[2]

if test $SPACEFISH_RUST_VERBOSE_VERSION = false
set rust_version (string split '-' $rust_version)[1] # Cut off -suffixes from version. "v1.30.0-beta" vs "v1.30.0"
end

__sf_lib_section \
$SPACEFISH_RUST_COLOR \
Expand Down
19 changes: 18 additions & 1 deletion tests/__sf_section_rust.test.fish
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source $DIRNAME/mock.fish

function setup
spacefish_test_setup
mock rustc 0 "echo \"rustc 1.28.0 (9634041f0 2018-07-30)\""
mock rustc 0 "echo \"rustc 1.28.0-nightly (9634041f0 2018-07-30)\""
mkdir -p /tmp/tmp-spacefish
touch /tmp/tmp-spacefish/Cargo.toml
cd /tmp/tmp-spacefish
Expand Down Expand Up @@ -100,6 +100,23 @@ test "Changing SPACEFISH_RUST_SUFFIX changes the character prefix"
) = (__sf_section_rust)
end

test "Prints verbose version when configured to do so"
(
touch /tmp/tmp-spacefish/testfile.rs
set SPACEFISH_RUST_VERBOSE_VERSION true

set_color --bold fff
echo -n "via "
set_color normal
set_color --bold red
echo -n "𝗥 v1.28.0-nightly"
set_color normal
set_color --bold fff
echo -n " "
set_color normal
) = (__sf_section_rust)
end

test "Doesn't display node when SPACEFISH_RUST_SHOW is set to 'false'"
(
set SPACEFISH_RUST_SHOW false
Expand Down