summaryrefslogtreecommitdiffstats
path: root/.config/bash/prompt
diff options
context:
space:
mode:
Diffstat (limited to '.config/bash/prompt')
-rw-r--r--.config/bash/prompt42
1 files changed, 42 insertions, 0 deletions
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