Skip to content

Commit b28170d

Browse files
committed
bashrc{,.d}: VCS Prompt RL fixes. Fixed #8.
1 parent d726732 commit b28170d

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

bashrc

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,24 @@ alias la='ls -AF'
5252
for c in {e,f,}grep {v,}dir ls; do alias $c="$c --color=auto"; done;
5353

5454
# So they can be unset.
55+
# I need someone to help me assign those names properly.
56+
# Those are actually bold colors.
5557
_aosc_bashrc_colors='NORMAL RED GREEN CYAN IRED YELLOW'
56-
NORMAL=$'\\[\e[0m\\]'
57-
RED=$'\\[\e[1;31m\\]'
58-
GREEN=$'\\[\e[1;32m\\]'
59-
CYAN=$'\\[\e[1;36m\\]'
60-
61-
# Linux tty color workaround
62-
if [[ "$TERM" == linux ]]; then # && "$(tput colors)" == 8
63-
YELLOW=$'\\[\e[1;33m' IRED=$'\\[\e[0;31m\\]'
58+
NORMAL='\e[0m'
59+
RED='\e[1;31m'
60+
GREEN='\e[1;32m'
61+
CYAN='\e[1;36m'
62+
YELLOW='\e[1;93m'
63+
IRED='\e[0;91m'
64+
65+
if _rc_term_colors="$(tput colors &>/dev/null)"; then
66+
[ "$colors" -le 16 ]
6467
else
65-
YELLOW=$'\\[\e[1;93m' IRED=$'\\[\e[0;91m\\]'
66-
fi
68+
case "$TERM" in (linux|msys|cygwin) true;; (*) false;; esac
69+
fi && YELLOW='\e[1;33m' IRED='\e[0;31m'
70+
unset _rc_term_colors
71+
72+
# if our TERM has no color support, then unset $_aosc_bashrc_colors
6773

6874
# A simple error level reporting function.
6975
# Loaded back to PS1
@@ -95,9 +101,9 @@ type _vcs_status &>/dev/null || ! echo _vcs_status not declared, making stub.. |
95101
# Well, forget it.
96102

97103
if [[ "$EUID" == 0 ]] ; then
98-
PS1="$RED\u $NORMAL[ \W\$(_vcs_status) ]$RED \$(_ret_prompt) $NORMAL"
104+
PS1="\[$RED\]\u \[$NORMAL\][ \W\$(_vcs_status) ]\[$RED\] \$(_ret_prompt) \[$NORMAL\]"
99105
else
100-
PS1="$GREEN\u $NORMAL[ \W\$(_vcs_status) ]$GREEN \$(_ret_prompt) $NORMAL"
106+
PS1="\[$GREEN\]\u \[$NORMAL\][ \W\$(_vcs_status) ]\[$GREEN\] \$(_ret_prompt) \[$NORMAL\]"
101107
fi
102108

103109

@@ -110,7 +116,7 @@ _is_posix || which --version | grep GNU &>/dev/null && alias which='(alias; decl
110116

111117
# Misc stuffs
112118
FIGNORE='~'
113-
TIMEFORMAT=$'\nreal\t%3lR\t%P%%\nuser\t%3lU\nsys\t%3lS'
119+
TIMEFORMAT='\nreal\t%3lR\t%P%%\nuser\t%3lU\nsys\t%3lS'
114120

115121
unset script shopt
116122
# End /etc/bashrc

bashrc.d/.vcs_git

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ alias __git_branch="git branch 2>/dev/null | grep '*' | sed 's/*\ //g'"
3333
_git_status() {
3434
git branch &>/dev/null || return 1
3535
if LC_ALL=C git status | grep -q "nothing to commit"; then
36-
printf "\e[1m@\e[0;32m$(__git_branch)\e[0m"
36+
echo -e "\[\e[1m\]@\[\e[0;32m\]$(__git_branch)\[\e[0m\]"
3737
elif LC_ALL=C git status | grep -q "nothing added to commit"; then # Untracked
38-
printf "\e[1m@\e[0;35m$(__git_branch)\e[0m"
38+
echo -e "\[\e[1m\]@\[\e[0;35m\]$(__git_branch)\[\e[0m\]"
3939
else # Change not added/not merged yet
40-
printf "\e[1m@$IRED$(__git_branch)\e[0m"
40+
echo -e "\[\e[1m\]@\[$IRED\]$(__git_branch)\[\e[0m\]"
4141
fi
4242
}
4343

44-
4544
# A shorter one without color
4645
# alias _git_status='_st="$(__git_branch)"; ((!PIPESTATUS[0])) && echo "@$_st"'
46+
# For users of the contrib/completion __git_ps1
47+
# _git_status(){ git branch &>/dev/null || return 1; echo -n ' '; __git_ps1; }

bashrc.d/.vcs_hg

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ alias hb='hg branch'
1313
alias hs='hg status'
1414
alias ha='hg add .'
1515

16-
# From http://mediadoneright.com/content/ultimate-hg-ps1-bash-prompt
16+
# From http://mediadoneright.com/content/ultimate-git-ps1-bash-prompt
1717
# Modified for hg.
1818
_hg_status() {
19-
if hg branch &>/dev/null
20-
then if LC_ALL=C hg status | grep " " &>/dev/null
21-
then printf "\e[1m@\e[0;32m$(hg branch)\e[0m"
22-
else printf "\e[1m@$IRED$(hg branch)\e[0m"
23-
fi
24-
else false
25-
fi
19+
hg branch &>/dev/null || return 1
20+
if LC_ALL=C hg status | grep -q ' '; then
21+
echo -ne "@\[\e[1m\]\[\e[0;32m\]$(hg branch)\[\e[0m\]"
22+
else
23+
echo -ne "@\[\e[1m\]\[$IRED\]$(hg branch)\[\e[0m\]"
24+
fi
2625
}
2726

2827
# A shorter one without color

0 commit comments

Comments
 (0)