aboutsummaryrefslogtreecommitdiffstats
path: root/_zsh
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2017-03-19 09:47:59 +0800
committerAaron LI <aaronly.me@outlook.com>2017-03-19 09:47:59 +0800
commit9fee8ed6e79decd9481cde6540e1575b3ba1e9ed (patch)
tree4e8f0c42efacc37f8cf379eaf656a57a63076c43 /_zsh
parentce57cdeb9977b9d4d02faada22b62b53c3fb276a (diff)
downloaddotfiles-9fee8ed6e79decd9481cde6540e1575b3ba1e9ed.tar.bz2
zsh: Use prompt from 'http://chneukirchen.org/dotfiles/.zshrc'
Diffstat (limited to '_zsh')
-rw-r--r--_zsh/30-prompt.zsh57
1 files changed, 39 insertions, 18 deletions
diff --git a/_zsh/30-prompt.zsh b/_zsh/30-prompt.zsh
index 3d439c7..d1c70c2 100644
--- a/_zsh/30-prompt.zsh
+++ b/_zsh/30-prompt.zsh
@@ -1,32 +1,53 @@
#
# zsh/prompt.zsh
#
+# Credit: http://chneukirchen.org/dotfiles/.zshrc
+#
+
-function git_prompt_info {
- local ref=$(=git symbolic-ref HEAD 2> /dev/null)
- local gitst="$(=git status --untracked-files=no 2> /dev/null)"
+# gitpwd - print %~, limited to $NDIR segments, with inline git branch
+NDIRS=3
+function gitpwd() {
+ local -a segs splitprefix
+ local prefix branch
+ segs=("${(Oas:/:)${(D)PWD}}")
+ segs=("${(@)segs/(#b)(?(#c10))??*(?(#c5))/${(j:\u2026:)match}}")
- if [[ -f .git/MERGE_HEAD ]]; then
- if [[ ${gitst} =~ "unmerged" ]]; then
- gitstatus=" %{$fg[red]%}unmerged%{$reset_color%}"
+ if gitprefix=$(git rev-parse --show-prefix 2>/dev/null); then
+ splitprefix=("${(s:/:)gitprefix}")
+ if ! branch=$(git symbolic-ref -q --short HEAD); then
+ branch=$(git name-rev --name-only HEAD 2>/dev/null)
+ [[ $branch = *\~* ]] || branch+="~0" # distinguish detached HEAD
+ fi
+ if (( $#splitprefix > NDIRS )); then
+ print -n "${segs[$#splitprefix]}@$branch "
else
- gitstatus=" %{$fg[green]%}merged%{$reset_color%}"
+ segs[$#splitprefix]+=@$branch
fi
- elif [[ ${gitst} =~ "Changes to be committed" ]]; then
- gitstatus=" %{$fg[blue]%}!%{$reset_color%}"
- elif [[ ${gitst} =~ "use \"git add" ]]; then
- gitstatus=" %{$fg[red]%}!%{$reset_color%}"
- else
- gitstatus=''
fi
- if [[ -n $ref ]]; then
- echo "%{$fg_bold[green]%}/${ref#refs/heads/}%{$reset_color%}$gitstatus"
- fi
+ (( $#segs == NDIRS+1 )) && [[ $segs[-1] == "" ]] && print -n /
+ print "${(j:/:)${(@Oa)segs[1,NDIRS]}}"
}
-PROMPT='%{$fg_bold[blue]%}%~%<< $(git_prompt_info)%{$fg_bold[red]%}%(?..[%?])${PR_BOLD_WHITE}>%{$reset_color%} '
-SPROMPT="zsh: correct %{$fg_bold[red]%}%R%{$reset_color%} to %{$fg_bold[green]%}%r%{$reset_color%} [(y)es (n)o (a)bort (e)dit]? "
+function myprompt() {
+ case "$TERM" in
+ xterm*|rxvt*)
+ precmd() { [[ -t 1 ]] && print -Pn "\e]0;%m: %~\a" }
+ preexec() { [[ -t 1 ]] && print -n "\e]0;$HOST: ${(q)1//(#m)[$'\000-\037\177-']/${(q)MATCH}}\a" }
+ esac
+ setopt PROMPT_SUBST
+ nbsp=$'\u00A0'
+ PROMPT='%B%F{green}%m%(?.. %F{red}%??)%(1j. %F{yellow}%j&.)%b%f $(gitpwd)%B%(!.%F{red}.%F{green})%#${SSH_CONNECTION:+%#}$nbsp%b%f'
+ RPROMPT=''
+ # Prompt for spelling correction
+ SPROMPT='zsh: correct %B%F{red}%R%b%f to %B%F{green}%r%b%f [(y)es (n)o (a)bort (e)dit]? '
+}
+
+
+# Setup prompts
+myprompt
+
# vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: #