From e14f4b7c056d94c5636c2adac6b85d04184c502c Mon Sep 17 00:00:00 2001 From: ben Date: Sat, 7 Jan 2017 23:15:48 +1100 Subject: [PATCH 1/2] Add support for choosing to show user and/or hostname in prompt --- README.md | 1 + fish_prompt.fish | 32 +++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a28e0cd..e67cc65 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ set -g theme_display_hg yes set -g theme_display_virtualenv no set -g theme_display_ruby no set -g theme_display_user yes +set -g theme_display_hostname yes set -g theme_display_vi no set -g theme_display_date no set -g theme_display_cmd_duration yes diff --git a/fish_prompt.fish b/fish_prompt.fish index 2bc077f..5af7c5a 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -27,6 +27,7 @@ # set -g theme_display_virtualenv no # set -g theme_display_ruby no # set -g theme_display_user yes +# set -g theme_display_hostname yes # set -g theme_display_vi no # set -g theme_avoid_ambiguous_glyphs yes # set -g theme_powerline_fonts no @@ -436,11 +437,18 @@ function __bobthefish_prompt_user -S -d 'Display actual user if different from $ if [ "$theme_display_user" = 'yes' ] if [ "$USER" != "$default_user" -o -n "$SSH_CLIENT" ] __bobthefish_start_segment $__color_username - set -l IFS . - hostname | read -l hostname __ - echo -ns (whoami) '@' $hostname ' ' + echo -ns (whoami) end end + + if [ "$theme_display_hostname" = 'yes' ] + __bobthefish_start_segment $__color_hostname + set -l IFS . + hostname | read -l hostname __ + if [ "$theme_display_user" = 'yes' ] + echo -ns '@' $hostname + end + echo -ns ' ' end function __bobthefish_prompt_hg -S -a current_dir -d 'Display the actual hg state' @@ -802,6 +810,11 @@ function __bobthefish_maybe_display_colors -S __bobthefish_finish_segments echo + __bobthefish_start_segment $__color_hostname + echo -n color_hostname ' ' + __bobthefish_finish_segments + echo + __bobthefish_start_segment $__color_rvm echo -n color_rvm ' ' __bobthefish_finish_segments @@ -931,6 +944,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' # # set -g __color_vagrant 48b4fb ffffff --bold # set -g __color_username cccccc 255e87 + # set -g __color_hostname cccccc 255e87 # set -g __color_rvm af0000 cccccc --bold # set -g __color_virtualfish 005faf cccccc --bold @@ -957,6 +971,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' set __color_vagrant brcyan $colorfg set __color_username white black + set __color_hostname white black set __color_rvm brmagenta $colorfg --bold set __color_virtualfish brblue $colorfg --bold @@ -983,6 +998,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' set __color_vagrant brcyan $colorfg set __color_username black white + set __color_hostname black white set __color_rvm brmagenta $colorfg --bold set __color_virtualfish brblue $colorfg --bold @@ -1009,6 +1025,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' set __color_vagrant brcyan $colorfg set __color_username brgrey white + set __color_hostname brgrey white set __color_rvm brmagenta $colorfg --bold set __color_virtualfish brblue $colorfg --bold @@ -1035,6 +1052,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' set __color_vagrant brcyan $colorfg set __color_username grey black + set __color_hostname grey black set __color_rvm brmagenta $colorfg --bold set __color_virtualfish brblue $colorfg --bold @@ -1067,6 +1085,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' set __color_vagrant $blue $green --bold set __color_username $grey $blue + set __color_hostname $grey $blue set __color_rvm $red $grey --bold set __color_virtualfish $blue $grey --bold @@ -1110,6 +1129,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' set __color_vagrant $base0C $colorfg --bold set __color_username $base02 $base0D + set __color_hostname $base02 $base0D set __color_rvm $base08 $colorfg --bold set __color_virtualfish $base0D $colorfg --bold @@ -1153,6 +1173,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' set __color_vagrant $base0C $colorfg --bold set __color_username $base02 $base0D + set __color_hostname $base02 $base0D set __color_rvm $base08 $colorfg --bold set __color_virtualfish $base0D $colorfg --bold @@ -1196,6 +1217,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' set __color_vagrant $violet $colorfg --bold set __color_username $base2 $blue + set __color_hostname $base2 $blue set __color_rvm $red $colorfg --bold set __color_virtualfish $cyan $colorfg --bold @@ -1239,6 +1261,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' set __color_vagrant $violet $colorfg --bold set __color_username $base02 $blue + set __color_hostname $base02 $blue set __color_rvm $red $colorfg --bold set __color_virtualfish $cyan $colorfg --bold @@ -1275,6 +1298,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' set __color_vagrant $blue[1] $white --bold set __color_username $grey[1] $blue[3] + set __color_hostname $grey[1] $blue[3] set __color_rvm $ruby_red $grey[1] --bold set __color_virtualfish $blue[2] $grey[1] --bold @@ -1310,6 +1334,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' set -g __color_vagrant $blue[2] $fg[2] --bold set -g __color_username $fg[3] $blue[2] + set -g __color_hostname $fg[3] $blue[2] set -g __color_rvm $red[2] $fg[2] --bold set -g __color_virtualfish $blue[2] $fg[2] --bold @@ -1346,6 +1371,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' set __color_vagrant $blue[1] $white --bold set __color_username $grey[1] $blue[3] + set __color_hostname $grey[1] $blue[3] set __color_rvm $ruby_red $grey[1] --bold set __color_virtualfish $blue[2] $grey[1] --bold end From d710b2b41cc2181603c3f578795d4e9ea8fbccff Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 13 Jan 2017 06:46:30 +1100 Subject: [PATCH 2/2] Resolved formatting error Fixed prompt segments that were out of place --- fish_prompt.fish | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fish_prompt.fish b/fish_prompt.fish index 5af7c5a..dd482e6 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -442,13 +442,19 @@ function __bobthefish_prompt_user -S -d 'Display actual user if different from $ end if [ "$theme_display_hostname" = 'yes' ] - __bobthefish_start_segment $__color_hostname set -l IFS . hostname | read -l hostname __ if [ "$theme_display_user" = 'yes' ] echo -ns '@' $hostname + else + __bobthefish_start_segment $__color_hostname + echo -ns $hostname + end + end + + if [ "$theme_display_user" = 'yes' -o "$theme_display_hostname" = 'yes' ] + echo -ns ' ' end - echo -ns ' ' end function __bobthefish_prompt_hg -S -a current_dir -d 'Display the actual hg state'