diff --git a/.gitignore b/.gitignore index 2e8db7341..278852dbd 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ custom/* !custom/example.zsh cache *.swp +.DS_Store \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 000000000..df6411321 --- /dev/null +++ b/Rakefile @@ -0,0 +1,4 @@ +task :setup do + %x(ln -sf ~/.zsh/zshrc ~/.zshrc) + %x(ln -sf ~/.zsh/zshenv ~/.zshenv) +end \ No newline at end of file diff --git a/aliases.zsh b/aliases.zsh new file mode 100644 index 000000000..66c78243a --- /dev/null +++ b/aliases.zsh @@ -0,0 +1,34 @@ +# ls +alias l="ls -FG" +alias ls="ls -FG" +alias la="l -lAh" + +alias e="$EDITOR" + +# git +alias g='git' +alias gp='git push' +alias gd='git diff' +alias gc='git clone' +alias gco='git checkout' +alias gb='git branch' +alias gs='git status -sb' +alias grm="git status | grep deleted | awk '{print \$3}' | xargs git rm" +alias gca='grm; git add .;gs;read;git commit' +alias git-authors='git shortlog -s -n' +# alias changelog='git log `git log -1 --format=%H -- CHANGELOG*`..; cat CHANGELOG*' +# alias gf='git flow' + +# rails +alias r="rails" +alias tlog='tail -f log/development.log' +alias rst='touch tmp/restart.txt' +alias bi="bundle install" +alias bu="bundle update" +alias rake_db_migrate_both="rake db:migrate && rake db:migrate RAILS_ENV=test" + + +# commands starting with % for pasting from web +alias %=' ' + +alias sleepmac="osascript -e 'tell application \"System Events\" to sleep'" diff --git a/completion.zsh b/completion.zsh new file mode 100644 index 000000000..4f22a94ef --- /dev/null +++ b/completion.zsh @@ -0,0 +1,8 @@ +autoload -U compinit +compinit + +# matches case insensitive for lowercase +zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' + +# pasting with tabs doesn't perform completion +zstyle ':completion:*' insert-tab pending diff --git a/config.zsh b/config.zsh new file mode 100644 index 000000000..730ae3264 --- /dev/null +++ b/config.zsh @@ -0,0 +1,76 @@ +# if [[ -n $SSH_CONNECTION ]]; then +# export PS1='%m:%3~$(git_info_for_prompt)%# ' +# else +# export PS1='%3~$(git_info_for_prompt)%# ' +# fi + +if (( ${+commands[mate]} ));then + export EDITOR='mate' +elif (( ${+commands[mvim]} ));then + export EDITOR="mvim" +else + export EDITOR='vim' +fi + +# uncommented since this is system dependent +# export PATH="$HOME/bin:$HOME/.bin:/usr/local/homebrew/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/git/bin:$PATH" +# export MANPATH="/usr/local/man:/usr/local/mysql/man:/usr/local/git/man:$MANPATH" +# +# uncommented since this is system dependent (caused error on configure nginx on my server) +# export CC=gcc-4.2 + +# LANG is required by some programs, like ruby, so ensure that it is set (to UTF) +export LANG=en_US.UTF-8 + +if [[ -e /usr/libexec/java_home ]]; then + export JAVA_HOME="`/usr/libexec/java_home`" +fi + +export IDEA_JDK="$JAVA_HOME" +fpath=(~/.zsh/functions $fpath) + +autoload -U ~/.zsh/functions/*(:t) + +#HISTFILE=~/.zsh_history +#HISTSIZE=1000 +#SAVEHIST=1000 +#REPORTTIME=10 # print elapsed time when more than 10 seconds + +#setopt NO_BG_NICE # don't nice background tasks +#setopt NO_HUP +#setopt NO_LIST_BEEP +#setopt LOCAL_OPTIONS # allow functions to have local options +#setopt LOCAL_TRAPS # allow functions to have local traps +#setopt HIST_VERIFY +## setopt SHARE_HISTORY # share history between sessions ??? +unsetopt EXTENDED_HISTORY # add timestamps to history +#setopt PROMPT_SUBST +#setopt CORRECT +#setopt COMPLETE_IN_WORD +#setopt IGNORE_EOF +#setopt AUTOCD # change to directory without "cd" + +#setopt APPEND_HISTORY # adds history +#setopt INC_APPEND_HISTORY # SHARE_HISTORY # adds history incrementally and share it across sessions +#setopt HIST_IGNORE_ALL_DUPS # don't record dupes in history +#setopt HIST_REDUCE_BLANKS + +#zle -N newtab + +#bindkey '^[^[[D' backward-word +#bindkey '^[^[[C' forward-word +#bindkey '^[[5D' beginning-of-line +#bindkey '^[[5C' end-of-line +#bindkey '^[[3~' delete-char +#bindkey '^[^N' newtab +#bindkey '^?' backward-delete-char +#bindkey '\e[3~' delete-char + +# reverse everything above and set it to default vim key-binding +#bindkey -e +## bindkey '' history-incremental-search-backward +#bindkey '' backward-word +#bindkey '' forward-word + +# ctrl-< and crtrl-> still works +export DISABLE_AUTO_UPDATE=true diff --git a/functions/_c b/functions/_c new file mode 100644 index 000000000..24ca71afa --- /dev/null +++ b/functions/_c @@ -0,0 +1,2 @@ +#compdef c +_files -W ~/code -/ diff --git a/functions/_d b/functions/_d new file mode 100644 index 000000000..9246960c8 --- /dev/null +++ b/functions/_d @@ -0,0 +1,2 @@ +#compdef d +_files -W ~/Dropbox -/ diff --git a/functions/c b/functions/c new file mode 100644 index 000000000..89b6e1f68 --- /dev/null +++ b/functions/c @@ -0,0 +1 @@ +cd ~/code/$1; diff --git a/functions/d b/functions/d new file mode 100644 index 000000000..09b57cefe --- /dev/null +++ b/functions/d @@ -0,0 +1 @@ +cd ~/Dropbox/$1; diff --git a/functions/verbose_completion b/functions/verbose_completion new file mode 100644 index 000000000..8ea12248c --- /dev/null +++ b/functions/verbose_completion @@ -0,0 +1,5 @@ +zstyle ':completion:*' verbose yes +zstyle ':completion:*:descriptions' format '%B%d%b' +zstyle ':completion:*:messages' format '%d' +zstyle ':completion:*:warnings' format 'No matches for: %d' +zstyle ':completion:*' group-name '' diff --git a/git_aliases b/git_aliases new file mode 100644 index 000000000..d3afa6b2f --- /dev/null +++ b/git_aliases @@ -0,0 +1,54 @@ +export git_concise_log_format='--pretty=format:%Cblue%h%d%Creset %ar %Cgreen%an%Creset %s' + +git_current_branch() { + git symbolic-ref HEAD 2> /dev/null | sed -e 's/refs\/heads\///' +} + +alias ga='git add' +alias gap='ga -p' +alias gau='git add -u' +alias gbr='git branch -v' +gc() { + git diff --cached | grep '\btap[ph]\b' >/dev/null && + echo "\e[0;31;29mOops, there's a #tapp or similar in that diff.\e[0m" || + git commit -v "$@" +} +alias gc!='git commit -v' +alias gca='git commit -v -a' +alias gcam='gca --amend' +alias gch='git cherry-pick' +alias gcm='git commit -v --amend' +alias gco='git checkout' +alias gcop='gco -p' +alias gd='git diff -M' +alias gd.='git diff -M --color-words="."' +alias gdc='git diff --cached -M' +alias gdc.='git diff --cached -M --color-words="."' +alias gf='git fetch' +alias glog='git log $git_concise_log_format' +alias gl='glog --graph' +alias gla='gl --all' +alias gl_absolute='git log --pretty=format:"%Cblue%h%d%Creset %ad %Cgreen%an%Creset %s"' +gls() { + query="$1" + shift + glog --pickaxe-regex "-S$query" "$@" +} +alias gm='git merge --no-ff' +alias gmf='git merge --ff-only' +alias gp='git push' +alias gpt='gp --tags' +alias gr='git reset' +alias grb='git rebase -p' +alias grbc='git rebase --continue' +alias grbi='git rebase -i' +alias grh='git reset --hard' +alias grp='gr --patch' +alias grsh='git reset --soft HEAD~' +alias grv='git remote -v' +alias gs='git show' +alias gs.='git show --color-words="."' +alias gst='git stash' +alias gstp='git stash pop' +alias gup='git smart-pull' +alias graf='git remote add $argv[1] $argv[2] && gf $argv[1]' diff --git a/themes/rweng.zsh-theme b/themes/rweng.zsh-theme new file mode 100644 index 000000000..3596054be --- /dev/null +++ b/themes/rweng.zsh-theme @@ -0,0 +1,71 @@ +# ZSH_THEME_GIT_PROMPT_PREFIX=" %{$fg[green]%}" +# ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[cyan]%}[" + +ZSH_THEME_GIT_PROMPT_PREFIX="" +ZSH_THEME_GIT_PROMPT_SUFFIX="]" # "]%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_DIRTY="*" +ZSH_THEME_GIT_PROMPT_CLEAN="" + +function prompt_char { + if [ $UID -eq 0 ]; then echo "%{$fg[red]%}#%{$reset_color%}"; else echo "%{$fg[red]%}⚡"; fi +} + +PROMPT='%(?, ,%{$fg[red]%}FAILED WITH CODE: $?%{$reset_color%} +) +%{$fg[blue]%}%~%{$reset_color%}$(git_time_since_commit)$(git_prompt_info) +%_$(prompt_char) ' + +RPROMPT='%{$fg[blue]%}%n%{$reset_color%}@%{$fg[cyan]%}%m%{$reset_color%}' + + +# 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]%}" + +# 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 60 ]; then + COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG" + elif [ "$MINUTES" -gt 30 ]; 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|" + elif [ "$MINUTES" -gt 60 ]; then + echo "${COLOR}[${HOURS}h${SUB_MINUTES}m|" + else + echo "${COLOR}[${MINUTES}m|" + fi + else + COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL" + echo "${COLOR}[~|" + fi + fi +} diff --git a/zshenv b/zshenv new file mode 100755 index 000000000..73725a005 --- /dev/null +++ b/zshenv @@ -0,0 +1 @@ +eval "$(rbenv init -)" \ No newline at end of file diff --git a/zshrc b/zshrc new file mode 100755 index 000000000..9ee6b158a --- /dev/null +++ b/zshrc @@ -0,0 +1,48 @@ +# source global profile if exists. This is important, since in /etc/profile the /etc/profile.d/* files are sourced. +# These usually contain additional path variables and other global settings +# on the other hand, when I source this the path i set in zshenv seems to be overriden +# [[ -f /etc/profile ]] && . /etc/profile + +# Path to your oh-my-zsh configuration. +ZSH=$HOME/.zsh + +# Set name of the theme to load. +# 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="rweng" + +# Set to this to use case-sensitive completion +# CASE_SENSITIVE="true" + +# Comment this out to disable weekly auto-update checks +DISABLE_AUTO_UPDATE="true" + +# Uncomment following line if you want to disable colors in ls +# DISABLE_LS_COLORS="true" + +# Uncomment following line if you want to disable autosetting terminal title. +# DISABLE_AUTO_TITLE="true" + +# Uncomment following line if you want disable red dots displayed while waiting for completion +# DISABLE_COMPLETION_WAITING_DOTS="true" + +# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*) +# Example format: plugins=(rails git textmate ruby lighthouse) +plugins=(git rails ruby brew bundler cap gem github osx pow powder rails3 rvm vagrant) + +source $ZSH/oh-my-zsh.sh + +# Customize to your needs... +alias h="dirs -v" +unalias d + +RWZSH=$HOME/.zsh +. $ZSH/config.zsh +. $ZSH/aliases.zsh +. $ZSH/completion.zsh + +# use .localrc for settings specific to one system +if [[ -f ~/.localrc ]]; then + . ~/.localrc +fi