From 4a47e212f8662e2dd2605ef3b8942f6bae8b1b3b Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 30 Dec 2019 14:03:36 +0100 Subject: [PATCH] Color the default prompt host if running via SSH This is part of our (well, my) quest to spice up the default prompt. In this case we color the host if $SSH_TTY is set, which is easy to detect and helps draw attention to the host. See #6398. See #6375. --- share/functions/__fish_config_interactive.fish | 1 + share/functions/fish_prompt.fish | 8 +++++++- share/tools/web_config/sample_prompts/classic_vcs.fish | 10 ++++++++-- sphinx_doc_src/index.rst | 2 ++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/share/functions/__fish_config_interactive.fish b/share/functions/__fish_config_interactive.fish index 15adeac68..70d1ecd64 100644 --- a/share/functions/__fish_config_interactive.fish +++ b/share/functions/__fish_config_interactive.fish @@ -58,6 +58,7 @@ function __fish_config_interactive -d "Initializations that should be performed __init_uvar fish_color_autosuggestion 555 brblack __init_uvar fish_color_user brgreen __init_uvar fish_color_host normal + __init_uvar fish_color_host_remote yellow __init_uvar fish_color_valid_path --underline __init_uvar fish_color_status red diff --git a/share/functions/fish_prompt.fish b/share/functions/fish_prompt.fish index 71a668643..1297008c2 100644 --- a/share/functions/fish_prompt.fish +++ b/share/functions/fish_prompt.fish @@ -16,8 +16,14 @@ function fish_prompt --description 'Write out the prompt' set suffix '#' end + # If we're running via SSH, change the host color. + set -l color_host $fish_color_host + if set -q SSH_TTY + set color_host $fish_color_host_remote + end + # Write pipestatus set -l prompt_status (__fish_print_pipestatus " [" "]" "|" (set_color $fish_color_status) (set_color --bold $fish_color_status) $last_pipestatus) - echo -n -s (set_color $fish_color_user) "$USER" $normal @ (set_color $fish_color_host) (prompt_hostname) $normal ' ' (set_color $color_cwd) (prompt_pwd) $normal (fish_vcs_prompt) $normal $prompt_status $suffix " " + echo -n -s (set_color $fish_color_user) "$USER" $normal @ (set_color $color_host) (prompt_hostname) $normal ' ' (set_color $color_cwd) (prompt_pwd) $normal (fish_vcs_prompt) $normal $prompt_status $suffix " " end diff --git a/share/tools/web_config/sample_prompts/classic_vcs.fish b/share/tools/web_config/sample_prompts/classic_vcs.fish index 7203b7320..bb8a98d06 100644 --- a/share/tools/web_config/sample_prompts/classic_vcs.fish +++ b/share/tools/web_config/sample_prompts/classic_vcs.fish @@ -1,4 +1,4 @@ -# name: Classic + Vcs +# name: Classic + Vcs (the default) # author: Lily Ballard function fish_prompt --description 'Write out the prompt' @@ -17,8 +17,14 @@ function fish_prompt --description 'Write out the prompt' set suffix '#' end + # If we're running via SSH, change the host color. + set -l color_host $fish_color_host + if set -q SSH_TTY + set color_host $fish_color_host_remote + end + # Write pipestatus set -l prompt_status (__fish_print_pipestatus " [" "]" "|" (set_color $fish_color_status) (set_color --bold $fish_color_status) $last_pipestatus) - echo -n -s (set_color $fish_color_user) "$USER" $normal @ (set_color $fish_color_host) (prompt_hostname) $normal ' ' (set_color $color_cwd) (prompt_pwd) $normal (fish_vcs_prompt) $normal $prompt_status $suffix " " + echo -n -s (set_color $fish_color_user) "$USER" $normal @ (set_color $color_host) (prompt_hostname) $normal ' ' (set_color $color_cwd) (prompt_pwd) $normal (fish_vcs_prompt) $normal $prompt_status $suffix " " end diff --git a/sphinx_doc_src/index.rst b/sphinx_doc_src/index.rst index d856384ac..04c5d1f4d 100644 --- a/sphinx_doc_src/index.rst +++ b/sphinx_doc_src/index.rst @@ -1096,6 +1096,8 @@ The following variables are available to change the highlighting colors in fish: - ``fish_color_host``, the color used to print the current host system in some of fish default prompts +- ``fish_color_host_remote``, the color used to print the current host system in some of fish default prompts, if fish is running remotely (via ssh or similar) + - ``fish_color_cancel``, the color for the '^C' indicator on a canceled command Additionally, the following variables are available to change the highlighting in the completion pager: