aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2022-10-27 22:56:23 -0300
committerEuAndreh <eu@euandre.org>2022-10-27 22:56:23 -0300
commit19b4f463e1c2cfbc328f0029432751a1804466b5 (patch)
treec15d902432724ad81ff150a014bed13d172a21ec
parentetc/sh/rc: Refactor "s", "d" and "ds" aliases using the new vcs(1) (diff)
downloaddotfiles-19b4f463e1c2cfbc328f0029432751a1804466b5.tar.gz
dotfiles-19b4f463e1c2cfbc328f0029432751a1804466b5.tar.xz
etc/sh/vcs-ps1.sh: Simplify, using vcs(1)
-rw-r--r--etc/sh/vcs-ps1.sh100
1 files changed, 1 insertions, 99 deletions
diff --git a/etc/sh/vcs-ps1.sh b/etc/sh/vcs-ps1.sh
index 72df2c4..e12c042 100644
--- a/etc/sh/vcs-ps1.sh
+++ b/etc/sh/vcs-ps1.sh
@@ -1,105 +1,7 @@
#!/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)"
-
- IS_AHEAD=false
- IS_BEHIND=false
- if echo "$BRANCH_LINE" | grep -q 'ahead'; then
- IS_AHEAD=true
- fi
- if echo "$BRANCH_LINE" | grep -q 'behind'; then
- IS_BEHIND=true
- fi
-
- LINE=''
-
- if [ "$IS_AHEAD" = true ] && [ "$IS_BEHIND" = true ]; then
- LINE="^^^ $BRANCH_NAME vvv"
- elif [ "$IS_AHEAD" = true ]; then
- LINE="^ $BRANCH_NAME ^"
- elif [ "$IS_BEHIND" = true ]; then
- LINE="v $BRANCH_NAME v"
- else
- LINE="$BRANCH_NAME"
- fi
-
- HAS_DIFF=false
- HAS_UNTRACKED=false
- if echo "$DIFF_LINES" | grep -q '^[A|D|M| ][M|D| ]'; then
- HAS_DIFF=true
- fi
- if echo "$DIFF_LINES" | grep -q '^[?][?]'; then
- HAS_UNTRACKED=true
- fi
-
- if [ "$HAS_DIFF" = true ]; then
- COLOR_FN=redb
- LINE="{$LINE}"
- elif [ "$IS_AHEAD" = true ] || [ "$IS_BEHIND" = true ]; then
- COLOR_FN=bluei
- LINE="[$LINE]"
- elif [ "$HAS_UNTRACKED" = true ]; then
- COLOR_FN=lightblue
- LINE="{$LINE}"
- else
- COLOR_FN=green
- LINE="($LINE)"
- fi
-
- color -c "$COLOR_FN" "$LINE"
-
- BRANCH_COUNT="$(git branch --list | wc -l)"
- if [ "$BRANCH_COUNT" -gt 1 ]; then
- color -c lightblue "<$BRANCH_COUNT>"
- fi
-
- STASH_COUNT="$(git stash list | wc -l)"
- if [ "$STASH_COUNT" != 0 ]; then
- color -c red "*$STASH_COUNT"
- fi
-
- color -c 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 -c "$COLOR_FN" "$LINE"
-
- color -c 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
+ vcs ps1
}