Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a rustc version segment with multiple install options #314

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ set -g theme_display_hg yes
set -g theme_display_virtualenv no
set -g theme_display_nix no
set -g theme_display_ruby no
set -g theme_display_rustc no
set -g theme_display_node yes
set -g theme_display_user ssh
set -g theme_display_hostname ssh
Expand Down Expand Up @@ -125,6 +126,7 @@ set -g theme_newline_prompt '$ '

- `theme_display_ruby`. Use `no` to completely hide all information about Ruby version. By default Ruby version displayed if there is the difference from default settings.
- `theme_display_node`. If set to `always`, will display current NPM, NVM or FNM node version. If set to `yes`, will display the version if an `.nvmrc`, `.node-version` or `package.json` file is found in the parent directories.
- `theme_display_rustc`. If set to `always`, will always show the rustc version. If set to `yes`, will show the version when inside a Cargo project. Use `diff` to show the rustc version if there is a difference from global rustc installed (if any). By default, we do not show the information.
- `theme_display_vagrant`. This feature is disabled by default, use `yes` to display Vagrant status in your prompt. Please note that only the VirtualBox and VMWare providers are supported.
- `theme_display_vi`. By default the vi mode indicator will be shown if vi or hybrid key bindings are enabled. Use `no` to hide the indicator, or `yes` to show the indicator.
- `theme_display_k8s_context`. This feature is disabled by default. Use `yes` to show the current kubernetes context (`> kubectl config current-context`).
Expand Down
15 changes: 15 additions & 0 deletions functions/__bobthefish_colors.fish
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_virtualgo brblue $colorfg --bold
set -x color_desk brblue $colorfg --bold
set -x color_nix brblue $colorfg --bold
set -x color_rustc brred $colorfg --bold

case 'terminal-light*'
set -l colorfg white
Expand Down Expand Up @@ -73,6 +74,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_virtualgo brblue $colorfg --bold
set -x color_desk brblue $colorfg --bold
set -x color_nix brblue $colorfg --bold
set -x color_rustc brred $colorfg --bold

case 'terminal2' 'terminal2-dark*'
set -l colorfg black
Expand Down Expand Up @@ -108,6 +110,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_virtualgo brblue $colorfg --bold
set -x color_desk brblue $colorfg --bold
set -x color_nix brblue $colorfg --bold
set -x color_rustc brred $colorfg --bold

case 'terminal2-light*'
set -l colorfg white
Expand Down Expand Up @@ -143,6 +146,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_virtualgo brblue $colorfg --bold
set -x color_desk brblue $colorfg --bold
set -x color_nix brblue $colorfg --bold
set -x color_rustc brred $colorfg --bold

case 'zenburn'
set -l grey 333333 # a bit darker than normal zenburn grey
Expand Down Expand Up @@ -184,6 +188,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_virtualgo $blue $grey --bold
set -x color_desk $blue $grey --bold
set -x color_nix $blue $grey --bold
set -x color_rustc $red $white --bold

case 'base16-light'
set -l base00 181818
Expand Down Expand Up @@ -236,6 +241,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_virtualgo $base0D $colorfg --bold
set -x color_desk $base0D $colorfg --bold
set -x color_nix $base0D $colorfg --bold
set -x color_rustc $base08 $colorfg --bold

case 'base16' 'base16-dark'
set -l base00 181818
Expand Down Expand Up @@ -288,6 +294,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_virtualgo $base0D $colorfg --bold
set -x color_desk $base0D $colorfg --bold
set -x color_nix $base0D $colorfg --bold
set -x color_rustc $base08 $colorfg --bold

case 'solarized-light'
set -l base03 002b36
Expand Down Expand Up @@ -340,6 +347,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_virtualgo $cyan $colorfg --bold
set -x color_desk $cyan $colorfg --bold
set -x color_nix $cyan $colorfg --bold
set -x color_rustc $red $colorfg --bold

case 'solarized' 'solarized-dark'
set -l base03 002b36
Expand Down Expand Up @@ -392,6 +400,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_virtualgo $cyan $colorfg --bold
set -x color_desk $cyan $colorfg --bold
set -x color_nix $cyan $colorfg --bold
set -x color_rustc $red $colorfg --bold

case 'light'
# light medium dark
Expand Down Expand Up @@ -437,6 +446,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_virtualgo $blue[2] $grey[1] --bold
set -x color_desk $blue[2] $grey[1] --bold
set -x color_nix $blue[2] $grey[1] --bold
set -x color_rustc $ruby_red $grey[1] --bold

case 'gruvbox'
# light medium dark darkest
Expand Down Expand Up @@ -481,6 +491,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_virtualgo $blue[2] $fg[2] --bold
set -x color_desk $blue[2] $fg[2] --bold
set -x color_nix $blue[2] $fg[2] --bold
set -x color_rustc $red[2] $fg[2] --bold

case 'dracula' # https://draculatheme.com
set -l bg 282a36
Expand Down Expand Up @@ -527,6 +538,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_virtualgo $cyan $bg --bold
set -x color_desk $comment $bg --bold
set -x color_nix $cyan $bg --bold
set -x color_rustc $red $bg --bold

case 'nord'
set -l base00 2E3440
Expand Down Expand Up @@ -624,6 +636,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_virtualgo $go_blue $black --bold
set -x color_desk $blue[2] $grey[1] --bold
set -x color_nix $blue[2] $grey[1] --bold
set -x color_rustc $ruby_red $white --bold
end
end

Expand Down Expand Up @@ -651,6 +664,7 @@ function __bobthefish_user_color_scheme_deprecated
set -q __color_virtualgo; or set -l __color_virtualgo 005faf cccccc --bold
set -q __color_desk; or set -l __color_desk 005faf cccccc --bold
set -q __color_nix; or set -l __color_nix 005faf cccccc --bold
set -q __color_rustc; or set -l __color_rustc af0000 cccccc --bold

set_color black -b red --bold
echo "The 'user' color scheme is deprecated."
Expand Down Expand Up @@ -691,6 +705,7 @@ function __bobthefish_user_color_scheme_deprecated
set -x color_virtualgo $__color_virtualgo
set -x color_desk $__color_desk
set -x color_nix $__color_nix
set -x color_rustc $__color_rustc
end"

echo
Expand Down
4 changes: 3 additions & 1 deletion functions/__bobthefish_glyphs.fish
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ function __bobthefish_glyphs -S -d 'Define glyphs used by bobthefish'
set -x pypy_glyph \u1D56

set -x ruby_glyph ''
set -x rustc_glyph ''
set -x go_glyph ''
set -x nix_glyph ''

# Desk glyphs
# Desk glyphs
set -x desk_glyph \u25F2

# Kubernetes glyphs
Expand Down Expand Up @@ -70,6 +71,7 @@ function __bobthefish_glyphs -S -d 'Define glyphs used by bobthefish'
set nix_glyph \uF313 ' ' # nf-linux-nixos
set virtualenv_glyph \uE73C ' '
set ruby_glyph \uE791 ' '
set rustc_glyph \uE7a8 ' ' # Rust Nerd Font logo
hansl marked this conversation as resolved.
Show resolved Hide resolved
set go_glyph \uE626 ' '
set node_glyph \uE718 ' '

Expand Down
4 changes: 4 additions & 0 deletions functions/bobthefish_display_colors.fish
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ function bobthefish_display_colors -a color_scheme -d 'Print example prompt colo
echo -ns $ruby_glyph rvm ' '
__bobthefish_finish_segments

__bobthefish_start_segment $color_rust
echo -ns $rust_glyph rust ' '
__bobthefish_finish_segments

__bobthefish_start_segment $color_virtualfish
echo -ns $virtualenv_glyph virtualfish ' '
__bobthefish_finish_segments
Expand Down
43 changes: 43 additions & 0 deletions functions/fish_prompt.fish
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
# set -g theme_display_virtualenv no
# set -g theme_display_nix no
# set -g theme_display_ruby no
# set -g theme_display_rustc no
# set -g theme_display_user ssh
# set -g theme_display_hostname ssh
# set -g theme_display_sudo_user yes
Expand Down Expand Up @@ -846,6 +847,47 @@ function __bobthefish_prompt_rubies -S -d 'Display current Ruby information'
echo -ns $ruby_glyph $ruby_version ' '
end

function __bobthefish_get_cargo_version -S -d 'Display the cargo version in a directory'
pushd $argv[1]
command rustc --version | cut -d ' ' -f 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does rustc take a working directory to save us from a pushd/popd? Otherwise, we should probably add command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately no. I'll add command but I'm also exploring if there's a better way to get this information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I decided to rely on fish -c " ... " to create a subshell only if we need to (which should be once for the global anyway).

popd
end

function __bobthefish_prompt_rustc -S -d 'Display current cargo version if different than system'
[ "$theme_display_rustc" = '' ]
and return

type -fq rustc
or return

# If this value is non-zero we should show it as a segment.
set -l local_rustc_version

switch "$theme_display_rustc"
case always
set local_rustc_version (__bobthefish_get_cargo_version (__bobthefish_pwd))
case yes
cargo locate-project --message-format plain --quiet >/dev/null 2>/dev/null
and set local_rustc_version (__bobthefish_get_cargo_version (__bobthefish_pwd))
case diff
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the default behavior for most segments (e.g. ruby). Can we make two options, always and yes, and have yes do what diff currently does?

(Alternatively, if it's not to expensive to default on, it would be off/always).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It takes 70msec to run rustc --version. I think it's too much to run with every prompt; if you had 2-3 of these it would be a third of a second and it's noticeable. But I'll defer the final decision to you.

I've done the first part.

if not set -q __bobthefish_global_cargo_version
set -g __bobthefish_global_cargo_version (__bobthefish_get_cargo_version /)
end

set local_rustc_version (__bobthefish_get_cargo_version (__bobthefish_pwd))
if [ "$local_rustc_version" = "$__bobthefish_global_cargo_version" ]
set local_rustc_version ''
end
end

[ -z "$local_rustc_version" ]
and return

__bobthefish_start_segment $color_rustc
echo -ns $rustc_glyph $local_rustc_version ' '
set_color normal
end

function __bobthefish_virtualenv_python_version -S -d 'Get current Python version'
switch (python --version 2>&1 | tr '\n' ' ')
case 'Python 2*PyPy*'
Expand Down Expand Up @@ -1170,6 +1212,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome'

# Virtual environments
__bobthefish_prompt_nix
__bobthefish_prompt_rustc
__bobthefish_prompt_desk
__bobthefish_prompt_rubies
__bobthefish_prompt_virtualfish
Expand Down