Created
December 15, 2014 22:38
-
-
Save prabhakhar/6342370f6791fb0549d2 to your computer and use it in GitHub Desktop.
zsh Prompt
This file contains 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
autoload colors && colors | |
# cheers, @ehrenmurdick | |
# http://github.com/ehrenmurdick/config/blob/master/zsh/prompt.zsh | |
if (( $+commands[git] )) | |
then | |
git="$commands[git]" | |
else | |
git="/usr/bin/git" | |
fi | |
venv_name() { | |
echo "`basename \"$VIRTUAL_ENV\"`" | |
} | |
venv() { | |
if [[ -n $VIRTUAL_ENV ]] | |
then | |
echo "%{$fg_bold[yellow]%}($(venv_name))%{$reset_color%}" | |
else | |
echo "" | |
fi | |
} | |
git_branch() { | |
echo $($git symbolic-ref HEAD 2>/dev/null | awk -F/ {'print $NF'}) | |
} | |
git_dirty() { | |
if $(! $git status -s &> /dev/null) | |
then | |
echo "" | |
else | |
if [[ $($git status --porcelain) == "" ]] | |
then | |
echo "on %{$fg_bold[green]%}$(git_prompt_info)%{$reset_color%}" | |
else | |
echo "on %{$fg_bold[red]%}$(git_prompt_info)%{$reset_color%}" | |
fi | |
fi | |
} | |
git_prompt_info () { | |
ref=$($git symbolic-ref HEAD 2>/dev/null) || return | |
# echo "(%{\e[0;33m%}${ref#refs/heads/}%{\e[0m%})" | |
echo "${ref#refs/heads/}" | |
} | |
unpushed () { | |
$git cherry -v @{upstream} 2>/dev/null | |
} | |
need_push () { | |
if [[ $(unpushed) == "" ]] | |
then | |
echo " " | |
else | |
echo " with %{$fg_bold[magenta]%}unpushed%{$reset_color%} " | |
fi | |
} | |
ruby_version() { | |
if (( $+commands[rbenv] )) | |
then | |
echo "$(rbenv version | awk '{print $1}')" | |
fi | |
if (( $+commands[rvm-prompt] )) | |
then | |
echo "$(rvm-prompt | awk '{print $1}')" | |
fi | |
} | |
rb_prompt() { | |
if ! [[ -z "$(ruby_version)" ]] | |
then | |
echo "%{$fg_bold[yellow]%}$(ruby_version)%{$reset_color%} " | |
else | |
echo "" | |
fi | |
} | |
directory_name() { | |
echo "%{$fg_bold[cyan]%}%1/%\/%{$reset_color%}" | |
} | |
export PROMPT=$'\n$(rb_prompt)in $(directory_name) $(git_dirty)$(need_push)$(venv)\n› ' | |
set_prompt () { | |
export RPROMPT="%{$fg_bold[cyan]%}%{$reset_color%}" | |
} | |
precmd() { | |
title "zsh" "%m" "%55<...<%~" | |
set_prompt | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment