diff options
Diffstat (limited to 'src/.bashrc_ps1')
-rw-r--r-- | src/.bashrc_ps1 | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/src/.bashrc_ps1 b/src/.bashrc_ps1 index ae945a1..48599a5 100644 --- a/src/.bashrc_ps1 +++ b/src/.bashrc_ps1 @@ -1,49 +1,45 @@ -# Dynamic PS1: exit code, time, user, current directory, git, colorized +# Dynamic PS1 using terminal palette colors only function update_ps1 { local exit_code=$? # Color exit code: green if 0, red otherwise if [[ $exit_code -eq 0 ]]; then - local exit_display="\[\033[1;32m\]$exit_code\[\033[0m\]" # green + local exit_display="\[\e[1;32m\]$exit_code\[\e[0m\]" # bright green else - local exit_display="\[\033[1;31m\]$exit_code\[\033[0m\]" # red + local exit_display="\[\e[1;31m\]$exit_code\[\e[0m\]" # bright red fi - # Symbol always white - local symbol="\[\033[1;37m\]\$\[\033[0m\]" + # Symbol always bright white + local symbol="\[\e[1;37m\]\$\[\e[0m\]" - # White brackets - local open_bracket="\[\033[1;37m\][\[\033[0m\]" - local close_bracket="\[\033[1;37m\]]\[\033[0m\]" + # Brackets in bright white + local open_bracket="\[\e[1;37m\][\[\e[0m\]" + local close_bracket="\[\e[1;37m\]]\[\e[0m\]" - # Time in HH:MM:SS - #local time="\[\033[1;37m\]\t\[\033[0m\]" - - # User - #local user="\[\033[1;37m\]\u\[\033[0m\]" + # User: red for root, cyan otherwise if [ $(id -u) -eq 0 ]; then - local user="\[\033[1;31m\]\u\[\033[0m\]" + local user="\[\e[1;31m\]\u\[\e[0m\]" else - local user="\[\033[1;36m\]\u\[\033[0m\]" + local user="\[\e[1;36m\]\u\[\e[0m\]" fi - # Current folder only, ~ for home - local folder="\[\033[1;33m\]\W\[\033[0m\]" + # Current folder: yellow + local folder="\[\e[1;33m\]\W\[\e[0m\]" - # Git status + # Git status: green if up to date, red if ahead, yellow if dirty local git_status="" - if [[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" == true ]]; then - if [[ -z $(git log origin/master..HEAD 2>/dev/null) ]]; then - git_status="\[\033[1;38;5;10m\](git)\[\033[0m\]" # green if up to date + if git rev-parse --is-inside-work-tree &>/dev/null; then + if [[ -z $(git status --porcelain 2>/dev/null) ]]; then + git_status="\[\e[1;32m\](git)\[\e[0m\]" # clean else - git_status="\[\033[1;38;5;9m\](git)\[\033[0m\]" # red if ahead + git_status="\[\e[1;31m\](git)\[\e[0m\]" # dirty fi fi # Build the prompt - export PS1="${open_bracket} ${exit_display} ${user} ${folder} ${git_status}${close_bracket} ${symbol} " + PS1="${open_bracket}${exit_display} ${user} ${folder}${git_status}${close_bracket}${symbol} " } - # Update PS1 after every command PROMPT_COMMAND='update_ps1' + |