Skip to content

vcs_hg survey: make _ps1_hg_status work again #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fi
export PATH MANPATH

# Base functions ready. Let's load bashrc.d.
for script in /etc/bashrc.d/*; do . "$script"; done
for script in /etc/bashrc.d/!(_vcs); do . "$script"; done

# The prompt depends on vcs_status! Get one backup anyway.
type _vcs_status &>/dev/null || \
Expand Down
17 changes: 8 additions & 9 deletions bashrc.d/20-vcs → bashrc.d/20-vcs.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 20-vcs, the version control display for AOSC OSes PS1.
# 20-vcs, the version control display for AOSC OS PS1.
# by Arthur Wang

# This module is highly extensible. Just read the source.
Expand All @@ -8,18 +8,17 @@
_is_posix && return

# Get functions
_vcs_files="$(echo /etc/bashrc.d/.vcs_*)"
if [ "$_vcs_files" == "/etc/bashrc.d/.vcs_*" ]; then
if [ -e /etc/bashrc.d/_vcs ]; then
for _vcs in /etc/bashrc.d/_vcs/*; do
. "$_vcs"
_vcs_mods+=" $(basename ${_vcs})"
done
else
_vcs_status(){ true; }
unset _vcs_files
return
else
for _vcs in $_vcs_files; do
. "$_vcs"
_vcs_mods+=" ${_vcs/\/etc\/bashrc.d\/.vcs_}"
done
fi
unset _vcs _vcs_files
unset _vcs

# Output
_vcs_status() {
Expand Down
3 changes: 3 additions & 0 deletions bashrc.d/.vcs_git → bashrc.d/_vcs/git
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ _ps1_git_status() {
local bgs
bgs=$(bash-git-status)
case "$?" in
1)
return 1
;;
5)
echo -e "\01\e[1m\02@\01\e[0;32m\0002$bgs\01\e[0m\02"
;;
Expand Down
15 changes: 11 additions & 4 deletions bashrc.d/.vcs_hg → bashrc.d/_vcs/hg
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ alias ha='hg add .'
# From http://mediadoneright.com/content/ultimate-git-ps1-bash-prompt
# Modified for hg.
_ps1_hg_status() {
hg branch &>/dev/null || return 1
if LC_ALL=C hg status | grep -q ' '; then
echo -ne "@\01\e[1m\]\01\e[0;32m\]$(hg branch)\01\e[0m\]"
# skip the check if possible, because hg is slow.
test -e .hg || return 1
hgb=$(hg branch 2>/dev/null) || return 1
hgs=$(LC_ALL=C hg status 2>&1)
if [ -z "$hgs" ]; then # unmodified
echo -e "\01\e[1m\02@\01\e[0;32m\0002$hgb\01\e[0m\02"
elif printf %s "$hgs" | grep -q '^[M!]'; then # modified or deleted
echo -e "\01\e[1m\02@\01$IRED\0002$hgb\01\e[0m\02"
elif printf %s "$hgs" | grep -q '^?'; then # untracked
echo -e "\01\e[1m\02@\01\e[0;35m\0002$hgb\01\e[0m\02"
else
echo -ne "@\01\e[1m\]\01$IRED\]$(hg branch)\01\e[0m\]"
echo -e "\01\e[1m\02@\01\e[0;37m\0002$hgb\01\e[0m\02"
fi
}

Expand Down