Skip to content

Commit f5a75ae

Browse files
committed
extract bash git prompt from dotfiles
0 parents  commit f5a75ae

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

bash-git-prompt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
# bash git prompt
4+
GIT_PS1_SHOWDIRTYSTATE=true
5+
GIT_PS1_SHOWUNTRACKEDFILES=true
6+
GIT_PS1_SHOWUPSTREAM="verbose"
7+
8+
__git_ps1_improved() {
9+
local git_current_branch_name="\$(__git_ps1 '%s' | sed 's/ .\+//' | sed -e 's/[\\\\/&]/\\\\\\\\&/g')"
10+
local git_status_substitutes=(
11+
"s/$git_current_branch_name//;" # remove branch temporarily
12+
"s/u//;" # upstream
13+
"s/+\([0-9]\+\)/↑\1/;" # outgoing
14+
"s/-\([0-9]\+\)/↓\1/;" # incoming
15+
"s/%/?/;" # untracked
16+
"s/+/✓/;" # staged
17+
"s/*/✕/;" # unstaged
18+
"s/\(.*\)/⑂ $git_current_branch_name\1/;" # insert branch again
19+
)
20+
21+
echo "\$(__git_ps1 '%s'| sed \"${git_status_substitutes[@]}\")"
22+
}

0 commit comments

Comments
 (0)