diff options
author | Ismaël Bouya <ismael.bouya@fretlink.com> | 2018-12-09 14:11:23 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@fretlink.com> | 2018-12-09 14:11:23 +0100 |
commit | 2fdf2f6d26026f2e1875e108ad9f0391c9d7f77e (patch) | |
tree | f51b563feaa206e02babcd9403cbca9c2bb73fec | |
parent | d4357f69e1ccbb1c277f8978ea6f4a368b3ee3c2 (diff) | |
download | Ansible-2fdf2f6d26026f2e1875e108ad9f0391c9d7f77e.tar.gz Ansible-2fdf2f6d26026f2e1875e108ad9f0391c9d7f77e.tar.zst Ansible-2fdf2f6d26026f2e1875e108ad9f0391c9d7f77e.zip |
Fix prompt for bash
-rw-r--r-- | roles/shell/bash/templates/bashrc.j2 | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/roles/shell/bash/templates/bashrc.j2 b/roles/shell/bash/templates/bashrc.j2 index c7f8522..2c5a999 100644 --- a/roles/shell/bash/templates/bashrc.j2 +++ b/roles/shell/bash/templates/bashrc.j2 | |||
@@ -90,32 +90,36 @@ function git_prompt() { | |||
90 | } | 90 | } |
91 | {% set ps1_git = '\[$(git_prompt_color)\]$(git_prompt)' %} | 91 | {% set ps1_git = '\[$(git_prompt_color)\]$(git_prompt)' %} |
92 | 92 | ||
93 | function error_code() { | ||
94 | ret=$? | ||
95 | if [[ $ret != 0 ]]; then | ||
96 | echo "$ret " | ||
97 | fi | ||
98 | } | ||
99 | |||
100 | function running_jobs() { | 93 | function running_jobs() { |
101 | ret=$(jobs | wc -l) | 94 | ret=$(jobs | wc -l) |
102 | if [[ $ret != 0 ]]; then | 95 | if [[ $ret != 0 ]]; then |
103 | echo "[$ret] " | 96 | echo "[$ret] " |
104 | fi | 97 | fi |
105 | } | 98 | } |
106 | {% set ps1_status = '\[\\033[01;31m\]$(error_code)\[\\033[00;00m\]$(running_jobs)' -%} | ||
107 | |||
108 | {# Ensure new line before the prompt #} | ||
109 | {% set ps1_newline = '$(printf "%$((`tput cols`-1))s\\r")' -%} | ||
110 | 99 | ||
111 | {% set ps1_other = '' %} | 100 | PROMPT_COMMAND=__prompt_command |
112 | {% if role.get(profile) == "fretlink" -%} | ||
113 | {% set ps1_other = '\[\\033[01;32m\]$(dev_prompt)' %} | ||
114 | {%- endif %} | ||
115 | 101 | ||
116 | PS1='{{ ps1_newline }}{{ ps1_status }}{{ ps1_other }}{{ ps1_git }}\[\033[00;32m\]\u@\h\[\033[94m\] \w \$\[\033[00m\] ' | 102 | __prompt_command () { |
103 | local ret="$?" | ||
104 | PS1="" | ||
105 | d="\[\033[00;00m\]" | ||
106 | red="\[\033[01;31m\]" | ||
107 | bgreen="\[\033[01;32m\]" | ||
108 | green="\[\033[00;32m\]" | ||
109 | blue="\[\033[94m\]" | ||
117 | 110 | ||
118 | PROMPT_COMMAND="[[ -f $XDG_STATE_HOME/bash/bashrc_temp ]] && . $XDG_STATE_HOME/bash/bashrc_temp" | 111 | # Ensure new line before the prompt |
112 | PS1='$(printf "%$((`tput cols`-1))s\r")' | ||
113 | if [[ $ret != 0 ]]; then | ||
114 | PS1+="$red$ret $d" | ||
115 | fi | ||
116 | PS1+='$(running_jobs)' | ||
117 | {% if role.get(profile) == "fretlink" %} | ||
118 | PS1+="$bgreen"'$(dev_prompt)' | ||
119 | {% endif %} | ||
120 | PS1+='\[$(git_prompt_color)\]$(git_prompt)' | ||
121 | PS1+="$green\u@\h$blue \w \$$d " | ||
122 | } | ||
119 | 123 | ||
120 | {% if "nodejs" in features.get(profile, []) %} | 124 | {% if "nodejs" in features.get(profile, []) %} |
121 | source /usr/share/nvm/init-nvm.sh | 125 | source /usr/share/nvm/init-nvm.sh |