]> git.immae.eu Git - perso/Immae/Config/Ansible.git/blobdiff - roles/shell/bash/templates/bashrc.j2
Fix prompt for bash
[perso/Immae/Config/Ansible.git] / roles / shell / bash / templates / bashrc.j2
index c7f85224b579b28d436bc72eda2924e655b35df3..2c5a999292339757da03e186af9e85f20bdd5e7f 100644 (file)
@@ -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