Created
June 15, 2010 17:05
-
-
Save brendano/439383 to your computer and use it in GitHub Desktop.
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
# anyall.org/.zshrc - for zsh, the best shell in the world | |
# brendan oconnor - brenocon at gmail - anyall.org | |
# if [[ -f ~/.profile ]] && [ ! "$PROFILE_READ" ]; then | |
# export PROFILE_READ=yes | |
# source ~/.profile | |
# fi | |
#[[ -f ~/.inputrc ]] && export INPUTRC=~/.inputrc | |
[[ -f ~/db.sh ]] && source ~/db.sh | |
uname=`uname` | |
[[ $uname == Darwin ]] && is_mac=yes | |
[[ $uname == Darwin ]] && is_local=yes | |
[[ "$is_local" = yes ]] && export DISPLAY=${DISPLAY:-:0.0} | |
if [ "$is_local" ] && [ "$is_mac" ]; then | |
alias cm="/Applications/Emacs.app/Contents/MacOS/Emacs" | |
alias ccm=/Applications/Emacs.app/Contents/MacOS/bin/emacs | |
# mac gui apps | |
# function better than alias: no hanging for tab completion | |
excel() { open -a "/Applications/Microsoft Office 2008/Microsoft Excel.app" "$@" } | |
word() { open -a "/Applications/Microsoft Office 2008/Microsoft Word.app" "$@" } | |
ppt() { open -a "Microsoft Powerpoint" "$@" } | |
ff() { open -a "/Applications/Firefox.app" "$@" } | |
safari() { open -a Safari "$@" } | |
chrome() { open -a /Applications/Google\ Chrome.app "$@" } | |
smul() { open -a Smultrion "$@" } | |
texshop(){ open -a TexShop "$@" } | |
alias apps='open /Applications' | |
fi | |
#alias lp='ls --color ^*(~|.pyc|ptlc)(^/)' | |
function abspath { | |
if [ -d "$1" ]; then | |
(cd "$1" && pwd) | |
else | |
echo "$(abspath $(dirname $1))/$(basename $1)" | |
fi | |
} | |
function habspath { | |
echo "$(hostname -s):$(abspath $1)" | |
} | |
function lsfull { | |
ls -d $(abspath $1) | |
# if [[ "$1" == /* ]]; then | |
# else | |
# ls -d $(pwd)/$1 | |
# fi | |
} | |
function 'h?' { | |
history +1 | perl -pe "s/ *\d+//" | grep "$@" | uniq | grep --color=always "$@" | |
} | |
# alias view='gvim --cmd "au GUIEnter * simalt ~x"' | |
alias v=vim | |
alias vp='vim -S =(echo "se paste\nstart")' | |
#iterm TERM=ansi screws up emacs | |
#alias emacs="TERM=xterm emacs" | |
# alias e="emacs -nw" | |
alias screen='TERM=screen screen' # http://ubuntuforums.org/showthread.php?t=90910 | |
export PYTHONSTARTUP=~/.pythonrc | |
# no spelling corrections (man zshbuiltins) | |
alias mv='nocorrect mv' | |
alias cp='nocorrect cp' | |
alias mkdir='nocorrect mkdir' | |
alias rm='nocorrect rm' | |
alias pu=pushd | |
alias p=popd | |
alias .='pwd' | |
alias ..="cd .." | |
alias ...='cd ../..' | |
alias ....='cd ../../..' | |
alias -- -='cd -' | |
cd () { | |
if [[ "x$*" == "x..." ]]; then | |
cd ../.. | |
elif [[ "x$*" == "x...." ]]; then | |
cd ../../.. | |
elif [[ "x$*" == "x....." ]]; then | |
cd ../../.. | |
elif [[ "x$*" == "x......" ]]; then | |
cd ../../../.. | |
else | |
builtin cd "$@" | |
fi | |
} | |
if ls --color &>/dev/null; then | |
ls_opt="--color=tty" # gnu (linux) | |
else | |
ls_opt="-G" # mac | |
#ls_opt="-F" # less buggy | |
fi | |
alias ls="ls $ls_opt" | |
alias ll='ls -l' | |
export GREP_OPTIONS='--color=auto' | |
alias cgrep='grep --color=always' | |
function lcgrep { | |
grep --color=always "$@" | less -r | |
} | |
alias pyclean='rm -f **/*(.pyc|.ptlc|~)' | |
alias rmtil='rm -f *~ *.pyc' | |
alias rrmtil='rm -f **/*~' | |
# override TERM=screen. need env bcs some apps dont smartly interpret PAGER | |
export PAGER='env TERM=xterm less' | |
export MANPAGER='env TERM=xterm less -Ri' | |
export GIT_PAGER='env TERM=xterm less -RFi' | |
export ACK_PAGER='env TERM=xterm less -RFi' | |
#export LESS='-XRF' | |
#export LESS='-RF' | |
export LESS='-RFi' | |
# export LESS='-i' # git diff unhappy | |
export EDITOR=vim | |
# export SVN_SSH="ssh -l $USER" | |
alias 1='cd -' | |
alias 2='cd +2' | |
alias 3='cd +3' | |
alias 4='cd +4' | |
alias 5='cd +5' | |
alias 6='cd +6' | |
alias 7='cd +7' | |
alias 8='cd +8' | |
alias 9='cd +9' | |
alias d='dirs -v' | |
setopt prompt_subst | |
autoload colors zsh/terminfo | |
autoload -Uz colors | |
colors | |
# if [[ "$terminfo[colors]" -ge 8 ]]; then | |
# colors | |
# fi | |
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do | |
if [[ "$TERM" == dumb ]]; then | |
eval PR_$color= | |
eval PR_LIGHT_$color= | |
BOLD= | |
UNBOLD= | |
else | |
eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}' | |
eval PR_LIGHT_$color='%{$fg[${(L)color}]%}' | |
BOLD='%B' | |
UNBOLD='%b' | |
fi | |
done | |
PR_NO_COLOUR="%{$terminfo[sgr0]%}" | |
[[ "$TERM" == dumb ]] && PR_NO_COLOUR= | |
## PS1 and PS2 also work, but conflict with sh/bash. | |
## PROMPT conflicts with cmd.exe, less important | |
# %m is machine name | |
if [[ "$is_local" == yes ]]; then | |
PROMPT='$BOLD$PR_BLUE%~$UNBOLD $PR_LIGHT_BLUE$PR_GREEN%#$PR_NO_COLOUR ' | |
# PROMPT='$BOLD$PR_BLUE%~$UNBOLD $PR_LIGHT_BLUE`vcprompt -f "[%b] "`$PR_GREEN%#$PR_NO_COLOUR ' | |
else | |
PROMPT='$BOLD$PR_RED%n@%m:$PR_BLUE%~$UNBOLD $PR_GREEN%#$PR_NO_COLOUR ' #user@machine on front | |
fi | |
# PROMPT="__________________________________________________________________ | |
# $BOLD$PR_BLUE%~$UNBOLD $PR_LIGHT_BLUE`vcprompt -f "[%b] "` | |
# $PR_GREEN%#$PR_NO_COLOUR " | |
# Prompt in right margin | |
## RPROMPT='[%h]' | |
function title { | |
if [[ $TERM == "screen" ]]; then | |
# Use these two for GNU Screen: | |
print -nR $'\033k'$1$'\033'\\\ | |
print -nR $'\033]0;'$2$'\a' | |
elif [[ $TERM == "xterm" || $TERM == "rxvt" ]]; then | |
# Use this one instead for XTerms: | |
print -nR $'\033]0;'$*$'\a' | |
fi | |
} | |
function precmd { | |
title zsh "$PWD" | |
} | |
function preexec { | |
emulate -L zsh | |
local -a cmd; cmd=(${(z)1}) | |
title $cmd[1]:t "$cmd[2,-1]" | |
} | |
function tab() { | |
osascript 2>/dev/null <<EOF | |
tell application "System Events" | |
tell process "Terminal" to keystroke "t" using command down | |
end | |
tell application "Terminal" | |
activate | |
do script with command "cd \"$PWD\"; $*" in window 1 | |
end tell | |
EOF | |
} | |
# case $TERM in | |
# screen) | |
# precmd() { | |
# local CMD=${1[(wr)^(*=*|sudo|-*)]} | |
# echo -ne "\ek$CMD\e\\" | |
# } | |
# ;; | |
# | |
# xterm*|rxvt|cygwin|putty|ansi) | |
# # precmd () { print -Pn "\e]0;%~ (%m)\a" } | |
# | |
# # i now use leopard terminal, it automatically makes tab titles the process under execution, so preexec() doesnt do anything. unclear what a good workaround is. | |
# # precmd () { print -Pn "\e]0;%m: %~\a" } | |
# # preexec () { | |
# # cmd=${1[0,100]} | |
# # print -Pn "\e]0;%m: $cmd\a" | |
# # } | |
# ;; | |
# esac | |
# ----- Lots of options. (man zshoptions) ----- | |
# History awesomeness! see rant at dotfiles.org/~brendano/.inputrc | |
# (zsh does not use gnu readline, so doesnt use .inputrc, but this duplicates | |
# those features...) | |
HISTFILE=~/.zhistory | |
HISTSIZE=100000 | |
SAVEHIST=100000 | |
#setopt appendhistory | |
setopt inc_append_history | |
setopt hist_verify | |
setopt share_history | |
setopt hist_ignore_dups | |
setopt hist_no_store | |
setopt hist_reduce_blanks | |
setopt hist_expire_dups_first | |
setopt autopushd pushdminus pushdtohome autocd pushdignoredups | |
setopt clobber | |
setopt nocorrectall # only want commands, not arg correction | |
setopt correct | |
setopt equals | |
setopt extended_glob | |
setopt interactive_comments | |
setopt long_list_jobs | |
setopt nohup | |
setopt nonomatch # echo not-here* actually gets the * | |
#setopt nullglob # echo not-here* expands to no args | |
LS_COLORS='no=00;32:fi=00:di=00;34:ln=01;36:pi=04;33:so=01;35:bd=33;04:cd=33;04:or=31;01:ex=00;32:*.rtf=00;33:*.txt=00;33:*.html=00;33:*.doc=00;33:*.pdf=00;33:*.ps=00;33:*.sit=00;31:*.hqx=00;31:*.bin=00;31:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.deb=00;31:*.dmg=00;36:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.ppm=00;35:*.tga=00;35:*.xbm=00;35:*.xpm=00;35:*.tif=00;35:*.mpg=00;37:*.avi=00;37:*.gl=00;37:*.dl=00;37:*.mov=00;37:*.mp3=00;35:' | |
export LS_COLORS; | |
autoload -U compinit | |
compinit | |
zmodload -i zsh/complist # completion for MANY commands | |
# zstyle ':completion:*' list-colors '' | |
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} | |
zstyle ':completion:*' group-name '' | |
zstyle ':completion:*' menu select | |
# zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01' | |
autoload -U url-quote-magic | |
zle -N self-insert url-quote-magic | |
#more more more more options | |
#setopt notify globdots correct pushdtohome cdablevars autolist | |
#setopt correctall autocd recexact longlistjobs | |
#setopt autoresume histignoredups pushdsilent noclobber | |
#setopt autopushd pushdminus extendedglob rcquotes mailwarning | |
#unsetopt bgnice autoparamslash | |
# zsh doesnt use readline, and these are almost always not set | |
# or set wrongly. yikes... | |
# if [ -f ~/.zkbd/$TERM-$VENDOR-$OSTYPE ]; then | |
# source ~/.zkbd/$TERM-$VENDOR-$OSTYPE | |
# [[ -n ${key[Backspace]} ]] && bindkey "${key[Backspace]}" backward-delete-char | |
# [[ -n ${key[Home]} ]] && bindkey "${key[Home]}" beginning-of-line | |
# [[ -n ${key[PageUp]} ]] && bindkey "${key[PageUp]}" up-line-or-history | |
# [[ -n ${key[Delete]} ]] && bindkey "${key[Delete]}" delete-char | |
# [[ -n ${key[End]} ]] && bindkey "${key[End]}" end-of-line | |
# [[ -n ${key[PageDown]} ]] && bindkey "${key[PageDown]}" down-line-or-history | |
# [[ -n ${key[Up]} ]] && bindkey "${key[Up]}" up-line-or-search | |
# [[ -n ${key[Up]} ]] && bindkey "${key[Up]}" up-line-or-search | |
# [[ -n ${key[Left]} ]] && bindkey "${key[Left]}" backward-char | |
# [[ -n ${key[Down]} ]] && bindkey "${key[Down]}" down-line-or-search | |
# [[ -n ${key[Right]} ]] && bindkey "${key[Right]}" forward-char | |
# else | |
WORDCHARS="" | |
#emacs bindings, e.g. ctrl-{a,e,d,k,u,y} | |
bindkey -e | |
#history only on first substring of command you're typing | |
#bindkey "\e[A" up-line-or-search | |
#bindkey "\e[B" down-line-or-search | |
bindkey "\e[A" history-beginning-search-backward | |
bindkey "\e[B" history-beginning-search-forward | |
#new iterm binds up arrow to this, wtf, ^[[A is standard on all other xterm's | |
bindkey "\eOA" history-beginning-search-backward | |
bindkey "\eOB" history-beginning-search-forward | |
bindkey "\e[1~" beginning-of-line | |
bindkey "\e[2~" quoted-insert | |
bindkey "\e[3~" delete-char | |
bindkey "\e[4~" end-of-line | |
bindkey "\e[5~" beginning-of-history | |
bindkey "\e[6~" end-of-history | |
bindkey "\e[7~" beginning-of-line | |
bindkey "\e[8~" end-of-line | |
bindkey "\e[H" beginning-of-line | |
bindkey "\e[F" end-of-line | |
bindkey "\eOH" beginning-of-line | |
bindkey "\eOF" end-of-line | |
bindkey "\eOd" backward-word | |
bindkey "\eOc" forward-word | |
# ubuntu demanded this once from iterm TERM=xterm-color | |
bindkey '^?' backward-delete-char | |
## file rename magick | |
bindkey "^[m" copy-prev-shell-word | |
lst() { | |
# colorized listing of individual files | |
if [ "$1" ]; then | |
prefix="$1/" | |
else | |
prefix= | |
fi | |
print -l $prefix**/* | xargs ls -d $ls_opt | |
} | |
export TAB="$(echo -e "\t")" | |
# alias jsonpp='python -msimplejson.tool' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment