aboutsummaryrefslogtreecommitdiff
path: root/config/bash/ps1.sh
diff options
context:
space:
mode:
authorben <ben@nagy.contact>2025-05-03 14:17:11 -0700
committerben <ben@nagy.contact>2025-05-03 14:17:11 -0700
commit0670c4910a615244900af884a7919509d99e2176 (patch)
treedd9f60cb7f99ec04639cb9e7a577c8e164c18042 /config/bash/ps1.sh
parent03aa9b73a6db45535b745e8c5d6f548beb5c8aaf (diff)
bash
Diffstat (limited to 'config/bash/ps1.sh')
-rw-r--r--config/bash/ps1.sh62
1 files changed, 62 insertions, 0 deletions
diff --git a/config/bash/ps1.sh b/config/bash/ps1.sh
new file mode 100644
index 0000000..35a182a
--- /dev/null
+++ b/config/bash/ps1.sh
@@ -0,0 +1,62 @@
+function parse_git_branch {
+ git rev-parse --is-inside-work-tree &>/dev/null || return
+ local branch=$(git symbolic-ref --short HEAD 2>/dev/null || git describe --tags --exact-match 2>/dev/null)
+
+ echo "(${branch})"
+}
+
+
+## ✗ ✓ ↑ ↓ ↲ ↲ ↳ ↴ ↵ ↺ ➔ ➙ ➜ ➥
+function parse_git_status {
+ local symbol="✓" # clean state (up to date)
+
+ if git rev-parse --is-inside-work-tree &>/dev/null; then
+ local branch
+ branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
+
+ # Ahead / behind remote
+ if [[ "$branch" != "HEAD" ]]; then
+ local behind=$(git rev-list --count HEAD..origin/$branch 2>/dev/null || echo 0)
+ local ahead=$(git rev-list --count origin/$branch..HEAD 2>/dev/null || echo 0)
+ if [[ "$ahead" -gt 0 ]]; then
+ symbol="↑"
+ elif [[ "$behind" -gt 0 ]]; then
+ symbol="↓"
+ fi
+ fi
+
+ # Unstaged changes
+ if ! git diff --quiet 2>/dev/null; then
+ symbol="✗"
+ fi
+ if ! git diff --cached --quiet 2>/dev/null; then
+ symbol="✗"
+ fi
+
+ # untracked files
+ if git ls-files --others --exclude-standard -z | grep -q .; then
+ symbol="?"
+ fi
+ fi
+
+ echo "${symbol}"
+}
+
+function set_PS1 {
+ WHITE="\[\033[01;015m\]"
+ YELLOW="\[\033[01;33m\]"
+ BLUE="\[\033[01;34m\]"
+ RED="\[\033[01;31m\]"
+ PINK="\[\033[01;35m\]"
+ RESET="\[\033[0m\]"
+
+ if git rev-parse --is-inside-work-tree &>/dev/null; then
+ PS1="${YELLOW}\u@\h ${BLUE}[$(basename "$PWD")]${RED}$(parse_git_branch) ${RESET}$(parse_git_status) ${PINK}\$:${RESET} "
+ else
+ PS1="${WHITE}\u@\h \$: ${RESET}"
+ #PS1="\[\033[01;015m\]\u@\h $: \[\033[0m\]"
+ fi
+}
+
+set_PS1
+PROMPT_COMMAND=set_PS1