2016-09-29 14:03:09 +02:00
|
|
|
svn_prompt_info() {
|
2021-12-20 11:24:00 +01:00
|
|
|
local info display
|
|
|
|
info="$(LANG= svn info 2>/dev/null)" || return 1
|
|
|
|
|
|
|
|
if [[ "$SVN_SHOW_BRANCH" = true ]]; then
|
|
|
|
display="$(svn_get_branch_name "$info")"
|
|
|
|
else
|
|
|
|
display="$(svn_get_repo_name "$info")"
|
2012-12-30 20:18:12 +01:00
|
|
|
fi
|
2011-01-10 18:18:31 +01:00
|
|
|
|
2021-12-20 11:24:00 +01:00
|
|
|
printf '%s%s%s%s%s%s%s%s%s%s' \
|
|
|
|
"$ZSH_PROMPT_BASE_COLOR" \
|
|
|
|
"$ZSH_THEME_SVN_PROMPT_PREFIX" \
|
|
|
|
"$ZSH_THEME_REPO_NAME_COLOR" \
|
|
|
|
"${display:gs/%/%%}" \
|
|
|
|
"$ZSH_PROMPT_BASE_COLOR" \
|
|
|
|
"$ZSH_THEME_SVN_PROMPT_SUFFIX" \
|
|
|
|
"$ZSH_PROMPT_BASE_COLOR" \
|
|
|
|
"$(svn_dirty $info)" \
|
|
|
|
"$(svn_dirty_pwd)" \
|
|
|
|
"$ZSH_PROMPT_BASE_COLOR"
|
|
|
|
}
|
2011-01-10 18:18:31 +01:00
|
|
|
|
2016-09-29 14:03:09 +02:00
|
|
|
in_svn() {
|
2021-12-20 11:24:00 +01:00
|
|
|
svn info &>/dev/null
|
2011-01-10 18:18:31 +01:00
|
|
|
}
|
|
|
|
|
2016-09-29 14:03:09 +02:00
|
|
|
svn_get_repo_name() {
|
2021-12-20 11:22:54 +01:00
|
|
|
local info name
|
|
|
|
info="${1:-$(LANG= svn info 2>/dev/null)}"
|
|
|
|
name="$(sed -n 's/^Repository\ Root:\ .*\///p' <<< "$info")"
|
|
|
|
omz_urldecode "$name"
|
2011-01-10 18:18:31 +01:00
|
|
|
}
|
|
|
|
|
2016-09-29 14:03:09 +02:00
|
|
|
svn_get_branch_name() {
|
2021-12-20 11:24:00 +01:00
|
|
|
local info branch
|
|
|
|
info="${1:-$(LANG= svn info 2>/dev/null)}"
|
|
|
|
branch=$(
|
|
|
|
awk -F/ '/^URL:/ {
|
|
|
|
for (i=0; i<=NF; i++) {
|
|
|
|
if ($i == "branches" || $i == "tags" ) {
|
|
|
|
print $(i+1)
|
|
|
|
break
|
|
|
|
};
|
|
|
|
if ($i == "trunk") {
|
|
|
|
print $i
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}' <<< "$info"
|
2012-12-30 20:18:12 +01:00
|
|
|
)
|
2021-12-20 11:24:00 +01:00
|
|
|
branch="$(omz_urldecode "$branch")"
|
2016-09-29 14:03:09 +02:00
|
|
|
|
2021-12-20 11:24:00 +01:00
|
|
|
echo "${branch:-$(svn_get_repo_name "$info")}"
|
2012-11-08 21:48:43 +01:00
|
|
|
}
|
|
|
|
|
2016-09-29 14:03:09 +02:00
|
|
|
svn_get_rev_nr() {
|
2021-12-20 11:24:00 +01:00
|
|
|
sed -n 's/Revision:\ //p' "${1:-$(LANG= svn info 2>/dev/null)}"
|
2011-01-10 18:18:31 +01:00
|
|
|
}
|
|
|
|
|
2016-09-29 14:03:09 +02:00
|
|
|
svn_dirty() {
|
2021-12-20 11:24:00 +01:00
|
|
|
svn_dirty_choose "${1:-$(LANG= svn info 2>/dev/null)}" $ZSH_THEME_SVN_PROMPT_DIRTY $ZSH_THEME_SVN_PROMPT_CLEAN
|
2016-09-29 14:03:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
svn_dirty_choose() {
|
2021-12-20 11:24:00 +01:00
|
|
|
local root
|
|
|
|
root=$(sed -n 's/^Working Copy Root Path: //p' <<< "${1:-$(LANG= svn info 2>/dev/null)}")
|
|
|
|
if LANG= svn status "$root" 2>/dev/null | command grep -Eq '^\s*[ACDIM!?L]'; then
|
|
|
|
# Grep exits with 0 when "One or more lines were selected", return "dirty".
|
|
|
|
echo $1
|
|
|
|
else
|
|
|
|
# Otherwise, no lines were found, or an error occurred. Return clean.
|
|
|
|
echo $2
|
2012-12-30 20:18:12 +01:00
|
|
|
fi
|
2011-01-10 18:18:31 +01:00
|
|
|
}
|
|
|
|
|
2016-09-29 14:03:09 +02:00
|
|
|
svn_dirty_pwd () {
|
|
|
|
svn_dirty_choose_pwd $ZSH_THEME_SVN_PROMPT_DIRTY_PWD $ZSH_THEME_SVN_PROMPT_CLEAN_PWD
|
2011-06-03 16:32:05 +02:00
|
|
|
}
|
2014-03-07 20:17:18 +01:00
|
|
|
|
2016-09-29 14:03:09 +02:00
|
|
|
svn_dirty_choose_pwd () {
|
2021-12-20 11:24:00 +01:00
|
|
|
if LANG= svn status "$PWD" 2>/dev/null | command grep -Eq '^\s*[ACDIM!?L]'; then
|
|
|
|
# Grep exits with 0 when "One or more lines were selected", return "dirty".
|
|
|
|
echo $1
|
|
|
|
else
|
|
|
|
# Otherwise, no lines were found, or an error occurred. Return clean.
|
|
|
|
echo $2
|
2014-03-07 20:17:18 +01:00
|
|
|
fi
|
|
|
|
}
|