From 81c4ed70ea1d36a2f8677865bd6f73041d11c032 Mon Sep 17 00:00:00 2001 From: BarbUk Date: Tue, 31 Mar 2020 12:15:28 +0400 Subject: [PATCH 1/9] Add user@host information for ssh session --- themes/barbuk/barbuk.theme.bash | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/themes/barbuk/barbuk.theme.bash b/themes/barbuk/barbuk.theme.bash index 39d4995e..372b8a0d 100644 --- a/themes/barbuk/barbuk.theme.bash +++ b/themes/barbuk/barbuk.theme.bash @@ -31,7 +31,7 @@ SCM_THEME_CURRENT_USER_PREFFIX='  ' SCM_GIT_SHOW_CURRENT_USER=false function _git-uptream-remote-logo { - [[ "$(_git-upstream)" == "" ]] && return + [[ "$(_git-upstream)" == "" ]] && SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT" local remote remote_domain remote=$(_git-upstream-remote) @@ -62,7 +62,7 @@ function _exit-code { } function _prompt { - local exit_code="$?" wrap_char=' ' dir_color=$green + local exit_code="$?" wrap_char=' ' dir_color=$green ssh_info='' _exit-code exit_code _git-uptream-remote-logo @@ -74,7 +74,12 @@ function _prompt { dir_color=$red fi - PS1="\\n ${purple}$(scm_char)${dir_color}\\w${normal}$(scm_prompt_info)${exit_code}" + # Detect ssh + if [[ -n "${SSH_CLIENT}" ]] || [[ -n "${SSH_CONNECTION}" ]]; then + ssh_info="${bold_blue}\u${bold_orange}@${cyan}\H ${bold_orange}in" + fi + + PS1="\\n${ssh_info} ${purple}$(scm_char)${dir_color}\\w${normal}$(scm_prompt_info)${exit_code}" [[ ${#PS1} -gt $((COLUMNS*3)) ]] && wrap_char="\\n" PS1="${PS1}${wrap_char}❯${normal} " From 337ed0de9aea4eb4c5bc07a2194bcebc06f537de Mon Sep 17 00:00:00 2001 From: BarbUk Date: Tue, 31 Mar 2020 12:16:06 +0400 Subject: [PATCH 2/9] Documentation for ssh and sudoer configuration --- themes/barbuk/README.md | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/themes/barbuk/README.md b/themes/barbuk/README.md index cc188190..372560e4 100644 --- a/themes/barbuk/README.md +++ b/themes/barbuk/README.md @@ -8,6 +8,7 @@ A minimal theme with a clean git prompt * Current path (red when user is root) * Current git info * Last command exit code (only shown when the exit code is greater than 0) +* user@host for ssh connection ## Fonts and glyphs @@ -37,6 +38,26 @@ SCM_GIT_CHAR_GITHUB='•' source "$BASH_IT"/bash_it.sh ``` +## SSH prompt and sudoers + +If you want the theme to persist using `sudo -s` in a ssh session, you need to configure sudo to keep the `HOME` and `SSH_CONNECTION` environment variables. + +`HOME` contains the path to the home directory of the current user. Keeping it will allow to use your user dotfiles when elevating privileges. + +Keeping `SSH_CONNECTION` env is necessary for ssh detection in the theme. + +Please refer to the following documentation for more information: + - [sudo manual](https://www.sudo.ws/man/1.8.13/sudoers.man.html) for `env_keep` configuration + - [openssh manual](https://linux.die.net/man/1/ssh) for information about `SSH_CONNECTION` environment + +```bash +cat << EOF > /etc/sudoers.d/keepenv +Defaults env_keep += HOME +Defaults env_keep += SSH_CONNECTION +EOF +chmod 400 /etc/sudoers.d/keepenv +``` + ## Examples ### Clean @@ -49,5 +70,10 @@ source "$BASH_IT"/bash_it.sh ```bash  ~/.dotfiles on  master ⤏ origin ↑2 •7 ✗ ❯ - ``` +``` +### Ssh + +```bash +user@fqdn in  ~/bash-it on  master ✓ ❯ +``` From d39eb053cfd40fa6c5a6aad9c8eb5208e922496b Mon Sep 17 00:00:00 2001 From: BarbUk Date: Wed, 1 Apr 2020 00:46:58 +0400 Subject: [PATCH 3/9] Allow to disable ssh info --- themes/barbuk/barbuk.theme.bash | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/themes/barbuk/barbuk.theme.bash b/themes/barbuk/barbuk.theme.bash index 372b8a0d..ead0940a 100644 --- a/themes/barbuk/barbuk.theme.bash +++ b/themes/barbuk/barbuk.theme.bash @@ -9,6 +9,9 @@ SCM_GIT_CHAR_DEFAULT=${SCM_GIT_CHAR_DEFAULT:=' '} SCM_GIT_CHAR_ICON_BRANCH=${SCM_GIT_CHAR_ICON_BRANCH:=''} EXIT_CODE_ICON=${EXIT_CODE_ICON:=' '} +# Ssh user and fqdn display +SSH_INFO=${BARBUK_SSH_INFO:=true} + # Bash-it default glyphs customization SCM_HG_CHAR='☿ ' SCM_SVN_CHAR='⑆ ' @@ -75,7 +78,7 @@ function _prompt { fi # Detect ssh - if [[ -n "${SSH_CLIENT}" ]] || [[ -n "${SSH_CONNECTION}" ]]; then + if [[ -n "${SSH_CONNECTION}" ]] && [ "$SSH_INFO" = true ]; then ssh_info="${bold_blue}\u${bold_orange}@${cyan}\H ${bold_orange}in" fi From 6d0744a9288ed8b29d6fbf2e4886cbe2ec1f7180 Mon Sep 17 00:00:00 2001 From: BarbUk Date: Wed, 1 Apr 2020 00:48:11 +0400 Subject: [PATCH 4/9] Update documentation --- themes/barbuk/README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/themes/barbuk/README.md b/themes/barbuk/README.md index 372560e4..736fd0ba 100644 --- a/themes/barbuk/README.md +++ b/themes/barbuk/README.md @@ -38,7 +38,19 @@ SCM_GIT_CHAR_GITHUB='•' source "$BASH_IT"/bash_it.sh ``` -## SSH prompt and sudoers +## SSH prompt + +### Usage + +When using a ssh session, the theme will display `user@fqdn`. +You can disable this information before sourcing bsah-it: + +```bash +export BARBUK_SSH_INFO=false +source "$BASH_IT"/bash_it.sh +``` + +### Keep theme with sudoer If you want the theme to persist using `sudo -s` in a ssh session, you need to configure sudo to keep the `HOME` and `SSH_CONNECTION` environment variables. From 347995d33e172faea431fc9fa72e40bf5e5f3b88 Mon Sep 17 00:00:00 2001 From: BarbUk Date: Wed, 1 Apr 2020 01:02:01 +0400 Subject: [PATCH 5/9] Allow to customize hostname format --- themes/barbuk/barbuk.theme.bash | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/themes/barbuk/barbuk.theme.bash b/themes/barbuk/barbuk.theme.bash index ead0940a..2cba4df7 100644 --- a/themes/barbuk/barbuk.theme.bash +++ b/themes/barbuk/barbuk.theme.bash @@ -11,6 +11,7 @@ EXIT_CODE_ICON=${EXIT_CODE_ICON:=' '} # Ssh user and fqdn display SSH_INFO=${BARBUK_SSH_INFO:=true} +HOST_INFO=${BARBUK_HOST_INFO:=long} # Bash-it default glyphs customization SCM_HG_CHAR='☿ ' @@ -65,7 +66,7 @@ function _exit-code { } function _prompt { - local exit_code="$?" wrap_char=' ' dir_color=$green ssh_info='' + local exit_code="$?" wrap_char=' ' dir_color=$green ssh_info='' host _exit-code exit_code _git-uptream-remote-logo @@ -79,7 +80,12 @@ function _prompt { # Detect ssh if [[ -n "${SSH_CONNECTION}" ]] && [ "$SSH_INFO" = true ]; then - ssh_info="${bold_blue}\u${bold_orange}@${cyan}\H ${bold_orange}in" + if [ "$HOST_INFO" = long ]; then + host="\H" + else + host="\h" + fi + ssh_info="${bold_blue}\u${bold_orange}@${cyan}$host ${bold_orange}in" fi PS1="\\n${ssh_info} ${purple}$(scm_char)${dir_color}\\w${normal}$(scm_prompt_info)${exit_code}" From 78db4d56f082b9dc9458db915e66904affe3b272 Mon Sep 17 00:00:00 2001 From: BarbUk Date: Wed, 1 Apr 2020 01:02:24 +0400 Subject: [PATCH 6/9] Update documentation to explain new BARBUK_HOST_INFO configuration --- themes/barbuk/README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/themes/barbuk/README.md b/themes/barbuk/README.md index 736fd0ba..06cce8de 100644 --- a/themes/barbuk/README.md +++ b/themes/barbuk/README.md @@ -42,10 +42,16 @@ source "$BASH_IT"/bash_it.sh ### Usage -When using a ssh session, the theme will display `user@fqdn`. -You can disable this information before sourcing bsah-it: +When using a ssh session, the theme will display `user@hostname`. +You can disable this information with `BARBUK_SSH_INFO`. + +The hostname is display in the FQDN format by default. You +can use the short hostname format with `BARBUK_HOST_INFO`. ```bash +# short or long +export BARBUK_HOST_INFO=short +# true or false export BARBUK_SSH_INFO=false source "$BASH_IT"/bash_it.sh ``` @@ -87,5 +93,5 @@ chmod 400 /etc/sudoers.d/keepenv ### Ssh ```bash -user@fqdn in  ~/bash-it on  master ✓ ❯ +user@hostname in  ~/bash-it on  master ✓ ❯ ``` From d6d4e4bc7d9f0ea0adf0675510e582593f097f56 Mon Sep 17 00:00:00 2001 From: BarbUk Date: Wed, 1 Apr 2020 01:05:15 +0400 Subject: [PATCH 7/9] Fix typo --- themes/barbuk/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/barbuk/README.md b/themes/barbuk/README.md index 06cce8de..c3101734 100644 --- a/themes/barbuk/README.md +++ b/themes/barbuk/README.md @@ -45,7 +45,7 @@ source "$BASH_IT"/bash_it.sh When using a ssh session, the theme will display `user@hostname`. You can disable this information with `BARBUK_SSH_INFO`. -The hostname is display in the FQDN format by default. You +The hostname is displayed in the FQDN format by default. You can use the short hostname format with `BARBUK_HOST_INFO`. ```bash From 0896ff2fb3d245ff39eb7fb91917e26e6c9a3768 Mon Sep 17 00:00:00 2001 From: BarbUk Date: Wed, 1 Apr 2020 01:06:33 +0400 Subject: [PATCH 8/9] Use same notation for user@hostname --- themes/barbuk/README.md | 2 +- themes/barbuk/barbuk.theme.bash | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/barbuk/README.md b/themes/barbuk/README.md index c3101734..dad6e140 100644 --- a/themes/barbuk/README.md +++ b/themes/barbuk/README.md @@ -8,7 +8,7 @@ A minimal theme with a clean git prompt * Current path (red when user is root) * Current git info * Last command exit code (only shown when the exit code is greater than 0) -* user@host for ssh connection +* user@hostname for ssh connection ## Fonts and glyphs diff --git a/themes/barbuk/barbuk.theme.bash b/themes/barbuk/barbuk.theme.bash index 2cba4df7..7990ca91 100644 --- a/themes/barbuk/barbuk.theme.bash +++ b/themes/barbuk/barbuk.theme.bash @@ -9,7 +9,7 @@ SCM_GIT_CHAR_DEFAULT=${SCM_GIT_CHAR_DEFAULT:=' '} SCM_GIT_CHAR_ICON_BRANCH=${SCM_GIT_CHAR_ICON_BRANCH:=''} EXIT_CODE_ICON=${EXIT_CODE_ICON:=' '} -# Ssh user and fqdn display +# Ssh user and hostname display SSH_INFO=${BARBUK_SSH_INFO:=true} HOST_INFO=${BARBUK_HOST_INFO:=long} From 3c6ffeb44fd50bdc5d9b07be89293139a6976ca4 Mon Sep 17 00:00:00 2001 From: BarbUk Date: Wed, 1 Apr 2020 12:09:54 +0400 Subject: [PATCH 9/9] Update theme var prefix --- themes/barbuk/README.md | 8 ++++---- themes/barbuk/barbuk.theme.bash | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/themes/barbuk/README.md b/themes/barbuk/README.md index dad6e140..4fe752b4 100644 --- a/themes/barbuk/README.md +++ b/themes/barbuk/README.md @@ -43,16 +43,16 @@ source "$BASH_IT"/bash_it.sh ### Usage When using a ssh session, the theme will display `user@hostname`. -You can disable this information with `BARBUK_SSH_INFO`. +You can disable this information with `BASH_IT_THEME_BARBUK_SSH_INFO`. The hostname is displayed in the FQDN format by default. You -can use the short hostname format with `BARBUK_HOST_INFO`. +can use the short hostname format with `BASH_IT_THEME_BARBUK_HOST_INFO`. ```bash # short or long -export BARBUK_HOST_INFO=short +export BASH_IT_THEME_BARBUK_HOST_INFO=short # true or false -export BARBUK_SSH_INFO=false +export BASH_IT_THEME_BARBUK_SSH_INFO=false source "$BASH_IT"/bash_it.sh ``` diff --git a/themes/barbuk/barbuk.theme.bash b/themes/barbuk/barbuk.theme.bash index 7990ca91..011fec32 100644 --- a/themes/barbuk/barbuk.theme.bash +++ b/themes/barbuk/barbuk.theme.bash @@ -10,8 +10,8 @@ SCM_GIT_CHAR_ICON_BRANCH=${SCM_GIT_CHAR_ICON_BRANCH:=''} EXIT_CODE_ICON=${EXIT_CODE_ICON:=' '} # Ssh user and hostname display -SSH_INFO=${BARBUK_SSH_INFO:=true} -HOST_INFO=${BARBUK_HOST_INFO:=long} +SSH_INFO=${BASH_IT_THEME_BARBUK_SSH_INFO:=true} +HOST_INFO=${BASH_IT_THEME_BARBUK_HOST_INFO:=long} # Bash-it default glyphs customization SCM_HG_CHAR='☿ '