Prompt fixes in zsh.

This commit is contained in:
2014-04-08 11:00:25 -07:00
parent cfc5cdbb6f
commit d8d47433d0
8 changed files with 51 additions and 47 deletions

View File

@@ -0,0 +1,3 @@
for filename in ~/.lib/bash/*; do
source $filename
done

View File

@@ -0,0 +1,15 @@
function current_directory() {
local PWD=$(pwd)
echo "${PWD/#$HOME/~}"
}
function git_prompt_info () {
if test -z $(parse_git_branch);
then
echo ""
else
echo "on $(parse_git_branch)"
fi
}
PS1='%u at $(hostname -s) in $(current_directory) $(git_prompt_info) $(colored_sandbox_string) '

View File

@@ -35,6 +35,8 @@ command -v md5sum > /dev/null || alias md5sum="md5"
# OS X has no `sha1sum`, so use `shasum` as a fallback
command -v sha1sum > /dev/null || alias sha1sum="shasum"
command -v greadlink > /dev/null && alias readlink="greadlink"
# URL-encode strings
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"'

View File

@@ -4,8 +4,12 @@ function parse_git_branch() {
echo ${ref#refs/heads/}
}
function git_is_dirty() {
git diff-index --quiet --cached HEAD && git diff-files --quiet
}
function current_shell() {
ps -p $$ | tail -1 | awk '{print $NF}' | xargs which | xargs readlink -f
greadlink -f $(which "$(ps -p $$ | tail -1 | awk '{print $NF}' | sed 's/\-//')")
}
function is_zsh() {

View File

@@ -51,7 +51,8 @@ function sandbox_prompt_info() {
if [ "$YELP_IN_SANDBOX" ];
then
sandbox_string=$sandbox_string"sandbox-$(get_sandbox_identifier)"
else
elif [ ! -z $(env | grep YELP) ];
then
sandbox_string="no sandbox"
fi
echo $sandbox_string
@@ -77,11 +78,11 @@ function zsh_sandbox_color() {
}
function colored_sandbox_string() {
if [ is_zsh ]
if [ is_zsh ];
then
sandbox_color=$(zsh_sandbox_color)
else
sandbox_color=$(bash_sandbox_color)
fi
echo $sandbox_color$(sandbox_prompt_info)
echo "$sandbox_color$(sandbox_prompt_info)%{$reset_color%}"
}

View File

@@ -3,16 +3,33 @@ function current_directory() {
echo "${PWD/#$HOME/~}"
}
function git_prompt_info () {
function git_prompt_info() {
if test -z $(parse_git_branch);
then
echo ""
else
echo " %{$FG[239]%}on%{$reset_color%} %{$FG[255]%}$(parse_git_branch)%{$reset_color%}"
echo " %{$FG[239]%}on%{$reset_color%} %{$FG[255]%}$(parse_git_branch)%{$reset_color%}$(git_status_character)"
fi
}
PROMPT='%{$FG[040]%}%n%{$reset_color%} %{$FG[239]%}at%{$reset_color%} %{$FG[033]%}$(hostname -s)%{$reset_color%} %{$FG[239]%}in%{$reset_color%} %{$terminfo[bold]$FG[226]%}$(current_directory)%{$reset_color%}$(git_prompt_info) %{$FG[239]%}with $(colored_sandbox_string)%{$FG[255]%}%{$reset_color%} '
function git_status_character() {
if git_is_dirty;
then
echo "%{$FG[202]%}✘%{$reset_color%}"
else
echo "%{$FG[040]%}✔%{$reset_color%}"
fi
}
function sandbox_prompt() {
if [ ! -z $(sandbox_prompt_info) ];
then
echo " %{$FG[239]%}with $(colored_sandbox_string)%{$reset_color%}"
fi
}
PROMPT='╭─% %{$FG[040]%}%n%{$reset_color%} %{$FG[239]%}at%{$reset_color%} %{$FG[033]%}$(hostname -s)%{$reset_color%} %{$FG[239]%}in%{$reset_color%} %{$terminfo[bold]$FG[226]%}$(current_directory)%{$reset_color%}$(git_prompt_info)$(sandbox_prompt)
$FG[255]╰─± '
PS2=''