From 51f843716b313e7586e052d235b57b0ce80d7d36 Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Fri, 6 Mar 2020 12:42:40 -0800 Subject: [PATCH] Prompt: Hide host if not on ssh Updates for fish/zsh/bash --- assets/default/dotfiles/bash_profile | 9 ++- assets/default/dotfiles/zshrc | 9 ++- .../default/fish/functions/fish_prompt.fish | 60 ++++++++++--------- 3 files changed, 49 insertions(+), 29 deletions(-) diff --git a/assets/default/dotfiles/bash_profile b/assets/default/dotfiles/bash_profile index 9063eca..da55343 100644 --- a/assets/default/dotfiles/bash_profile +++ b/assets/default/dotfiles/bash_profile @@ -45,7 +45,14 @@ function ps_force_target { } function ps_host_name { - [ -z "$TMUX" ] || return && echo '\h ' + # Returns hostname if on remote host and not using tmux + # Check if we're on a non-local host via ssh + if [ -n "$SSH_CLIENT" ] && [ -n "$SSH_TTY" ]; then + # Check if we're using tmux, since tmux status line displays the host + if [ -z "$TMUX" ]; then + echo '\h ' + fi + fi } function ps_virtual_env { diff --git a/assets/default/dotfiles/zshrc b/assets/default/dotfiles/zshrc index 168125e..0201619 100644 --- a/assets/default/dotfiles/zshrc +++ b/assets/default/dotfiles/zshrc @@ -83,7 +83,14 @@ fi # Set prompt to include some useful information function ps_host_name { - [ -z "$TMUX" ] || return && echo "$(hostname) " + # Returns hostname if on remote host and not using tmux + # Check if we're on a non-local host via ssh + if [ -n "$SSH_CLIENT" ] && [ -n "$SSH_TTY" ]; then + # Check if we're using tmux, since tmux status line displays the host + if [ -z "$TMUX" ]; then + echo "$(hostname) " + fi + fi } function ps_git_branch { diff --git a/assets/default/fish/functions/fish_prompt.fish b/assets/default/fish/functions/fish_prompt.fish index fafd490..d0f730f 100644 --- a/assets/default/fish/functions/fish_prompt.fish +++ b/assets/default/fish/functions/fish_prompt.fish @@ -1,42 +1,48 @@ # name: ifij (forked from RobbyRussel) +# description: prompt containing minimal relevant information with host, path, +# and git status. function _status_color - # Returns a color for successful or failed previous command - if test $__prompt_last_status -eq 0 - echo (set_color -o green) - else - echo (set_color -o red) - end + # Returns a color for successful or failed previous command + if test $__prompt_last_status -eq 0 + echo (set_color -o green) + else + echo (set_color -o red) + end end function _hostname - # Returns the hostname if not using tmux since tmux will display - if [ -z $TMUX ] - echo (hostname -s)" " - end + # Returns hostname if on remote host and not using tmux + # Check if we're on a non-local host via ssh + if set -q SSH_CLIENT; or set -q SSH_TTY + # Check if we're using tmux, since tmux status line displays the host + if not set -q TMUX + echo (hostname -s)" " + end + end end function _prompt_char - # Gives a colored prompt char for user or root - echo -n (_status_color) - if [ (whoami) = 'root' ] - echo -n '#' - else - echo -n '$' - end - echo -n (set_color normal) + # Gives a colored prompt char for user or root + echo -n (_status_color) + if [ (whoami) = 'root' ] + echo -n '#' + else + echo -n '$' + end + echo -n (set_color normal) end function fish_prompt - # Build full left side prompt + # Build full left side prompt - # Collect last status for coloring prompt - set -g __prompt_last_status $status + # Collect last status for coloring prompt + set -g __prompt_last_status $status - # Configure git prompt - set -g __fish_git_prompt_showcolorhints 1 - set -g __fish_git_prompt_showdirtystate 1 - set -g __fish_git_prompt_showstashstate 1 - set -g __fish_git_prompt_showuntrackedfiles 1 - echo -n -s $arrow (_hostname) (prompt_pwd) (__fish_git_prompt) (_prompt_char) ' ' + # Configure git prompt + set -g __fish_git_prompt_showcolorhints 1 + set -g __fish_git_prompt_showdirtystate 1 + set -g __fish_git_prompt_showstashstate 1 + set -g __fish_git_prompt_showuntrackedfiles 1 + echo -n -s $arrow (_hostname) (prompt_pwd) (__fish_git_prompt) (_prompt_char) ' ' end