From 2fdf2f6d26026f2e1875e108ad9f0391c9d7f77e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 9 Dec 2018 14:11:23 +0100 Subject: [PATCH] Fix prompt for bash --- roles/shell/bash/templates/bashrc.j2 | 38 +++++++++++++++------------- 1 file 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() { } {% set ps1_git = '\[$(git_prompt_color)\]$(git_prompt)' %} -function error_code() { - ret=$? - if [[ $ret != 0 ]]; then - echo "$ret " - fi -} - function running_jobs() { ret=$(jobs | wc -l) if [[ $ret != 0 ]]; then echo "[$ret] " fi } -{% set ps1_status = '\[\\033[01;31m\]$(error_code)\[\\033[00;00m\]$(running_jobs)' -%} - -{# Ensure new line before the prompt #} -{% set ps1_newline = '$(printf "%$((`tput cols`-1))s\\r")' -%} -{% set ps1_other = '' %} -{% if role.get(profile) == "fretlink" -%} - {% set ps1_other = '\[\\033[01;32m\]$(dev_prompt)' %} -{%- endif %} +PROMPT_COMMAND=__prompt_command -PS1='{{ ps1_newline }}{{ ps1_status }}{{ ps1_other }}{{ ps1_git }}\[\033[00;32m\]\u@\h\[\033[94m\] \w \$\[\033[00m\] ' +__prompt_command () { + local ret="$?" + PS1="" + d="\[\033[00;00m\]" + red="\[\033[01;31m\]" + bgreen="\[\033[01;32m\]" + green="\[\033[00;32m\]" + blue="\[\033[94m\]" -PROMPT_COMMAND="[[ -f $XDG_STATE_HOME/bash/bashrc_temp ]] && . $XDG_STATE_HOME/bash/bashrc_temp" + # Ensure new line before the prompt + PS1='$(printf "%$((`tput cols`-1))s\r")' + if [[ $ret != 0 ]]; then + PS1+="$red$ret $d" + fi + PS1+='$(running_jobs)' +{% if role.get(profile) == "fretlink" %} + PS1+="$bgreen"'$(dev_prompt)' +{% endif %} + PS1+='\[$(git_prompt_color)\]$(git_prompt)' + PS1+="$green\u@\h$blue \w \$$d " +} {% if "nodejs" in features.get(profile, []) %} source /usr/share/nvm/init-nvm.sh -- 2.41.0