summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.config/bash/bashrc3
-rw-r--r--.config/bash/prompt42
2 files changed, 43 insertions, 2 deletions
diff --git a/.config/bash/bashrc b/.config/bash/bashrc
index bd440fc..fa1c425 100644
--- a/.config/bash/bashrc
+++ b/.config/bash/bashrc
@@ -41,8 +41,7 @@ if [[ $TERM == +(xterm-256color|tmux-256color|foot) ]]; then
alias pacman='pacman --color auto'
alias bat='bat --color=always'
export LESS="--RAW-CONTROL-CHARS" # `less` display colors instead of the raw escape sequences
- # Prompt
- PS1='\[\033[01;32m\][\u@\h\[\033[01;37m\] \W :$SHLVL :\j\[\033[01;32m\]]\$\[\033[00m\] '
+ source_if_readable "$HOME/.config/bash/prompt"
fi
# History
diff --git a/.config/bash/prompt b/.config/bash/prompt
new file mode 100644
index 0000000..13316c3
--- /dev/null
+++ b/.config/bash/prompt
@@ -0,0 +1,42 @@
+# prompt
+#
+# bash prompt configuration
+
+declare -A colors=(
+ [bold_black]='\[\e[01;30m\]'
+ [bold_red]='\[\e[01;31m\]'
+ [bold_green]='\[\e[01;32m\]'
+ [bold_yellow]='\[\e[01;33m\]'
+ [bold_blue]='\[\e[01;34m\]'
+ [bold_magenta]='\[\e[01;35m\]'
+ [bold_cyan]='\[\e[01;36m\]'
+ [bold_white]='\[\e[01;37m\]'
+ [reset]='\[\e[00m\]'
+)
+
+# Shell nesting level — only shown when nested beyond the first sub-shell
+function prompt_shlvl() {
+ ((SHLVL > 1)) && printf '%s:%s ' $'' "$SHLVL"
+}
+
+function prompt_jobs() {
+ local job_count
+ job_count=$(jobs | wc --lines)
+ ((job_count > 0)) && printf '%s:%s ' $'' "$job_count"
+}
+
+# Diverging commits vs the upstream branch — empty when in sync, no upstream, or outside a repo
+function prompt_git() {
+ local ahead behind
+ read -r ahead behind < <(git rev-list --left-right --count "HEAD...@{u}" 2>/dev/null) || return
+ ((ahead == 0 && behind == 0)) && return
+ local green=$'\001\e[01;32m\002' red=$'\001\e[01;31m\002' reset=$'\001\e[00m\002'
+ local out=
+ ((ahead > 0)) && out+="${green}↑${ahead}${reset}"
+ ((behind > 0)) && out+="${red}↓${behind}${reset}"
+ printf '%s ' "$out"
+}
+
+PS1=${colors[bold_green]}'[\u@\h'${colors[bold_white]}' \W $(prompt_git)$(prompt_shlvl)$(prompt_jobs)${colors[bold_green]}]\$'${colors[reset]}' '
+
+# vim: ft=bash