From 9e441a9700046519e8e798f8606bdabf002e8a62 Mon Sep 17 00:00:00 2001 From: Andrew Vit Date: Sun, 6 Nov 2011 03:50:57 -0800 Subject: [PATCH 1/4] Accept alternate install paths via ZSH variable --- README.textile | 4 +++- templates/zshrc.zsh-template | 21 +++++++++++++++++++-- tools/install.sh | 23 ++++++++++++++++++----- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/README.textile b/README.textile index 2dbfbe5a6..2686dc078 100644 --- a/README.textile +++ b/README.textile @@ -8,7 +8,9 @@ h2. Setup h3. The automatic installer... (do you trust me?) -@wget --no-check-certificate https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh@ +@wget --no-check-certificate https://github.com/avit/oh-my-zsh/raw/master/tools/install.sh -O - | ZSH=~/.oh-my-zsh sh@ + +You can adjust the install destination by changing the ZSH variable. The default location is `~/.oh-my-zsh` (but I like to keep these things together under my .dotfiles, for example.) h3. The manual way diff --git a/templates/zshrc.zsh-template b/templates/zshrc.zsh-template index 1ab40aba6..f26a47022 100644 --- a/templates/zshrc.zsh-template +++ b/templates/zshrc.zsh-template @@ -5,7 +5,7 @@ ZSH=$HOME/.oh-my-zsh # Look in ~/.oh-my-zsh/themes/ # Optionally, if you set this to "random", it'll load a random theme each # time that oh-my-zsh is loaded. -ZSH_THEME="robbyrussell" +ZSH_THEME="avit" # Set to this to use case-sensitive completion # CASE_SENSITIVE="true" @@ -28,4 +28,21 @@ plugins=(git) source $ZSH/oh-my-zsh.sh -# Customize to your needs... +# User configuration + +# export PATH=$HOME/bin:/usr/local/bin:$PATH +# export MANPATH="/usr/local/man:$MANPATH" + +# # Preferred editor for local and remote sessions +# if [[ -n $SSH_CONNECTION ]]; then +# export EDITOR='vim' +# else +# export EDITOR='mvim' +# fi + +# Compilation flags +# export ARCHFLAGS="-arch x86_64" + +# ssh +# export SSH_KEY_PATH="~/.ssh/dsa_id" + diff --git a/tools/install.sh b/tools/install.sh index aedb706da..6ecb4e861 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -1,11 +1,18 @@ -if [ -d ~/.oh-my-zsh ] +set -e + +if [ ! -n $ZSH ] then - echo "\033[0;33mYou already have Oh My Zsh installed.\033[0m You'll need to remove ~/.oh-my-zsh if you want to install" + ZSH=~/.oh-my-zsh +fi + +if [ -d $ZSH ] +then + echo "\033[0;33mYou already have Oh My Zsh installed.\033[0m You'll need to remove $ZSH if you want to install" exit fi echo "\033[0;34mCloning Oh My Zsh...\033[0m" -/usr/bin/env git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh +/usr/bin/env git clone https://github.com/avit/oh-my-zsh.git $ZSH echo "\033[0;34mLooking for an existing zsh config...\033[0m" if [ -f ~/.zshrc ] || [ -h ~/.zshrc ] @@ -16,10 +23,15 @@ then fi echo "\033[0;34mUsing the Oh My Zsh template file and adding it to ~/.zshrc\033[0m" -cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc +cp $ZSH/templates/zshrc.zsh-template ~/.zshrc +sed -i -e "/^ZSH=/ c\\ +ZSH=$ZSH +" ~/.zshrc echo "\033[0;34mCopying your current PATH and adding it to the end of ~/.zshrc for you.\033[0m" -echo "export PATH=$PATH" >> ~/.zshrc +sed -i -e "/export PATH=/ c\\ +export PATH=\"$PATH\" +" ~/.zshrc echo "\033[0;34mTime to change your default shell to zsh!\033[0m" chsh -s `which zsh` @@ -32,5 +44,6 @@ echo "\033[0;32m"'\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ '"\033[0m echo "\033[0;32m"' /____/ '"\033[0m" echo "\n\n \033[0;32m....is now installed.\033[0m" +echo "\n\n \033[0;32mPlease look over the ~/.zshrc file to select plugins, themes, and options.\033[0m" /usr/bin/env zsh source ~/.zshrc From a22cea19fdde1d5e2a5d88a48d6cb09bd90948f0 Mon Sep 17 00:00:00 2001 From: Andrew Vit Date: Sun, 6 Nov 2011 04:07:16 -0800 Subject: [PATCH 2/4] Added avit theme --- themes/avit.zsh-theme | 120 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 themes/avit.zsh-theme diff --git a/themes/avit.zsh-theme b/themes/avit.zsh-theme new file mode 100644 index 000000000..51f5e375a --- /dev/null +++ b/themes/avit.zsh-theme @@ -0,0 +1,120 @@ +# +# Author:: Andrew Vit () +# +# AVIT ZSH Theme +# +# Copyright 2011, Andrew Vit +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +PROMPT=' +$(_user_host)${_current_dir} $(git_prompt_info) $(_ruby_version) +▶ ' + +PROMPT2='%{$fg[grey]%}◀%{$reset_color%} ' + +RPROMPT='$(_vi_status)%{$(echotc UP 1)%}$(_git_time_since_commit) $(git_prompt_status) ${_return_status}%{$(echotc DO 1)%}' + +local _current_dir="%{$fg[blue]%}%3~%{$reset_color%} " +local _return_status="%{$fg[red]%}%(?..⍉)%{$reset_color%}" +local _hist_no="%{$fg[grey]%}%h%{$reset_color%}" + +function _user_host() { + if [[ -n $SSH_CONNECTION ]]; then + me="%n@%m" + elif [[ $LOGNAME != $USER ]]; then + me="%n" + fi + if [[ -n $me ]]; then + echo "%{$fg[cyan]%}$me%{$reset_color%}:" + fi +} + +function _vi_status() { + if {echo $fpath | grep -q "plugins/vi-mode"}; then + echo "$(vi_mode_prompt_info)" + fi +} + +function _ruby_version() { + if {echo $fpath | grep -q "plugins/rvm"}; then + echo "%{$fg[grey]%}$(rvm_prompt_info)%{$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() { + if git rev-parse --git-dir > /dev/null 2>&1; then + # Only proceed if there is actually a commit. + if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then + # Get the last commit. + last_commit=$(git log --pretty=format:'%at' -1 2> /dev/null) + now=$(date +%s) + seconds_since_last_commit=$((now-last_commit)) + + # Totals + minutes=$((seconds_since_last_commit / 60)) + hours=$((seconds_since_last_commit/3600)) + + # Sub-hours and sub-minutes + days=$((seconds_since_last_commit / 86400)) + sub_hours=$((hours % 24)) + sub_minutes=$((minutes % 60)) + + if [ $hours -gt 24 ]; then + commit_age="${days}d" + elif [ $minutes -gt 60 ]; then + commit_age="${sub_hours}h${sub_minutes}m" + else + commit_age="${minutes}m" + fi + + color=$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL + echo "$color$commit_age%{$reset_color%}" + fi + fi +} + +if [[ $USER == "root" ]]; then + CARETCOLOR="red" +else + CARETCOLOR="white" +fi + +MODE_INDICATOR="%{$fg_bold[yellow]%}❮%{$reset_color%}%{$fg[yellow]%}❮❮%{$reset_color%}" + +ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}" +ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" + +ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}✗%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_CLEAN=" %{$fg[green]%}✔%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[green]%}✚ " +ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[yellow]%}⚑ " +ZSH_THEME_GIT_PROMPT_DELETED="%{$fg[red]%}✖ " +ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[blue]%}▴ " +ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[cyan]%}§ " +ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[grey]%}◒ " + +# Colors vary depending on time lapsed. +ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}" +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[grey]%}" + +# LS colors, made with http://geoff.greer.fm/lscolors/ +export LSCOLORS="exfxcxdxbxegedabagacad" +export LS_COLORS='di=34;40:ln=35;40:so=32;40:pi=33;40:ex=31;40:bd=34;46:cd=34;43:su=0;41:sg=0;46:tw=0;42:ow=0;43:' +export GREP_COLOR='1;33' + From 73b5cffb863c8fe34a5a0299baa515641ac27610 Mon Sep 17 00:00:00 2001 From: Andrew Vit Date: Sun, 6 Nov 2011 04:24:33 -0800 Subject: [PATCH 3/4] Bwana plugin for reading man pages in Safari --- plugins/bwana/bwana.plugin.zsh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 plugins/bwana/bwana.plugin.zsh diff --git a/plugins/bwana/bwana.plugin.zsh b/plugins/bwana/bwana.plugin.zsh new file mode 100644 index 000000000..455da8621 --- /dev/null +++ b/plugins/bwana/bwana.plugin.zsh @@ -0,0 +1,13 @@ +# +# Requires http://www.bruji.com/bwana/ +# +if [[ -e /Applications/Bwana.app ]] || + ( system_profiler -detailLevel mini SPApplicationsDataType | grep -q Bwana ) +then + function man() { + open "man:$1" + } +else + echo "Bwana lets you read man files in Safari through a man: URI scheme" + echo "To use it within Zsh, install it from http://www.bruji.com/bwana/" +fi From ebe3f9b204adfae2e51e77eb126430e2d0e8cfdd Mon Sep 17 00:00:00 2001 From: Andrew Vit Date: Wed, 9 Nov 2011 16:58:45 -0800 Subject: [PATCH 4/4] Allow (re)installing from local repo --- tools/install.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tools/install.sh b/tools/install.sh index 6ecb4e861..998bf5163 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -5,15 +5,12 @@ then ZSH=~/.oh-my-zsh fi -if [ -d $ZSH ] +if [ ! -d $ZSH ] then - echo "\033[0;33mYou already have Oh My Zsh installed.\033[0m You'll need to remove $ZSH if you want to install" - exit + echo "\033[0;34mCloning Oh My Zsh...\033[0m" + /usr/bin/env git clone https://github.com/avit/oh-my-zsh.git $ZSH fi -echo "\033[0;34mCloning Oh My Zsh...\033[0m" -/usr/bin/env git clone https://github.com/avit/oh-my-zsh.git $ZSH - echo "\033[0;34mLooking for an existing zsh config...\033[0m" if [ -f ~/.zshrc ] || [ -h ~/.zshrc ] then