diff --git a/.gitignore b/.gitignore index 8bb8c59..5f484d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -.DS_Store +custom/zsh + vim/backups vim/view *un~ diff --git a/README.md b/README.md index 873c68f..508967b 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,21 @@ mnemonic aliases. Please feel free to edit them: * Bash style ctrl-R for reverse history finder * Fuzzy matching - if you mistype a directory name, tab completion will fix it +### How To Customize ZSH + +YADR allows you to completely customize your ZSH without having to fork and maintain the project. Here's how it works: YADR will +source (include) any files matching the pattern `*.before.zsh` or `*.after.zsh` in the `custom/zsh` directory. `before` files are +useful for setting the theme and plugins. `after` files allow you to override options set by YADR, define your own aliases, etc. + +To make your life easier, create a `zsh` folder in your Dropbox (or as a git repo) and symlink it into `~/.yadr/custom`. Do it like this: + +```bash +ln -s ~/Dropbox/path/to/zsh ~/.yadr/custom/zsh +``` + +Create as many `whatever.before.zsh` or `whatever.after.zsh` files as you need within the `zsh` directory. Please see `custom/zsh.sample` for +an example. + ## Pry diff --git a/custom/zsh.sample/after.sample.zsh b/custom/zsh.sample/after.sample.zsh new file mode 100644 index 0000000..a3a8078 --- /dev/null +++ b/custom/zsh.sample/after.sample.zsh @@ -0,0 +1,20 @@ +# +# Samples of what you can do in *.after.zsh files. +# You can create as many files as you like, or put everything in one. +# + +# define your own aliases or override those provided by YADR. +alias ls='ls -lAhFG' +alias hosts='sudo vim /private/etc/hosts' + + +# set or override options. two of my favorite are below. + + +# Automatically cd to frequently used directories http://robots.thoughtbot.com/post/10849086566/cding-to-frequently-used-directories-in-zsh +setopt auto_cd +cdpath=($HOME/Dropbox/code) + +# Fancy globbing http://linuxshellaccount.blogspot.com/2008/07/fancy-globbing-with-zsh-on-linux-and.html +setopt extendedglob + diff --git a/custom/zsh.sample/before.sample.zsh b/custom/zsh.sample/before.sample.zsh new file mode 100644 index 0000000..c171f66 --- /dev/null +++ b/custom/zsh.sample/before.sample.zsh @@ -0,0 +1,16 @@ +# +# Samples of what you can do in *.before.zsh files. +# You can create as many files as you like, or put everything in one. +# + +# append your own plugins. the $plugins at the end includes the plugins +# defined by YADR. +plugins=(osx ruby vagrant $plugins) + +# ignore plugins defined by YADR and use your own list. Notice there is no +# $plugins at the end. +plugins=(osx ruby vagrant) + +# set your theme. +export ZSH_THEME="kennethreitz" + diff --git a/zsh/aliases b/zsh/aliases deleted file mode 100644 index 56d5677..0000000 --- a/zsh/aliases +++ /dev/null @@ -1,127 +0,0 @@ -# Aliases in this file are bash and zsh compatible - -# Don't change. The following determines where YADR is installed. -yadr=`find -L ~ -type file -maxdepth 2 -name .yadr | head | sed 's:\.yadr\/::'` - -# YADR support -alias yav='yadr vim-add-plugin' -alias yuv='yadr vim-update-plugins' -alias yip='yadr init-plugins' - -# PS -alias psg="ps aux | grep " -alias psr='ps aux | grep ruby' - -# Moving around -alias ..='cd ..' -alias cdb='cd -' - -# Show human friendly numbers and colors -alias df='df -h' -alias ll='ls -alGh' -alias ls='ls -Gh' -alias du='du -h -d 2' - -# show me files matching "ls grep" -alias lsg='ll | grep' - -# Alias Editing -alias ae='vi $yadr/zsh/aliases' #alias edit -alias ar='source $yadr/zsh/aliases' #alias reload - -# vim using -alias vim=$(brew ls macvim | grep Contents/MacOS/Vim) - -# vimrc editing -alias ve='vi ~/.vimrc' - -# zsh profile editing -alias ze='vi ~/.zshrc' -alias zr='source ~/.zshrc' - -# Git Aliases -alias gs='git status' -alias gstsh='git stash' -alias gst='git stash' -alias gsh='git show' -alias gshw='git show' -alias gshow='git show' -alias gi='vi .gitignore' -alias gcm='git ci -m' -alias gcim='git ci -m' -alias gci='git ci' -alias gco='git co' -alias ga='git add -A' -alias guns='git unstage' -alias gunc='git uncommit' -alias gm='git merge' -alias gms='git merge --squash' -alias gam='git amend' -alias gr='git rebase' -alias gra='git rebase --abort' -alias grc='git rebase --continue' -alias gbi='git rebase --interactive' -alias gl='git l' -alias glg='git l' -alias glog='git l' -alias co='git co' -alias gf='git fetch' -alias gfch='git fetch' -alias gd='git diff' -alias gb='git b' -alias gdc='git diff --cached' -alias gpub='grb publish' -alias gtr='grb track' -alias gpl='git pull' -alias gplr='git pull --rebase' -alias gps='git push' -alias gpsh='git push' -alias gnb='git nb' # new branch aka checkout -b -alias grs='git reset' -alias grsh='git reset --hard' -alias gcln='git clean' -alias gclndf='git clean -df' -alias gsm='git submodule' -alias gsmi='git submodule init' -alias gsmu='git submodule update' -alias gt='git t' - -# Common shell functions -alias less='less -r' -alias tf='tail -f' -alias l='less' -alias lh='ls -alt | head' # see the last modified files -alias screen='TERM=screen screen' -alias cl='clear' -alias ps='ps aux' - -# Zippin -alias gz='tar -zcvf' - -# Ruby -alias c='script/console --irb=pry' -alias ms='mongrel_rails start' - -# Vim/ctags "mctags = make ctags", using the ruby specific version -# to save some time -alias mctags=~/.bin/run_tags.rb #'/opt/local/bin/ctags -Rf ./tags *' - -alias ka9='killall -9' -alias k9='kill -9' - -# Gem install -alias sgi='sudo gem install --no-ri --no-rdoc' - -# TODOS -# This uses NValt (NotationalVelocity alt fork) - http://brettterpstra.com/project/nvalt/ -# to find the note called 'todo' -alias todo='open nvalt://find/todo' - -# fasd - https://github.com/clvv/fasd -# jump to recently used items -alias a='fasd -a' # any -alias s='fasd -s' # show / search / select -alias d='fasd -d' # directory -alias f='fasd -f' # file -alias z='fasd_cd -d' # cd, same functionality as j in autojump -alias v='f -e vim' # quick opening files with vim diff --git a/zsh/aliases b/zsh/aliases new file mode 120000 index 0000000..a56c775 --- /dev/null +++ b/zsh/aliases @@ -0,0 +1 @@ +aliases.zsh \ No newline at end of file diff --git a/zsh/aliases.zsh b/zsh/aliases.zsh new file mode 100644 index 0000000..e2c65d5 --- /dev/null +++ b/zsh/aliases.zsh @@ -0,0 +1,119 @@ +# Aliases in this file are bash and zsh compatible + +# Don't change. The following determines where YADR is installed. +yadr=`find -L ~ -type file -maxdepth 2 -name .yadr | head | sed 's:\.yadr\/::'` + +# YADR support +alias yav='yadr vim-add-plugin' +alias yuv='yadr vim-update-plugins' +alias yip='yadr init-plugins' + +# PS +alias psg="ps aux | grep " +alias psr='ps aux | grep ruby' + +# Moving around +alias ..='cd ..' +alias cdb='cd -' + +# Show human friendly numbers and colors +alias df='df -h' +alias ll='ls -alGh' +alias ls='ls -Gh' +alias du='du -h -d 2' + +# show me files matching "ls grep" +alias lsg='ll | grep' + +# Alias Editing +alias ae='vi $yadr/zsh/aliases' #alias edit +alias ar='source $yadr/zsh/aliases' #alias reload + +# vim using +alias vim=$(brew ls macvim | grep Contents/MacOS/Vim) + +# vimrc editing +alias ve='vi ~/.vimrc' + +# zsh profile editing +alias ze='vi ~/.zshrc' +alias zr='source ~/.zshrc' + +# Git Aliases +alias gs='git status' +alias gstsh='git stash' +alias gst='git stash' +alias gsh='git show' +alias gshw='git show' +alias gshow='git show' +alias gi='vi .gitignore' +alias gcm='git ci -m' +alias gcim='git ci -m' +alias gci='git ci' +alias gco='git co' +alias ga='git add -A' +alias guns='git unstage' +alias gunc='git uncommit' +alias gm='git merge' +alias gms='git merge --squash' +alias gam='git amend' +alias gr='git rebase' +alias gra='git rebase --abort' +alias grc='git rebase --continue' +alias gbi='git rebase --interactive' +alias gl='git l' +alias glg='git l' +alias glog='git l' +alias co='git co' +alias gf='git fetch' +alias gfch='git fetch' +alias gd='git diff' +alias gb='git b' +alias gdc='git diff --cached' +alias gpub='grb publish' +alias gtr='grb track' +alias gpl='git pull' +alias gplr='git pull --rebase' +alias gps='git push' +alias gpsh='git push' +alias gnb='git nb' # new branch aka checkout -b +alias grs='git reset' +alias grsh='git reset --hard' +alias gcln='git clean' +alias gclndf='git clean -df' +alias gsm='git submodule' +alias gsmi='git submodule init' +alias gsmu='git submodule update' +alias gt='git t' + +# Common shell functions +alias less='less -r' +alias tf='tail -f' +alias l='less' +alias lh='ls -alt | head' # see the last modified files +alias screen='TERM=screen screen' +alias cl='clear' +alias ps='ps aux' + +# Zippin +alias gz='tar -zcvf' + +# Ruby +alias c='script/console --irb=pry' +alias ms='mongrel_rails start' + +# Vim/ctags "mctags = make ctags", using the ruby specific version +# to save some time +alias mctags=~/.bin/run_tags.rb #'/opt/local/bin/ctags -Rf ./tags *' + +alias ka9='killall -9' +alias k9='kill -9' + +# Gem install +alias sgi='sudo gem install --no-ri --no-rdoc' + +# TODOS +# This uses NValt (NotationalVelocity alt fork) - http://brettterpstra.com/project/nvalt/ +# to find the note called 'todo' +alias todo='open nvalt://find/todo' + diff --git a/zsh/color-man-pages.zsh b/zsh/color-man-pages.zsh new file mode 100644 index 0000000..7d2de22 --- /dev/null +++ b/zsh/color-man-pages.zsh @@ -0,0 +1,10 @@ +# Less Colors for Man Pages +# http://linuxtidbits.wordpress.com/2009/03/23/less-colors-for-man-pages/ +export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking +export LESS_TERMCAP_md=$'\E[01;38;5;74m' # begin bold +export LESS_TERMCAP_me=$'\E[0m' # end mode +export LESS_TERMCAP_se=$'\E[0m' # end standout-mode +export LESS_TERMCAP_so=$'\E[38;33;246m' # begin standout-mode - info box +export LESS_TERMCAP_ue=$'\E[0m' # end underline +export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline + diff --git a/zsh/fasd.zsh b/zsh/fasd.zsh new file mode 100644 index 0000000..06e59e3 --- /dev/null +++ b/zsh/fasd.zsh @@ -0,0 +1,16 @@ +# only init if installed. +if [[ -f $HOME/.fasd ]]; then + # Initialize fasd (https://github.com/clvv/fasd) + eval "$(fasd --init posix-alias zsh-hook)" + + # aliases + + # jump to recently used items + alias a='fasd -a' # any + alias s='fasd -s' # show / search / select + alias d='fasd -d' # directory + alias f='fasd -f' # file + alias z='fasd_cd -d' # cd, same functionality as j in autojump + alias v='f -e vim' # quick opening files with vim +fi + diff --git a/zsh/git.zsh b/zsh/git.zsh new file mode 100644 index 0000000..1733236 --- /dev/null +++ b/zsh/git.zsh @@ -0,0 +1,6 @@ +# Speed up git completion +# http://talkings.org/post/5236392664/zsh-and-slow-git-completion +__git_files () { + _wanted files expl 'local files' _files +} + diff --git a/zsh/key-bindings.zsh b/zsh/key-bindings.zsh new file mode 100644 index 0000000..a6b7332 --- /dev/null +++ b/zsh/key-bindings.zsh @@ -0,0 +1,34 @@ +# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html +# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Builtins +# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Standard-Widgets + +bindkey -v # Use vi key bindings + +bindkey '\ew' kill-region # [Esc-w] - Kill from the cursor to the mark +bindkey -s '\el' 'ls\n' # [Esc-l] - run command: ls +bindkey -s '\e.' '..\n' # [Esc-.] - run command: .. (up directory) +bindkey '^r' history-incremental-search-backward # [Ctrl-r] - Search backward incrementally for a specified string. The string may begin with ^ to anchor the search to the beginning of the line. +bindkey '^[[5~' up-line-or-history # [PageUp] - Up a line of history +bindkey '^[[6~' down-line-or-history # [PageDown] - Down a line of history + +bindkey '^[[A' up-line-or-search # start typing + [Up-Arrow] - fuzzy find history forward +bindkey '^[[B' down-line-or-search # start typing + [Down-Arrow] - fuzzy find history backward + +bindkey '^[[H' beginning-of-line # [Home] - Go to beginning of line +bindkey '^[[1~' beginning-of-line # [Home] - Go to beginning of line +bindkey '^[OH' beginning-of-line # [Home] - Go to beginning of line +bindkey '^[[F' end-of-line # [End] - Go to end of line +bindkey '^[[4~' end-of-line # [End] - Go to end of line +bindkey '^[OF' end-of-line # [End] - Go to end of line + +bindkey ' ' magic-space # [Space] - do history expansion + +bindkey '^[[1;5C' forward-word # [Ctrl-RightArrow] - move forward one word +bindkey '^[[1;5D' backward-word # [Ctrl-LeftArrow] - move backward one word + +# Make the delete key (or Fn + Delete on the Mac) work instead of outputting a ~ +bindkey '^?' backward-delete-char # [Delete] - delete backward +bindkey '^[[3~' delete-char # [fn-Delete] - delete forward +bindkey '^[3;5~' delete-char +bindkey '\e[3~' delete-char + diff --git a/zsh/path.zsh b/zsh/path.zsh new file mode 100644 index 0000000..c6706f2 --- /dev/null +++ b/zsh/path.zsh @@ -0,0 +1,3 @@ +# path +export PATH=/usr/local/bin:$PATH + diff --git a/zsh/zsh-aliases.zsh b/zsh/zsh-aliases.zsh new file mode 100644 index 0000000..5fcd1cf --- /dev/null +++ b/zsh/zsh-aliases.zsh @@ -0,0 +1,18 @@ +# Global aliases +alias -g ...='../..' +alias -g ....='../../..' +alias -g .....='../../../..' +alias -g C='| wc -l' +alias -g H='| head' +alias -g L="| less" +alias -g N="| /dev/null" +alias -g S='| sort' +alias -g G='| grep' # now you can do: ls foo G something + +# Functions +# +# (f)ind by (n)ame +# usage: fn foo +# to find all files containing 'foo' in the name +function fn() { ls **/*$1* } + diff --git a/zsh/zsh_aliases b/zsh/zsh_aliases deleted file mode 100644 index 34c1c1f..0000000 --- a/zsh/zsh_aliases +++ /dev/null @@ -1,17 +0,0 @@ -# Global aliases -alias -g ...='../..' -alias -g ....='../../..' -alias -g .....='../../../..' -alias -g C='| wc -l' -alias -g H='| head' -alias -g L="| less" -alias -g N="| /dev/null" -alias -g S='| sort' -alias -g G='| grep' # now you can do: ls foo G something - -# Functions -# -# (f)ind by (n)ame -# usage: fn foo -# to find all files containing 'foo' in the name -function fn() { ls **/*$1* } diff --git a/zsh/zsh_aliases b/zsh/zsh_aliases new file mode 120000 index 0000000..93ecce6 --- /dev/null +++ b/zsh/zsh_aliases @@ -0,0 +1 @@ +zsh-aliases.zsh \ No newline at end of file diff --git a/zsh/zshrc b/zsh/zshrc index cefaf34..04d08f6 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -1,3 +1,14 @@ +# -------------------------------- +# +# DO NOT EDIT THIS FILE. +# If you want to make changes, do so in the custom/zsh directory. +# Fork and send pull requests to add features and fix bugs. Thanks! +# +# ================================ + +# Don't change. The following determines where YADR is installed. +yadr=`find -L ~ -type file -maxdepth 2 -name .yadr | head | sed 's:\.yadr\/::'` + # Source oh-my-zsh if it is installed. if [[ -d $HOME/.oh-my-zsh ]]; then # Path to your oh-my-zsh configuration. @@ -10,56 +21,46 @@ if [[ -d $HOME/.oh-my-zsh ]]; then # Example format: plugins=(rails git textmate ruby lighthouse) plugins=(vi-mode git rvm ruby rails autojump bundler gem gnu-utils heroku rake redis-cli zsh-syntax-highlighting history-substring-search) - # Load default oh-my-zsh stuff + # source every zsh file in user's custom/zsh/before. This is useful for setting theme and plugins. + if [[ -d $yadr/custom/zsh/ ]]; then + for config_file ($yadr/custom/zsh/**/*.before.zsh) source $config_file + fi + + # Source oh-my-zsh source $ZSH/oh-my-zsh.sh fi -# Don't change. The following determines where YADR is installed. -yadr=`find -L ~ -type file -maxdepth 2 -name .yadr | head | sed 's:\.yadr\/::'` - # Configuration -source $yadr/zsh/aliases -source $yadr/zsh/zsh_aliases +for config_file ($yadr/zsh/*.zsh) source $config_file -# Things I don't want to publish to github -[[ -s "$HOME/.secrets" ]] && source "$HOME/.secrets" +# RVM / rbenv +if [[ -d ~/.rvm/ ]] && [[ -d ~/.rbenv/ ]]; then + # TODO: colorize + echo '***************************************************************' + echo 'ERROR!' + echo 'YADR found both ~/.rvm and ~/.rbenv directories. You cannot use' + echo 'RVM and rbenv simultaneously. Please delete one and reload zsh.' + echo '***************************************************************' + echo '' +else + if [[ -d ~/.rvm/ ]]; then + [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" + fi + if [[ -d ~/.rbenv/ ]]; then + eval "$(rbenv init -)" + fi +fi -# Give me my bash style incremental search -bindkey '^R' history-incremental-search-backward +# ------------------ +# zsh/after +# ================== +# source every zsh file in user's custom/zsh/after. +if [[ -d $yadr/custom/zsh/ ]]; then + for config_file ($yadr/custom/zsh/**/*.after.zsh) source $config_file +fi -# Speed up git completion -# http://talkings.org/post/5236392664/zsh-and-slow-git-completion -__git_files () { - _wanted files expl 'local files' _files -} +# Put secret configuration settings in ~/.secrets +if [[ -a ~/.secrets ]] then + source ~/.secrets +fi -# Always pushd when changing directory -setopt auto_pushd - -# Use zmv, which is amazing -autoload -U zmv -alias zmv="noglob zmv -W" - -# Fuzzy matching of completions for when you mistype them: -zstyle ':completion:*' completer _complete _match _approximate -zstyle ':completion:*:match:*' original only -zstyle ':completion:*:approximate:*' max-errors 1 numeric - -# RVM -[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" - -# Add path to our custom bins -export PATH=/usr/local/bin:$PATH:$yadr/bin:$yadr/bin/yadr - -# Less Colors for Man Pages -# http://linuxtidbits.wordpress.com/2009/03/23/less-colors-for-man-pages/ -export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking -export LESS_TERMCAP_md=$'\E[01;38;5;74m' # begin bold -export LESS_TERMCAP_me=$'\E[0m' # end mode -export LESS_TERMCAP_se=$'\E[0m' # end standout-mode -export LESS_TERMCAP_so=$'\E[38;33;246m' # begin standout-mode - info box -export LESS_TERMCAP_ue=$'\E[0m' # end underline -export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline - -# Initialize fasd (https://github.com/clvv/fasd) -eval "$(fasd --init posix-alias zsh-hook)" diff --git a/zsh/zvm.zsh b/zsh/zvm.zsh new file mode 100644 index 0000000..674184e --- /dev/null +++ b/zsh/zvm.zsh @@ -0,0 +1,4 @@ +# Use zmv, which is amazing +autoload -U zmv +alias zmv="noglob zmv -W" +