From 8cc85ff3ffe5ebd1260ed276fc2b35621ccfba55 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 27 Jan 2017 13:03:09 +1300 Subject: Extend "fallback" prompt a bit Include username/hostname if no SSH variables --- bash/bashrc.d/prompt.bash | 5 ++++- ksh/kshrc.d/prompt.ksh | 5 ++++- sh/shrc.d/prompt.sh | 6 ++++++ zsh/zshrc.d/prompt.zsh | 5 ++++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index 2bd70c2f..f64355f7 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -81,10 +81,13 @@ prompt() { # Revert to simple inexpensive prompts off) unset -v PROMPT_COMMAND PROMPT_DIRTRIM - PS1='\$ ' + PS1='$ ' PS2='> ' PS3='? ' PS4='+ ' + if [[ -n $SSH_CLIENT || -n $SSH_CONNECTION ]] ; then + PS1=$(id -nu)'@'$(hostname -s)'$ ' + fi ;; # Git prompt function diff --git a/ksh/kshrc.d/prompt.ksh b/ksh/kshrc.d/prompt.ksh index 1dcbd864..3f526526 100644 --- a/ksh/kshrc.d/prompt.ksh +++ b/ksh/kshrc.d/prompt.ksh @@ -188,10 +188,13 @@ function prompt { # Revert to simple inexpensive prompts off) - PS1='\$ ' + PS1='$ ' PS2='> ' PS3='? ' PS4='+ ' + if [[ -n $SSH_CLIENT || -n $SSH_CONNECTION ]] ; then + PS1=$(id -nu)'@'$(hostname -s)'$ ' + fi ;; # Abbreviated working directory diff --git a/sh/shrc.d/prompt.sh b/sh/shrc.d/prompt.sh index a481b5bb..f1b67fb4 100644 --- a/sh/shrc.d/prompt.sh +++ b/sh/shrc.d/prompt.sh @@ -3,3 +3,9 @@ # it to break the export and then just setting them as simple variables unset PS1 PS2 PS3 PS4 PS1='$ ' PS2='> ' PS3='? ' PS4='+ ' + +# If we have an SSH_CLIENT or SSH_CONNECTION environment variable, put the +# username and hostname in PS1 too. +if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_CONNECTION" ] ; then + PS1=$(id -nu)'@'$(hostname)'$ ' +fi diff --git a/zsh/zshrc.d/prompt.zsh b/zsh/zshrc.d/prompt.zsh index f374dbec..446e336e 100644 --- a/zsh/zshrc.d/prompt.zsh +++ b/zsh/zshrc.d/prompt.zsh @@ -44,10 +44,13 @@ prompt() { # Revert to simple inexpensive prompts off) - PS1='\$ ' + PS1='$ ' PS2='> ' PS3='? ' PS4='+ ' + if [[ -n $SSH_CLIENT || -n $SSH_CONNECTION ]] ; then + PS1=$(id -nu)'@'$(hostname -s)'$ ' + fi ;; # Git prompt function -- cgit v1.2.3