Skip to content

Commit c1cf2db

Browse files
committed
Add a rustc version segment with multiple install options
1 parent 1eaed8c commit c1cf2db

5 files changed

Lines changed: 67 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ set -g theme_display_hg yes
8585
set -g theme_display_virtualenv no
8686
set -g theme_display_nix no
8787
set -g theme_display_ruby no
88+
set -g theme_display_rustc no
8889
set -g theme_display_node yes
8990
set -g theme_display_user ssh
9091
set -g theme_display_hostname ssh
@@ -125,6 +126,7 @@ set -g theme_newline_prompt '$ '
125126

126127
- `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.
127128
- `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.
129+
- `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.
128130
- `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.
129131
- `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.
130132
- `theme_display_k8s_context`. This feature is disabled by default. Use `yes` to show the current kubernetes context (`> kubectl config current-context`).

functions/__bobthefish_colors.fish

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
3838
set -x color_virtualgo brblue $colorfg --bold
3939
set -x color_desk brblue $colorfg --bold
4040
set -x color_nix brblue $colorfg --bold
41+
set -x color_rustc brred $colorfg --bold
4142

4243
case 'terminal-light*'
4344
set -l colorfg white
@@ -73,6 +74,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
7374
set -x color_virtualgo brblue $colorfg --bold
7475
set -x color_desk brblue $colorfg --bold
7576
set -x color_nix brblue $colorfg --bold
77+
set -x color_rustc brred $colorfg --bold
7678

7779
case 'terminal2' 'terminal2-dark*'
7880
set -l colorfg black
@@ -108,6 +110,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
108110
set -x color_virtualgo brblue $colorfg --bold
109111
set -x color_desk brblue $colorfg --bold
110112
set -x color_nix brblue $colorfg --bold
113+
set -x color_rustc brred $colorfg --bold
111114

112115
case 'terminal2-light*'
113116
set -l colorfg white
@@ -143,6 +146,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
143146
set -x color_virtualgo brblue $colorfg --bold
144147
set -x color_desk brblue $colorfg --bold
145148
set -x color_nix brblue $colorfg --bold
149+
set -x color_rustc brred $colorfg --bold
146150

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

188193
case 'base16-light'
189194
set -l base00 181818
@@ -236,6 +241,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
236241
set -x color_virtualgo $base0D $colorfg --bold
237242
set -x color_desk $base0D $colorfg --bold
238243
set -x color_nix $base0D $colorfg --bold
244+
set -x color_rustc $base08 $colorfg --bold
239245

240246
case 'base16' 'base16-dark'
241247
set -l base00 181818
@@ -288,6 +294,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
288294
set -x color_virtualgo $base0D $colorfg --bold
289295
set -x color_desk $base0D $colorfg --bold
290296
set -x color_nix $base0D $colorfg --bold
297+
set -x color_rustc $base08 $colorfg --bold
291298

292299
case 'solarized-light'
293300
set -l base03 002b36
@@ -340,6 +347,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
340347
set -x color_virtualgo $cyan $colorfg --bold
341348
set -x color_desk $cyan $colorfg --bold
342349
set -x color_nix $cyan $colorfg --bold
350+
set -x color_rustc $red $colorfg --bold
343351

344352
case 'solarized' 'solarized-dark'
345353
set -l base03 002b36
@@ -392,6 +400,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
392400
set -x color_virtualgo $cyan $colorfg --bold
393401
set -x color_desk $cyan $colorfg --bold
394402
set -x color_nix $cyan $colorfg --bold
403+
set -x color_rustc $red $colorfg --bold
395404

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

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

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

531543
case 'nord'
532544
set -l base00 2E3440
@@ -624,6 +636,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
624636
set -x color_virtualgo $go_blue $black --bold
625637
set -x color_desk $blue[2] $grey[1] --bold
626638
set -x color_nix $blue[2] $grey[1] --bold
639+
set -x color_rustc $ruby_red $white --bold
627640
end
628641
end
629642

@@ -651,6 +664,7 @@ function __bobthefish_user_color_scheme_deprecated
651664
set -q __color_virtualgo; or set -l __color_virtualgo 005faf cccccc --bold
652665
set -q __color_desk; or set -l __color_desk 005faf cccccc --bold
653666
set -q __color_nix; or set -l __color_nix 005faf cccccc --bold
667+
set -q __color_rustc; or set -l __color_rustc af0000 cccccc --bold
654668

655669
set_color black -b red --bold
656670
echo "The 'user' color scheme is deprecated."
@@ -691,6 +705,7 @@ function __bobthefish_user_color_scheme_deprecated
691705
set -x color_virtualgo $__color_virtualgo
692706
set -x color_desk $__color_desk
693707
set -x color_nix $__color_nix
708+
set -x color_rustc $__color_rustc
694709
end"
695710

696711
echo

functions/__bobthefish_glyphs.fish

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ function __bobthefish_glyphs -S -d 'Define glyphs used by bobthefish'
2121
set -x pypy_glyph \u1D56
2222

2323
set -x ruby_glyph ''
24+
set -x rustc_glyph ''
2425
set -x go_glyph ''
2526
set -x nix_glyph ''
2627

27-
# Desk glyphs
28+
# Desk glyphs
2829
set -x desk_glyph \u25F2
2930

3031
# Kubernetes glyphs
@@ -70,6 +71,7 @@ function __bobthefish_glyphs -S -d 'Define glyphs used by bobthefish'
7071
set nix_glyph \uF313 ' ' # nf-linux-nixos
7172
set virtualenv_glyph \uE73C ' '
7273
set ruby_glyph \uE791 ' '
74+
set rustc_glyph \uE7a8 ' ' # Rust Nerd Font logo
7375
set go_glyph \uE626 ' '
7476
set node_glyph \uE718 ' '
7577

functions/bobthefish_display_colors.fish

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ function bobthefish_display_colors -a color_scheme -d 'Print example prompt colo
129129
echo -ns $ruby_glyph rvm ' '
130130
__bobthefish_finish_segments
131131

132+
__bobthefish_start_segment $color_rust
133+
echo -ns $rust_glyph rust ' '
134+
__bobthefish_finish_segments
135+
132136
__bobthefish_start_segment $color_virtualfish
133137
echo -ns $virtualenv_glyph virtualfish ' '
134138
__bobthefish_finish_segments

functions/fish_prompt.fish

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
# set -g theme_display_virtualenv no
3636
# set -g theme_display_nix no
3737
# set -g theme_display_ruby no
38+
# set -g theme_display_rustc no
3839
# set -g theme_display_user ssh
3940
# set -g theme_display_hostname ssh
4041
# set -g theme_display_sudo_user yes
@@ -846,6 +847,47 @@ function __bobthefish_prompt_rubies -S -d 'Display current Ruby information'
846847
echo -ns $ruby_glyph $ruby_version ' '
847848
end
848849

850+
function __bobthefish_get_cargo_version -S -d 'Display the cargo version in a directory'
851+
pushd $argv[1]
852+
command rustc --version | cut -d ' ' -f 2
853+
popd
854+
end
855+
856+
function __bobthefish_prompt_rustc -S -d 'Display current cargo version if different than system'
857+
[ "$theme_display_rustc" = '' ]
858+
and return
859+
860+
type -fq rustc
861+
or return
862+
863+
# If this value is non-zero we should show it as a segment.
864+
set -l local_rustc_version
865+
866+
switch "$theme_display_rustc"
867+
case always
868+
set local_rustc_version (__bobthefish_get_cargo_version (__bobthefish_pwd))
869+
case yes
870+
cargo locate-project --message-format plain --quiet >/dev/null 2>/dev/null
871+
and set local_rustc_version (__bobthefish_get_cargo_version (__bobthefish_pwd))
872+
case diff
873+
if not set -q __bobthefish_global_cargo_version
874+
set -g __bobthefish_global_cargo_version (__bobthefish_get_cargo_version /)
875+
end
876+
877+
set local_rustc_version (__bobthefish_get_cargo_version (__bobthefish_pwd))
878+
if [ "$local_rustc_version" = "$__bobthefish_global_cargo_version" ]
879+
set local_rustc_version ''
880+
end
881+
end
882+
883+
[ -z "$local_rustc_version" ]
884+
and return
885+
886+
__bobthefish_start_segment $color_rustc
887+
echo -ns $rustc_glyph $local_rustc_version ' '
888+
set_color normal
889+
end
890+
849891
function __bobthefish_virtualenv_python_version -S -d 'Get current Python version'
850892
switch (python --version 2>&1 | tr '\n' ' ')
851893
case 'Python 2*PyPy*'
@@ -1170,6 +1212,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome'
11701212

11711213
# Virtual environments
11721214
__bobthefish_prompt_nix
1215+
__bobthefish_prompt_rustc
11731216
__bobthefish_prompt_desk
11741217
__bobthefish_prompt_rubies
11751218
__bobthefish_prompt_virtualfish

0 commit comments

Comments
 (0)