Escape strings that may comes from remote sources
Use printf "%q" to escape branch names.
This commit is contained in:
parent
b7ffd46f9b
commit
92bd933905
101
liquidprompt
101
liquidprompt
@ -317,6 +317,13 @@ unset _lp_source_config
|
|||||||
[[ "$LP_ENABLE_BZR" = 1 ]] && { command -v bzr > /dev/null || LP_ENABLE_BZR=0 ; }
|
[[ "$LP_ENABLE_BZR" = 1 ]] && { command -v bzr > /dev/null || LP_ENABLE_BZR=0 ; }
|
||||||
[[ "$LP_ENABLE_BATT" = 1 ]] && { command -v acpi >/dev/null || LP_ENABLE_BATT=0 ; }
|
[[ "$LP_ENABLE_BATT" = 1 ]] && { command -v acpi >/dev/null || LP_ENABLE_BATT=0 ; }
|
||||||
|
|
||||||
|
# Escape the given strings
|
||||||
|
# Must be used for all strings that may comes from remote sources,
|
||||||
|
# like VCS branch names
|
||||||
|
_lp_escape()
|
||||||
|
{
|
||||||
|
printf "%q" "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
###############
|
###############
|
||||||
@ -688,7 +695,8 @@ _lp_git_branch()
|
|||||||
branch="$(git rev-parse --short HEAD 2>/dev/null)"
|
branch="$(git rev-parse --short HEAD 2>/dev/null)"
|
||||||
fi
|
fi
|
||||||
[[ $? -ne 0 || -z "$branch" ]] && return
|
[[ $? -ne 0 || -z "$branch" ]] && return
|
||||||
echo "${branch#refs/heads/}"
|
branch="${branch#refs/heads/}"
|
||||||
|
echo $(_lp_escape "$branch")
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set a color depending on the branch state:
|
# Set a color depending on the branch state:
|
||||||
@ -772,7 +780,8 @@ _lp_hg_branch()
|
|||||||
[[ "$LP_ENABLE_HG" != 1 ]] && return
|
[[ "$LP_ENABLE_HG" != 1 ]] && return
|
||||||
local branch
|
local branch
|
||||||
branch="$(hg branch 2>/dev/null)"
|
branch="$(hg branch 2>/dev/null)"
|
||||||
[[ $? -eq 0 ]] && echo "$branch"
|
[[ $? -eq 0 ]] && echo $(_lp_escape "$branch")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set a color depending on the branch state:
|
# Set a color depending on the branch state:
|
||||||
@ -813,7 +822,7 @@ _lp_svn_branch()
|
|||||||
echo trunk
|
echo trunk
|
||||||
else
|
else
|
||||||
result=$(expr "$url" : '.*/branches/\([^/]*\)' || expr "$url" : '/\([^/]*\)' || basename "$root")
|
result=$(expr "$url" : '.*/branches/\([^/]*\)' || expr "$url" : '/\([^/]*\)' || basename "$root")
|
||||||
echo $result
|
echo $(_lp_escape "$result")
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -851,11 +860,11 @@ _lp_fossil_branch()
|
|||||||
local branch
|
local branch
|
||||||
branch=$(fossil status 2>/dev/null | grep tags: | cut -c17-)
|
branch=$(fossil status 2>/dev/null | grep tags: | cut -c17-)
|
||||||
if [[ -n "$branch" ]] ; then
|
if [[ -n "$branch" ]] ; then
|
||||||
echo "$branch"
|
echo $(_lp_escape "$branch")
|
||||||
else
|
else
|
||||||
if fossil info &>/dev/null ; then
|
if fossil info &>/dev/null ; then
|
||||||
echo "no-tag"
|
echo "no-tag"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -875,52 +884,52 @@ _lp_fossil_branch_color()
|
|||||||
branch=$(_lp_fossil_branch)
|
branch=$(_lp_fossil_branch)
|
||||||
|
|
||||||
if [[ ! -z "$branch" ]] ; then
|
if [[ ! -z "$branch" ]] ; then
|
||||||
local C2E # Modified files (added or edited)
|
local C2E # Modified files (added or edited)
|
||||||
local C2D # Deleted files
|
local C2D # Deleted files
|
||||||
local C2A # Extras files
|
local C2A # Extras files
|
||||||
local ret
|
local ret
|
||||||
C2E=$(fossil changes | wc -l)
|
C2E=$(fossil changes | wc -l)
|
||||||
C2D=$(fossil changes | grep DELETED | wc -l)
|
C2D=$(fossil changes | grep DELETED | wc -l)
|
||||||
let "C2E = $C2E - $C2D"
|
let "C2E = $C2E - $C2D"
|
||||||
C2A=$(fossil extras | wc -l)
|
C2A=$(fossil extras | wc -l)
|
||||||
ret=""
|
ret=""
|
||||||
|
|
||||||
if [[ "$C2E" -gt 0 ]] ; then
|
if [[ "$C2E" -gt 0 ]] ; then
|
||||||
ret+="+$C2E"
|
ret+="+$C2E"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$C2D" -gt 0 ]] ; then
|
if [[ "$C2D" -gt 0 ]] ; then
|
||||||
if [[ "$ret" = "" ]] ; then
|
if [[ "$ret" = "" ]] ; then
|
||||||
ret+="-$C2D"
|
ret+="-$C2D"
|
||||||
else
|
else
|
||||||
ret+="/-$C2D"
|
ret+="/-$C2D"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$C2A" -gt 0 ]] ; then
|
if [[ "$C2A" -gt 0 ]] ; then
|
||||||
C2A="$LP_MARK_UNTRACKED"
|
C2A="$LP_MARK_UNTRACKED"
|
||||||
else
|
else
|
||||||
C2A=""
|
C2A=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$ret" != "" ]] ; then
|
if [[ "$ret" != "" ]] ; then
|
||||||
ret="(${LP_COLOR_DIFF}$ret${NO_COL})"
|
ret="(${LP_COLOR_DIFF}$ret${NO_COL})"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [[ "$branch" = "no-tag" ]] ; then
|
if [[ "$branch" = "no-tag" ]] ; then
|
||||||
# Warning, your branch has no tag name !
|
# Warning, your branch has no tag name !
|
||||||
branch="${LP_COLOR_COMMITS}$branch${NO_COL}$ret${LP_COLOR_COMMITS}$C2A${NO_COL}"
|
branch="${LP_COLOR_COMMITS}$branch${NO_COL}$ret${LP_COLOR_COMMITS}$C2A${NO_COL}"
|
||||||
else
|
else
|
||||||
if [[ "$C2E" -eq 0 && "$C2D" -eq 0 ]] ; then
|
if [[ "$C2E" -eq 0 && "$C2D" -eq 0 ]] ; then
|
||||||
# All is up-to-date
|
# All is up-to-date
|
||||||
branch="${LP_COLOR_UP}$branch$C2A${NO_COL}"
|
branch="${LP_COLOR_UP}$branch$C2A${NO_COL}"
|
||||||
else
|
else
|
||||||
# There're some changes to commit
|
# There're some changes to commit
|
||||||
branch="${LP_COLOR_CHANGES}$branch${NO_COL}$ret${LP_COLOR_CHANGES}$C2A${NO_COL}"
|
branch="${LP_COLOR_CHANGES}$branch${NO_COL}$ret${LP_COLOR_CHANGES}$C2A${NO_COL}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
echo -ne "$branch"
|
echo $(_lp_escape "$branch")
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -930,10 +939,10 @@ _lp_fossil_branch_color()
|
|||||||
_lp_bzr_branch()
|
_lp_bzr_branch()
|
||||||
{
|
{
|
||||||
[[ "$LP_ENABLE_BZR" != 1 ]] && return
|
[[ "$LP_ENABLE_BZR" != 1 ]] && return
|
||||||
local output
|
local branch
|
||||||
output=$(bzr nick 2> /dev/null)
|
branch=$(bzr nick 2> /dev/null)
|
||||||
[[ $? -ne 0 ]] && return
|
[[ $? -ne 0 ]] && return
|
||||||
echo "$output"
|
echo $(_lp_escape "$branch")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -957,7 +966,7 @@ _lp_bzr_branch_color()
|
|||||||
if [[ "$clean" -eq 0 ]] ; then
|
if [[ "$clean" -eq 0 ]] ; then
|
||||||
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_COMMITS}$revno${NO_COL})"
|
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_COMMITS}$revno${NO_COL})"
|
||||||
else
|
else
|
||||||
ret="${LP_COLOR_UP}${branch}${NO_COL}(${LP_COLOR_COMMITS}$revno${NO_COL})"
|
ret="${LP_COLOR_UP}${branch}${NO_COL}(${LP_COLOR_COMMITS}$revno${NO_COL})"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
@ -1271,7 +1280,7 @@ _lp_set_prompt()
|
|||||||
case "$LP_OS" in
|
case "$LP_OS" in
|
||||||
Linux|FreeBSD|SunOS) $LP_OLD_PROMPT_COMMAND ;;
|
Linux|FreeBSD|SunOS) $LP_OLD_PROMPT_COMMAND ;;
|
||||||
Darwin)
|
Darwin)
|
||||||
case "$(LP_DWIN_KERNEL_REL_VER)" in
|
case "$(LP_DWIN_KERNEL_REL_VER)" in
|
||||||
11|12) update_terminal_cwd ;;
|
11|12) update_terminal_cwd ;;
|
||||||
*) $LP_OLD_PROMPT_COMMAND ;;
|
*) $LP_OLD_PROMPT_COMMAND ;;
|
||||||
esac ;;
|
esac ;;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user