Created
December 6, 2012 04:03
-
-
Save yyuu/4221688 to your computer and use it in GitHub Desktop.
pseudo vcs_info() for ancient zsh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setopt prompt_subst | |
autoload -Uz add-zsh-hook | |
autoload -Uz vcs_info | |
## display scm info in the prompt | |
if vcs_info 1>/dev/null 2>&1; then | |
zstyle ':vcs_info:*' formats '%b' | |
precmd_vcs_info() { | |
LANG=C vcs_info | |
} | |
else | |
precmd_vcs_info() { | |
unset -v vcs_info_msg_0_ | |
local dir=$(pwd) | |
while [ -z "${vcs_info_msg_0_}" ] && [ "${dir}" != "/" ]; do | |
if test -d "${dir}/.hg"; then | |
vcs_info_msg_0_=$(cd ${dir}; hg branch) | |
elif test -d "${dir}/.git"; then | |
vcs_info_msg_0_=$(cd ${dir}; git name-rev --name-only $(cd ${dir}; git rev-parse HEAD)) | |
elif test -d "${dir}/.svn"; then | |
vcs_info_msg_0_=$(cd ${dir}; svnversion) | |
fi | |
local dir=$(cd "${dir}/.."; pwd) | |
done | |
} | |
fi | |
add-zsh-hook precmd precmd_vcs_info | |
export PROMPT='[%n@%m:%~(${vcs_info_msg_0_:--})]%% ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment