Merge pull request #1536 from BarbUk/update/barbuk_theme_ssh
Theme barbuk: Add ssh detection and user@host information in ssh sessionpull/1543/head
commit
f4618ae918
|
|
@ -8,6 +8,7 @@ A minimal theme with a clean git prompt
|
||||||
* Current path (red when user is root)
|
* Current path (red when user is root)
|
||||||
* Current git info
|
* Current git info
|
||||||
* Last command exit code (only shown when the exit code is greater than 0)
|
* Last command exit code (only shown when the exit code is greater than 0)
|
||||||
|
* user@hostname for ssh connection
|
||||||
|
|
||||||
## Fonts and glyphs
|
## Fonts and glyphs
|
||||||
|
|
||||||
|
|
@ -37,6 +38,44 @@ SCM_GIT_CHAR_GITHUB='•'
|
||||||
source "$BASH_IT"/bash_it.sh
|
source "$BASH_IT"/bash_it.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## SSH prompt
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
When using a ssh session, the theme will display `user@hostname`.
|
||||||
|
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 `BASH_IT_THEME_BARBUK_HOST_INFO`.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# short or long
|
||||||
|
export BASH_IT_THEME_BARBUK_HOST_INFO=short
|
||||||
|
# true or false
|
||||||
|
export BASH_IT_THEME_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.
|
||||||
|
|
||||||
|
`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
|
## Examples
|
||||||
|
|
||||||
### Clean
|
### Clean
|
||||||
|
|
@ -51,3 +90,8 @@ source "$BASH_IT"/bash_it.sh
|
||||||
~/.dotfiles on master ⤏ origin ↑2 •7 ✗ ❯
|
~/.dotfiles on master ⤏ origin ↑2 •7 ✗ ❯
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Ssh
|
||||||
|
|
||||||
|
```bash
|
||||||
|
user@hostname in ~/bash-it on master ✓ ❯
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,10 @@ SCM_GIT_CHAR_DEFAULT=${SCM_GIT_CHAR_DEFAULT:=' '}
|
||||||
SCM_GIT_CHAR_ICON_BRANCH=${SCM_GIT_CHAR_ICON_BRANCH:=''}
|
SCM_GIT_CHAR_ICON_BRANCH=${SCM_GIT_CHAR_ICON_BRANCH:=''}
|
||||||
EXIT_CODE_ICON=${EXIT_CODE_ICON:=' '}
|
EXIT_CODE_ICON=${EXIT_CODE_ICON:=' '}
|
||||||
|
|
||||||
|
# Ssh user and hostname display
|
||||||
|
SSH_INFO=${BASH_IT_THEME_BARBUK_SSH_INFO:=true}
|
||||||
|
HOST_INFO=${BASH_IT_THEME_BARBUK_HOST_INFO:=long}
|
||||||
|
|
||||||
# Bash-it default glyphs customization
|
# Bash-it default glyphs customization
|
||||||
SCM_HG_CHAR='☿ '
|
SCM_HG_CHAR='☿ '
|
||||||
SCM_SVN_CHAR='⑆ '
|
SCM_SVN_CHAR='⑆ '
|
||||||
|
|
@ -31,7 +35,7 @@ SCM_THEME_CURRENT_USER_PREFFIX=' '
|
||||||
SCM_GIT_SHOW_CURRENT_USER=false
|
SCM_GIT_SHOW_CURRENT_USER=false
|
||||||
|
|
||||||
function _git-uptream-remote-logo {
|
function _git-uptream-remote-logo {
|
||||||
[[ "$(_git-upstream)" == "" ]] && return
|
[[ "$(_git-upstream)" == "" ]] && SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT"
|
||||||
|
|
||||||
local remote remote_domain
|
local remote remote_domain
|
||||||
remote=$(_git-upstream-remote)
|
remote=$(_git-upstream-remote)
|
||||||
|
|
@ -62,7 +66,7 @@ function _exit-code {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _prompt {
|
function _prompt {
|
||||||
local exit_code="$?" wrap_char=' ' dir_color=$green
|
local exit_code="$?" wrap_char=' ' dir_color=$green ssh_info='' host
|
||||||
|
|
||||||
_exit-code exit_code
|
_exit-code exit_code
|
||||||
_git-uptream-remote-logo
|
_git-uptream-remote-logo
|
||||||
|
|
@ -74,7 +78,17 @@ function _prompt {
|
||||||
dir_color=$red
|
dir_color=$red
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PS1="\\n ${purple}$(scm_char)${dir_color}\\w${normal}$(scm_prompt_info)${exit_code}"
|
# Detect ssh
|
||||||
|
if [[ -n "${SSH_CONNECTION}" ]] && [ "$SSH_INFO" = true ]; then
|
||||||
|
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}"
|
||||||
|
|
||||||
[[ ${#PS1} -gt $((COLUMNS*3)) ]] && wrap_char="\\n"
|
[[ ${#PS1} -gt $((COLUMNS*3)) ]] && wrap_char="\\n"
|
||||||
PS1="${PS1}${wrap_char}❯${normal} "
|
PS1="${PS1}${wrap_char}❯${normal} "
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue