Ability to customize zsh in ~/.yadr/custom/zsh folder

* Split zsh config into snippets in zsh/ folder, similar to vim
 * Feature implementation by @kylewest

* kylewest/zsh:
  Documentation for customizing ZSH.
  Only init fasd if it is installed.
  Removed brew and github plugins.
  updated .gitignore for new zsh paths.
  simplifying paths for zsh customization.
  added zsh aliases. Moved other files but left symlinks for backwards compatibility.
  automatically load RVM or rbenv.
  updated .gitignore
  adding sample zsh configs.
  added directories and code for custom zsh configuration.
This commit is contained in:
Kyle West 2012-04-01 14:48:23 -07:00 committed by Yan Pritzker
commit 4c41b17591
15 changed files with 311 additions and 190 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
.DS_Store custom/zsh
vim/backups vim/backups
vim/view vim/view
*un~ *un~

View File

@ -172,6 +172,21 @@ mnemonic aliases. Please feel free to edit them:
* Bash style ctrl-R for reverse history finder * Bash style ctrl-R for reverse history finder
* Fuzzy matching - if you mistype a directory name, tab completion will fix it * 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 ## Pry

View File

@ -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

View File

@ -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"

View File

@ -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

1
zsh/aliases Symbolic link
View File

@ -0,0 +1 @@
aliases.zsh

119
zsh/aliases.zsh Normal file
View File

@ -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'

10
zsh/color-man-pages.zsh Normal file
View File

@ -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

16
zsh/fasd.zsh Normal file
View File

@ -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

6
zsh/git.zsh Normal file
View File

@ -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
}

34
zsh/key-bindings.zsh Normal file
View File

@ -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

3
zsh/path.zsh Normal file
View File

@ -0,0 +1,3 @@
# path
export PATH=/usr/local/bin:$PATH

18
zsh/zsh-aliases.zsh Normal file
View File

@ -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* }

View File

@ -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* }

1
zsh/zsh_aliases Symbolic link
View File

@ -0,0 +1 @@
zsh-aliases.zsh

View File

@ -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. # Source oh-my-zsh if it is installed.
if [[ -d $HOME/.oh-my-zsh ]]; then if [[ -d $HOME/.oh-my-zsh ]]; then
# Path to your oh-my-zsh configuration. # 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) # 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) 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 source $ZSH/oh-my-zsh.sh
fi 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 # Configuration
source $yadr/zsh/aliases for config_file ($yadr/zsh/*.zsh) source $config_file
source $yadr/zsh/zsh_aliases
# Things I don't want to publish to github # RVM / rbenv
[[ -s "$HOME/.secrets" ]] && source "$HOME/.secrets" 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 # Put secret configuration settings in ~/.secrets
# http://talkings.org/post/5236392664/zsh-and-slow-git-completion if [[ -a ~/.secrets ]] then
__git_files () { source ~/.secrets
_wanted files expl 'local files' _files 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)"

4
zsh/zvm.zsh Normal file
View File

@ -0,0 +1,4 @@
# Use zmv, which is amazing
autoload -U zmv
alias zmv="noglob zmv -W"