Created
May 26, 2013 12:23
-
-
Save cyrildiagne/5652645 to your computer and use it in GitHub Desktop.
My .zshrc
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
# DESCRIPTION: | |
# A simple zsh configuration that gives you 90% of the useful features that I use everyday. | |
# | |
# AUTHOR: | |
# Geoffrey Grosenbach http://peepcode.com | |
############ | |
# FUNCTIONS | |
############ | |
# 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 [[ -n $(git status -s 2> /dev/null) ]]; then | |
if [ "$MINUTES" -gt 30 ]; then | |
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG" | |
elif [ "$MINUTES" -gt 10 ]; then | |
COLOR="$ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM" | |
else | |
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT" | |
fi | |
else | |
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL" | |
fi | |
if [ "$HOURS" -gt 24 ]; then | |
echo "$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%} " | |
else | |
echo "$COLOR${MINUTES}m%{$reset_color%} " | |
fi | |
else | |
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL" | |
echo "" | |
fi | |
fi | |
} | |
function prompt_char { | |
git branch >/dev/null 2>/dev/null && echo '[±] ' && return | |
hg root >/dev/null 2>/dev/null && echo '[☿] ' && return | |
echo '' | |
} | |
# mkdir & cd to it | |
function mcd() { | |
mkdir -p "$1" && cd "$1"; | |
} | |
# gitdir : mkdir, cd to it, init git, create initial empty commit | |
function gitdir() { | |
mkdir -p "$1" && cd "$1" && git init && git commit --allow-empty -m 'initial commit'; | |
} | |
# gco : pull before committing new changes (fail early fail often) | |
function gco() { | |
git pull && git commit -m $1 | |
} | |
######### | |
# COLORS | |
######### | |
autoload -U colors | |
colors | |
setopt prompt_subst | |
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[white]%}" | |
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%})" | |
# Text to display if the branch is dirty | |
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%} *%{$reset_color%}" | |
# Text to display if the branch is clean | |
ZSH_THEME_GIT_PROMPT_CLEAN="" | |
# 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[cyan]%}" | |
######### | |
# PROMPT | |
######### | |
# Current path color depending on last command exit status | |
local current_path="%(?,%{$fg[green]%}%~%{$reset_color%},%{$fg[red]%}%~%{$reset_color%})" | |
PROMPT=' | |
${current_path} | |
%{$fg[white]%}$(prompt_char)%{$fg[white]%}$(git_time_since_commit)> %{$reset_color%}' | |
RPROMPT='%{$fg[white]%} $(~/.rvm/bin/rvm-prompt)$(~/bin/git-cwd-info.rb)%{$reset_color%}' | |
############################################################################## | |
# History Configuration | |
############################################################################## | |
HISTSIZE=5000 #How many lines of history to keep in memory | |
HISTFILE=~/.zsh_history #Where to save history to disk | |
SAVEHIST=5000 #Number of history entries to save to disk | |
#HISTDUP=erase #Erase duplicates in the history file | |
setopt appendhistory #Append history to the history file (no overwriting) | |
setopt sharehistory #Share history across terminals | |
setopt incappendhistory #Immediately append to the history file, not just when a term is killed | |
############# | |
# COMPLETION | |
############# | |
# Show completion on first TAB | |
setopt menucomplete | |
# load autocompletion | |
autoload -U compinit && compinit | |
# enable cache | |
zstyle ':completion:*' use-cache on | |
zstyle ':completion:*' cache-path ~/.zsh/cache | |
# ignore completion to commands we don't have | |
zstyle ':completion:*:functions' ignored-patterns '_*' | |
# format autocompletion style | |
zstyle ':completion:*:descriptions' format "%{$fg_bold[green]%}%d%{$reset_color%}" | |
zstyle ':completion:*:corrections' format "%{$fg_bold[yellow]%}%d%{$reset_color%}" | |
zstyle ':completion:*:messages' format "%{$fg_bold[red]%}%d%{$reset_color%}" | |
zstyle ':completion:*:warnings' format "%{$fg_bold[red]%}%d%{$reset_color%}" | |
# zstyle show completion menu if 2 or more items to select | |
zstyle ':completion:*' menu select=2 | |
# zstyle kill menu | |
zstyle ':completion:*:*:kill:*' menu yes select | |
zstyle ':completion:*:kill:*' force-list always | |
zstyle ':completion:*:*:kill:*:processes' list-colors "=(#b) #([0-9]#)*=36=31" | |
# enable color completion | |
zstyle ':completion:*:default' list-colors "=(#b) #([0-9]#)*=$color[yellow]=$color[red]" | |
# fuzzy matching of completions for when we mistype them | |
zstyle ':completion:*' completer _complete _match _approximate | |
zstyle ':completion:*:match:*' original only | |
# number of errors allowed by _approximate increase with the length of what we have typed so far | |
zstyle -e ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)' | |
########## | |
# ALIASES | |
########## | |
alias ls="ls -lahG" | |
# Git aliases | |
alias gplod="git pull origin development" | |
alias gplom="git pull origin master" | |
alias gpsod="git push origin development" | |
alias gpsom="git push origin master" | |
alias mate="subl" | |
####### | |
# PATH | |
####### | |
# Add RVM to PATH for scripting | |
export PATH=/usr/local/bin:$PATH:$HOME/bin:$HOME/.rvm/bin | |
###### | |
# PATH | |
####### | |
### Add Blender | |
export PATH="/Applications/Blender/blender.app/Contents/MacOS:$PATH" | |
### Add Android SDK | |
export PATH=${PATH}:~/Dev/android/sdk/platform-tools:~/Dev/android/sdk/tools | |
### Flex SDK | |
export PATH="/Users/kikko/Dev/flash/flex_sdk_4.6/bin:$PATH" | |
### Added by the Heroku Toolbelt | |
export PATH="/usr/local/heroku/bin:$PATH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment