Skip to content

Commit a8f0294

Browse files
Show rebase/merge in progress along with number of
staged/worktree/untracked files It has be once too many times amending a commit and forgetting to stage first.
1 parent 5575995 commit a8f0294

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

gitconfig.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[alias]
22
add-without-whitespace = !sh -c 'git diff --unified=0 --ignore-all-space "$@" | git apply --cached --unidiff-zero -'
33
to-ssh = !git remote set-url origin $(git remote get-url origin | sed s+https://+git@+ | sed s+/+:+)
4-
prompt = !git symbolic-ref HEAD --short 2>/dev/null
54
top-committers = "!_() { \
65
git shortlog -sn --no-merges | head -n${1:-10}; \
76
}; _"

scripts/git-prompt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/env sh
2+
3+
# <https://stackoverflow.com/a/59115583>
4+
rebasing-branch() {
5+
for location in rebase-merge rebase-apply; do
6+
path=$(git rev-parse --git-path ${location})
7+
if test -d ${path}; then
8+
revision=$(<${path}/head-name)
9+
echo ${revision##refs/heads/}
10+
return 0
11+
fi
12+
done
13+
}
14+
15+
branch() {
16+
git symbolic-ref HEAD --short 2>/dev/null
17+
}
18+
19+
changes() {
20+
STAGED="$(git diff --cached --name-only 2>/dev/null | wc --lines)s"
21+
WORKTREE="$(git diff --name-only 2>/dev/null | wc --lines)w"
22+
UNTRACKED="$(git ls-files --others --exclude-standard 2>/dev/null | wc --lines)u"
23+
echo "${STAGED}${WORKTREE}${UNTRACKED}" | sed "s/0.//g"
24+
}
25+
26+
PROMPT=$(branch)
27+
if git rev-parse --quiet --verify MERGE_HEAD > /dev/null; then
28+
PROMPT="$PROMPT [merging]"
29+
elif git rev-parse --quiet --verify REBASE_HEAD > /dev/null; then
30+
PROMPT="$(rebasing-branch) [rebasing]"
31+
fi
32+
CHANGES=$(changes)
33+
if [[ -n "$CHANGES" ]]; then
34+
PROMPT="$PROMPT ($CHANGES)"
35+
fi
36+
echo "$PROMPT"

0 commit comments

Comments
 (0)