aboutsummaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2022-03-28 08:55:56 -0300
committerEuAndreh <eu@euandre.org>2022-03-28 08:55:56 -0300
commit8fd3a199c8b67a2a5dceedc0e021b3c31ec96e4e (patch)
tree68cc4767190ff3b89e7dd313aa4964f69405b95c /sh
parentsh/reload.sh: Remove tmuxinator-templates.sh (diff)
downloaddotfiles-8fd3a199c8b67a2a5dceedc0e021b3c31ec96e4e.tar.gz
dotfiles-8fd3a199c8b67a2a5dceedc0e021b3c31ec96e4e.tar.xz
sh/ps1.sh: Factor decisions into separate functions
Diffstat (limited to 'sh')
-rw-r--r--sh/ps1.sh143
1 files changed, 90 insertions, 53 deletions
diff --git a/sh/ps1.sh b/sh/ps1.sh
index 0c030707..c0fdd967 100644
--- a/sh/ps1.sh
+++ b/sh/ps1.sh
@@ -1,5 +1,95 @@
#!/bin/sh
+repo_status_git() {
+ BRANCH_NAME="$(git rev-parse --abbrev-ref HEAD)"
+ OUT="$(git status --short --branch --porcelain)"
+ BRANCH_LINE="$(echo "$OUT" | head -n 1)"
+ DIFF_LINES="$(echo "$OUT" | tail -n +2)"
+
+ if echo "$BRANCH_LINE" | grep -q 'ahead'; then
+ IS_AHEAD=1
+ fi
+ if echo "$BRANCH_LINE" | grep -q 'behind'; then
+ IS_BEHIND=1
+ fi
+
+ if [ -n "$IS_AHEAD" ] && [ -n "$IS_BEHIND" ]; then
+ BRANCH_MARKER="^^^ $BRANCH_NAME vvv"
+ elif [ -n "$IS_AHEAD" ]; then
+ BRANCH_MARKER="^ $BRANCH_NAME ^"
+ elif [ -n "$IS_BEHIND" ]; then
+ BRANCH_MARKER="v $BRANCH_NAME v"
+ else
+ BRANCH_MARKER="$BRANCH_NAME"
+ fi
+
+ if echo "$DIFF_LINES" | grep -q '^[A|D|M| ][M|D| ]'; then
+ HAS_DIFF=1
+ fi
+
+ if echo "$DIFF_LINES" | grep -q '^[?][?]'; then
+ HAS_UNTRACKED=1
+ fi
+
+ if [ -n "$HAS_DIFF" ]; then
+ COLOR_FN=redb
+ LINE="{$BRANCH_MARKER}"
+ elif [ -n "$IS_AHEAD" ] || [ -n "$IS_BEHIND" ]; then
+ COLOR_FN=bluei
+ LINE="[$BRANCH_MARKER]"
+ elif [ -n "$HAS_UNTRACKED" ]; then
+ COLOR_FN=lightblue
+ LINE="($BRANCH_MARKER)"
+ else
+ COLOR_FN=green
+ LINE="($BRANCH_MARKER)"
+ fi
+
+ "$COLOR_FN" "$LINE"
+
+ blacki " - git/$(git rev-parse HEAD)"
+}
+
+repo_status_fossil() {
+ BRANCH_NAME="$(fossil branch current)"
+
+ if [ -n "$(fossil extras)" ]; then
+ HAS_UNTRACKED=1
+ fi
+
+ BRANCH_MARKER="$BRANCH_NAME"
+
+ if [ -n "${HAS_UNTRACKED:-}" ]; then
+ COLOR_FN=lightblue
+ LINE="($BRANCH_MARKER)"
+ else
+ COLOR_FN=green
+ LINE="($BRANCH_MARKER)"
+ fi
+
+ "$COLOR_FN" "$LINE"
+
+ # echo 'FOSSIL!'
+ # printf '%s' "$BRANCH_NAME"
+ blacki " - fossil/$(fossil info | awk '/^checkout:/ { print $2 }')"
+}
+
+repo_status_mercurial() {
+ BRANCH_NAME="$(hg branch)"
+}
+
+repo_status() {
+ dir="$(basename "$PWD")"
+ if [ -d .git ]; then
+ repo_status_git
+ elif [ -f "$dir.fossil" ]; then
+ repo_status_fossil
+ elif [ -d .hg ]; then
+ repo_status_mercurial
+ fi
+}
+
+
error_marker() {
STATUS=$?
if [ "$STATUS" != 0 ]; then
@@ -15,59 +105,6 @@ path() {
yellowb '\w/'
}
-repo_status() {
- inner="$(__git_ps1 "%s")"
- if [ -n "$inner" ]; then
- OUT="$(git status --short --branch --porcelain 2>/dev/null)"
- BRANCH_LINE="$(echo "$OUT" | head -n 1)"
- DIFF_LINES="$(echo "$OUT" | tail -n +2)"
-
- if echo "$BRANCH_LINE" | grep -q 'ahead'; then
- IS_AHEAD=1
- fi
- if echo "$BRANCH_LINE" | grep -q 'behind'; then
- IS_BEHIND=1
- fi
-
- if [ -n "$IS_AHEAD" ] && [ -n "$IS_BEHIND" ]; then
- BRANCH_MARKER="^^^ $inner vvv"
- elif [ -n "$IS_AHEAD" ]; then
- BRANCH_MARKER="^ $inner ^"
- elif [ -n "$IS_BEHIND" ]; then
- BRANCH_MARKER="v $inner v"
- else
- BRANCH_MARKER="$inner"
- fi
-
- if echo "$DIFF_LINES" | grep -q '^[A|D|M| ][M|D| ]'; then
- HAS_DIFF=1
- fi
-
- if echo "$DIFF_LINES" | grep -q '^[?][?]'; then
- HAS_UNTRACKED=1
- fi
-
- if [ -n "$HAS_DIFF" ]; then
- COLOR_FN=redb
- LINE="{$BRANCH_MARKER}"
- elif [ -n "$IS_AHEAD" ] || [ -n "$IS_BEHIND" ]; then
- COLOR_FN=bluei
- LINE="[$BRANCH_MARKER]"
- elif [ -n "$HAS_UNTRACKED" ]; then
- COLOR_FN=lightblue
- LINE="($BRANCH_MARKER)"
- else
- COLOR_FN=green
- LINE="($BRANCH_MARKER)"
- fi
-
- "$COLOR_FN" "$LINE"
-
- printf ' - '
- blacki "$(git rev-parse HEAD)"
- fi
-}
-
guix_env() {
if [ "$GUIX_ENVIRONMENT" != '' ]; then
printf '\n'