Permalink
Browse files

Made my them display the current rvm gemset and check for detached head

state in git.
  • Loading branch information...
Christopher Chow
Christopher Chow committed Apr 21, 2011
1 parent 971b071 commit eb3d1576bf593c900d0e0fd9465ca3a076779fe0
Showing with 28 additions and 5 deletions.
  1. +28 −5 themes/Soliah.zsh-theme
View
@@ -1,4 +1,4 @@
-PROMPT='%{$fg[blue]%}%n%{$reset_color%} on %{$fg[red]%}%M%{$reset_color%} in %{$fg[blue]%}%~%b%{$reset_color%}$(git_time_since_commit)$(git_prompt_info)
+PROMPT='%{$fg[blue]%}%n%{$reset_color%} on %{$fg[red]%}%M%{$reset_color%} in %{$fg[blue]%}%~%b%{$reset_color%}$(git_time_since_commit)$(check_git_prompt_info)
$ '
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[white]%}"
@@ -16,6 +16,29 @@ ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM="%{$fg[yellow]%}"
ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG="%{$fg[red]%}"
ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[cyan]%}"
+
+# Git sometimes goes into a detached head state. git_prompt_info doesn't
+# return anything in this case. So wrap it in another function and check
+# for an empty string.
+function check_git_prompt_info() {
+ if git rev-parse --git-dir > /dev/null 2>&1; then
+ if [[ -z $(git_prompt_info) ]]; then
+ echo "%{$fg[magenta]%}detached-head%{$reset_color%})"
+ else
+ echo "$(git_prompt_info)"
+ fi
+ fi
+}
+
+# Determine if we are using a gemset.
+function rvm_gemset() {
+ GEMSET=`rvm gemset list | grep '=>' | cut -b4-`
+ if [[ -n $GEMSET ]]; then
+ echo "%{$fg[yellow]%}$GEMSET%{$reset_color%}|"
+ fi
+
+}
+
# Determine the time since last commit. If branch is clean,
# use a neutral color, otherwise colors will vary according to time.
function git_time_since_commit() {
@@ -49,15 +72,15 @@ function git_time_since_commit() {
fi
if [ "$HOURS" -gt 24 ]; then
- echo "($COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
+ echo "($(rvm_gemset)$COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
elif [ "$MINUTES" -gt 60 ]; then
- echo "($COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
+ echo "($(rvm_gemset)$COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
else
- echo "($COLOR${MINUTES}m%{$reset_color%}|"
+ echo "($(rvm_gemset)$COLOR${MINUTES}m%{$reset_color%}|"
fi
else
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
- echo "($COLOR~|"
+ echo "($(rvm_gemset)$COLOR~|"
fi
fi
}

4 comments on commit eb3d157

@nightire

This comment has been minimized.

Show comment Hide comment
@nightire

nightire Sep 1, 2012

Hi, Soliah, I'm using your theme for oh-my-zsh, it's very good for my requirement, thanks for you effort!

But I have only one problem without any idea to fix it, please help me to see:

Whenever I go into a directory with a Git repository, terminal will show this error:

$ awk: i/o error occurred while closing /dev/stdin
input record number 1, file /Users/Albert/.rvm/user/db
source line number 1

then no prompt anymore unless I keep on typing something. It will not to break the normal shell function, but it is too annoy :(

So how I'm suppose to do to get rid of it?

Hi, Soliah, I'm using your theme for oh-my-zsh, it's very good for my requirement, thanks for you effort!

But I have only one problem without any idea to fix it, please help me to see:

Whenever I go into a directory with a Git repository, terminal will show this error:

$ awk: i/o error occurred while closing /dev/stdin
input record number 1, file /Users/Albert/.rvm/user/db
source line number 1

then no prompt anymore unless I keep on typing something. It will not to break the normal shell function, but it is too annoy :(

So how I'm suppose to do to get rid of it?

@Soliah

This comment has been minimized.

Show comment Hide comment
@Soliah

Soliah Sep 1, 2012

Hrm, looks like something is up with rvm. To be honest I haven't used my own theme in awhile, since I migrated to https://github.com/sorin-ionescu/prezto so something may have broken with the newer versions of rvm or git.

I'll see if I can have a look.

Hrm, looks like something is up with rvm. To be honest I haven't used my own theme in awhile, since I migrated to https://github.com/sorin-ionescu/prezto so something may have broken with the newer versions of rvm or git.

I'll see if I can have a look.

@Soliah

This comment has been minimized.

Show comment Hide comment
@Soliah

Soliah Sep 1, 2012

I can't seem to reproduce this with the latest version of rvm. Can you try upgrading rvm: rvm get stable and see if that fixes it?

I can't seem to reproduce this with the latest version of rvm. Can you try upgrading rvm: rvm get stable and see if that fixes it?

@nightire

This comment has been minimized.

Show comment Hide comment
@nightire

nightire Sep 1, 2012

I've already use the newest stable version of rvm, seems like it's not about the rvm.

Thanks for your reply anyway, I'll keep looking for the solution :)

I've already use the newest stable version of rvm, seems like it's not about the rvm.

Thanks for your reply anyway, I'll keep looking for the solution :)

Please sign in to comment.