Permalink
Browse files

Add a slightly modified version of @bjeanes prompt_pwd function

  • Loading branch information...
1 parent 689ad4e commit 206ddff8a045dde5982500c558c25a2eca3f11e2 @twe4ked committed Apr 7, 2013
Showing with 29 additions and 1 deletion.
  1. +0 −1 freshrc
  2. +29 −0 zsh/prompt.zsh
View
@@ -15,7 +15,6 @@ fresh henrik/dotfiles rubyrc --file=~/.pryrc --filter='cat; echo include RubyRC'
# Zsh
fresh-options --file=~/.zshrc --marker
fresh zsh/completion.zsh
- fresh bjeanes/dot-files shells/zsh/lib/prompt.zsh --ref=f48931f --filter='sed -n 28,53p'
fresh zsh/prompt.zsh
fresh zsh/title.zsh
fresh zsh/aliases.zsh
View
@@ -32,6 +32,35 @@ git_stash() {
git stash list 2> /dev/null | wc -l | sed -e "s/ *\([0-9]*\)/\ \+\1/g" | sed -e "s/ \+0//"
}
+function prompt_pwd() {
+ if [ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1; then
+ local repo="$(basename "$(git rev-parse --show-toplevel)")"
+ fi
+
+ parts=(${(s:/:)${${PWD}/#${HOME}/\~}})
+
+ i=0
+ while (( i++ < ${#parts} )); do
+ part="$parts[i]"
+ if [[ "$part" == "$repo" ]]; then
+ # if this part of the path represents the repo,
+ # underline it, and skip truncating the component
+ parts[i]="%U$part%u"
+ else
+ # shorten the path as long as it isn't the last piece
+ if [[ "$parts[${#parts}]" != "$part" ]]; then
+ parts[i]="$part[1,1]"
+ fi
+ fi
+ done
+
+ local prompt_path="${(j:/:)parts}"
+ if [ "$parts[1]" != "~" ]; then
+ prompt_path="/$prompt_path"
+ fi
+ echo "$prompt_path"
+}
+
local git_formats="%{${fg_bold[yellow]}%}± %b%c%u:%.7i%{${reset_color}%}"
zstyle ':vcs_info:git*' enable git
zstyle ':vcs_info:git*' check-for-changes true

4 comments on commit 206ddff

Oh man... you aren't using vcs_info_msg_1_? It means supporting SVN, Hg, etc...

Owner

twe4ked replied Apr 7, 2013

I don't have vcs_info_msg_1_ set up. I've never used another VCS (thankfully).

It also saves a shell out and iirc is faster. Just set up vcs info it's amazing. On your line 65-66 you already do half the work!

Owner

twe4ked replied Apr 7, 2013

Good idea, will do. Once freshshell/fresh#47 is done I'll source it from you again. I want to be able to give someone my prompt in a single file though.

Please sign in to comment.