From 1c8cb165cd5b1c43b60098fc6e288d7177bdaf39 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Fri, 20 Jul 2012 09:19:54 -0700 Subject: [PATCH 1/9] Move system-specific customizations to .rc (no more .rc.$SYS) --- rc | 38 ++++++++++++++++++++++++++++++++------ rc.darwin | 15 --------------- 2 files changed, 32 insertions(+), 21 deletions(-) delete mode 100644 rc.darwin diff --git a/rc b/rc index 97a6284..ead7bb6 100644 --- a/rc +++ b/rc @@ -3,16 +3,18 @@ # Generic interactive shell setup # Eryn Wells -alias ls="ls --color=auto" -alias la="ls -A --color=auto" -alias ll="ls -l --color=auto" -alias l.="ls -d --color=auto .*" alias j='jobs' alias h='history' alias df='df -h' alias du='du -h' alias g='git' -alias l='ledger' +alias v='view' + +$(hash ledger 1>/dev/null 2>&1) && alias l='ledger' + +alias cux='chmod u+x' +alias cuw='chmod u+w' +alias cur='chmod u+r' alias today='date +%Y-%m-%d' @@ -20,5 +22,29 @@ alias addkey="ssh-agent ~/.ssh/id_rsa" alias pprint-json="python -c 'import sys,json;print json.dumps(json.load(sys.stdin), indent=2)'" -[ -e $HOME/.rc.$SYS ] && source $HOME/.rc.$SYS +case $SYS in + darwin) + if $(hash gls 1>/dev/null 2>&1); then + ls='gls' + ls_options="--color=auto" + else + ls='ls' + ls_options='-G' + fi + alias ls="$ls $ls_options" + alias la="$ls -A $ls_options" + alias ll="$ls -l $ls_options" + $(hash gdircolors 1>/dev/null 2>&1) && alias dircolors='gdircolors' + ;; + linux) + alias ls="ls --color=auto" + alias la="ls -A --color=auto" + alias ll="ls -l --color=auto" + alias l.="ls -d --color=auto .*" + ;; + *) + print -P "%F{red}==>%f What system *is* this, anyway?" + ;; +esac + [ -e $HOME/.rc.local ] && source $HOME/.rc.local diff --git a/rc.darwin b/rc.darwin deleted file mode 100644 index f4111eb..0000000 --- a/rc.darwin +++ /dev/null @@ -1,15 +0,0 @@ -# vim: ft=zsh -# Darwin specific interactive shell setup for Bash and derivatives -# Eryn Wells - -alias ls="gls --color=auto" -alias la="gls -A --color=auto" -alias ll="gls -l --color=auto" -alias l.="gls -d --color=auto .*" -alias dircolors='gdircolors' - -if [[ $? -eq 0 ]]; then - alias itp="osascript $HOME/Code/AppleScripts/iTunes/previous-track.scpt" - alias itn="osascript $HOME/Code/AppleScripts/iTunes/next-track.scpt" - alias ito="osascript $HOME/Code/AppleScripts/iTunes/toggle.scpt" -fi From b2678621c96125f0cf97796e53ded4fca47083de Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Fri, 20 Jul 2012 09:35:41 -0700 Subject: [PATCH 2/9] Script of shell helper functions --- shell-functions | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 shell-functions diff --git a/shell-functions b/shell-functions new file mode 100644 index 0000000..403cd53 --- /dev/null +++ b/shell-functions @@ -0,0 +1,13 @@ +#!/bin/zsh +# vim: ft=zsh +# Helper functions for the init files +# Eryn Wells + + +# Print prettier, more uniform messages +function print_msg { print -P "%F{$1}==>%f $2" } +function print_info { print_msg 'blue' "$@" } +function print_error { print_msg 'red' "$@" } + +# Return 1 if the binary exists (according to hash); 0 otherwise. +function binary_exists { return $(hash $1 1>/dev/null 2>&1) } From 1f51980a5e781d00627217321b5d37066e790edb Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Fri, 20 Jul 2012 09:36:00 -0700 Subject: [PATCH 3/9] Source and use new shell-functions script in .rc --- rc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rc b/rc index ead7bb6..2b0b4e2 100644 --- a/rc +++ b/rc @@ -3,6 +3,8 @@ # Generic interactive shell setup # Eryn Wells +. $HOME/.shell-functions + alias j='jobs' alias h='history' alias df='df -h' @@ -10,7 +12,7 @@ alias du='du -h' alias g='git' alias v='view' -$(hash ledger 1>/dev/null 2>&1) && alias l='ledger' +binary_exists ledger && alias l='ledger' alias cux='chmod u+x' alias cuw='chmod u+w' @@ -24,7 +26,7 @@ alias pprint-json="python -c 'import sys,json;print json.dumps(json.load(sys.std case $SYS in darwin) - if $(hash gls 1>/dev/null 2>&1); then + if binary_exists gls; then ls='gls' ls_options="--color=auto" else @@ -34,7 +36,7 @@ case $SYS in alias ls="$ls $ls_options" alias la="$ls -A $ls_options" alias ll="$ls -l $ls_options" - $(hash gdircolors 1>/dev/null 2>&1) && alias dircolors='gdircolors' + binary_exists gdircolors && alias dircolors='gdircolors' ;; linux) alias ls="ls --color=auto" @@ -43,7 +45,7 @@ case $SYS in alias l.="ls -d --color=auto .*" ;; *) - print -P "%F{red}==>%f What system *is* this, anyway?" + print_error "What system %Bis%b this, anyway?" ;; esac From e2234bd4a0440c127ede526053ea8f663916afca Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Fri, 20 Jul 2012 09:36:57 -0700 Subject: [PATCH 4/9] Fix some formatting in .gitconfig --- gitconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitconfig b/gitconfig index 9c189a8..89a163b 100644 --- a/gitconfig +++ b/gitconfig @@ -3,7 +3,7 @@ email = eryn@erynwells.me [core] editor = vim - quotepath = false + quotepath = false [color] ui = auto [merge] From ec39d11f26161082a39dfc38ec52e938930c4382 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Fri, 20 Jul 2012 09:41:48 -0700 Subject: [PATCH 5/9] Move system-specific configuration to .env; remove .env.darwin --- env | 39 +++++++++++++++++++++++++++++++++++++-- env.darwin | 16 ---------------- 2 files changed, 37 insertions(+), 18 deletions(-) delete mode 100644 env.darwin diff --git a/env b/env index 09f8c4d..0176255 100644 --- a/env +++ b/env @@ -1,20 +1,55 @@ # .env # vim: ft=zsh # -# Environment settings for bash and derivatives +# Environment settings for bash and derivatives. The env scripts are sources by +# Zsh for every shell, even the non-interactive ones, so this needs to be small +# and quick. Any configuration that will only be used for interactive sessions +# should be in the rc scripts. # # Eryn Wells export SYS=`uname -s | tr A-Z a-z` +PAGER="less" +MANPAGER=$PAGER +EDITOR="vim" +VISUAL=$EDITOR +LESSHISTFILE="-" +GREP_OPTIONS="--color=auto" +GREP_COLOR="1;32" + +export PAGER MANPAGER \ + EDITOR VISUAL \ + LESSHISTFILE \ + GREP_OPTIONS GREP_COLOR + PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin +# NOTE: These prepended to $PATH in reverse order, so $HOME/bin will end up +# being the first path component. [ -d /usr/X11/bin ] && PATH=$PATH:/usr/X11/bin [ -d /opt/local/bin ] && PATH=/opt/local/bin:$PATH [ -d $HOME/.local/bin ] && PATH=$HOME/.local/bin:$PATH [ -d $HOME/bin ] && PATH=$HOME/bin:$PATH + export PATH # System specific environment settings -[ -e $HOME/.env.$SYS ] && source $HOME/.env.$SYS +case $SYS in + darwin) + export PATH=$HOME/Library/Python/2.7/bin:$PATH + + local py27local=$HOME/Library/Python/2.7/lib/python/site-packages + if [[ ! -z $PYTHONPATH ]]; then + [ -d $py27local ] && PYTHONPATH=$py27local:$PYTHONPATH + else + PYTHONPATH=$py27local + fi + export PYTHONPATH + ;; + linux) + export MAIL="/var/mail/$USER" + ;; +esac + # Local environment settings [ -e $HOME/.env.local ] && source $HOME/.env.local diff --git a/env.darwin b/env.darwin deleted file mode 100644 index dfa14a9..0000000 --- a/env.darwin +++ /dev/null @@ -1,16 +0,0 @@ -# .env.darwin -# vim: ft=zsh -# -# Darwin-specific environment settings -# -# Eryn Wells - -export PATH=$HOME/Library/Python/2.7/bin:$PATH - -local py27local=$HOME/Library/Python/2.7/lib/python/site-packages -if [[ ! -z $PYTHONPATH ]]; then - [ -d $py27local ] && PYTHONPATH=$py27local:$PYTHONPATH -else - PYTHONPATH=$py27local -fi -export PYTHONPATH From 10f025a6680424e42e0535494eb659d1b7380945 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Fri, 20 Jul 2012 09:48:27 -0700 Subject: [PATCH 6/9] Few minor tweaks to .vimrc --- vimrc | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/vimrc b/vimrc index ab20841..db4911b 100644 --- a/vimrc +++ b/vimrc @@ -1,5 +1,5 @@ " ~/.vimrc -" Eryn Wells +" Eryn Wells set nocompatible "use enhanced vim features @@ -31,8 +31,6 @@ set colorcolumn=80 " highlight 80th column set showmatch " show matching things: (), {}, [], etc set fo+=n " format numbered lists properly -set fo+=2 " format paragraphs with first line indent different - " from rest if has('gui_running') set list @@ -60,8 +58,10 @@ else set spellfile=~/.vim/spelling.en.add endif -set noswapfile " disable swap file -set nobackup " disable backup files +set noswapfile " don't keep swap files +set nobackup " don't keep backup files +set backupdir=~/.vim/backup + " save backup files here set undofile " save undo history set undodir=~/.vim/undo " save undo files here set history=1000 " remember 1000 commands in history @@ -129,7 +129,7 @@ if has('gui_running') if has('win32') || has('win64') set guifont=Inconsolata:h18 elseif has('mac') - set guifont=Menlo:h14 + set guifont=Menlo:h11 elseif has('linux') set guifont=Inconsolata\ 14 endif @@ -151,16 +151,12 @@ inoremap nnoremap vnoremap -" gonna give this a try... exit from insert mode with jj -inoremap jj - " make switching windows easier nnoremap h nnoremap j nnoremap k nnoremap l - function! StripTrailingWhitespace() " save last search let _s=@/ @@ -195,7 +191,8 @@ let g:CommandTAcceptSelectionTabMap='' if has('autocmd') filetype plugin indent on - autocmd BufAdd,BufEnter,BufFilePost *.md :set ft=markdown + " Markdown files can also have the .md extension + autocmd BufAdd,BufEnter,BufFilePost *.md :setlocal ft=markdown " Jump to last known cursor position unless it's the first line, or past the " end of the file @@ -204,10 +201,11 @@ if has('autocmd') \ exe "normal! g`\"" | \ endif - " Clean whitespace before saving - autocmd BufWritePre *.py,*.c,*.html :call StripTrailingWhitespace() + " Clean whitespace before saving: Python, C, HTML, and Objective-C + autocmd BufWritePre *.py,*.h,*.c,*.html,*.m + \ :call StripTrailingWhitespace() endif -if exists("~/.vimrc-local") - source ~/.vimrc-local +if exists("~/.vimrc.local") + source ~/.vimrc.local endif From 174afc2f063841867e412a37bd3e5b89bade2578 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Fri, 20 Jul 2012 09:49:03 -0700 Subject: [PATCH 7/9] Move shell agnostic stuff to .env from .zshenv --- zshenv | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/zshenv b/zshenv index fd127c0..c26dd05 100644 --- a/zshenv +++ b/zshenv @@ -7,22 +7,6 @@ [ -e $HOME/.env ] && source $HOME/.env -PAGER="less" -MANPAGER=$PAGER -EDITOR="vim" -VISUAL=$EDITOR -LESSHISTFILE="-" -GREP_OPTIONS="--color=auto" -GREP_COLOR="1;32" - -export PATH \ - PAGER MANPAGER \ - EDITOR VISUAL \ - LESSHISTFILE \ - GREP_OPTIONS GREP_COLOR - -[ $SYS = 'linux' ] && export MAIL="/var/mail/$USER" - # System specific environment settings [ -e $HOME/.zshenv.$SYS ] && source $HOME/.zshenv.$SYS # Local environment settings From 7b2074e2928447458122fd3cfdc64fa6856e9b1b Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Tue, 7 Aug 2012 11:18:50 -0700 Subject: [PATCH 8/9] Add push alias to git config --- gitconfig | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gitconfig b/gitconfig index 89a163b..46db076 100644 --- a/gitconfig +++ b/gitconfig @@ -1,6 +1,6 @@ [user] - name = Eryn Wells - email = eryn@erynwells.me + name = Eryn Wells + email = eryn@erynwells.me [core] editor = vim quotepath = false @@ -14,3 +14,8 @@ ci = commit br = branch lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative + push = push -u +[ui] + color = true +[mergetool] + keepBackup = true From 1400941de13bb00f468abe1d113dfb8893761ec6 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Tue, 7 Aug 2012 11:19:43 -0700 Subject: [PATCH 9/9] Add status messages to shell init files Mostly for profiling, but I think it's cool to have status occasionally. In the process, I also did some clean up, moving some stuff between profile, rc, and env. --- env | 8 ++++++-- profile | 28 ++-------------------------- rc | 25 ++++++++++++++++++++++++- shell-functions | 11 +++++++++++ zprofile | 2 ++ zshrc | 15 ++++----------- 6 files changed, 49 insertions(+), 40 deletions(-) diff --git a/env b/env index 0176255..a637661 100644 --- a/env +++ b/env @@ -8,8 +8,13 @@ # # Eryn Wells -export SYS=`uname -s | tr A-Z a-z` +[ -e $HOME/.shell-functions ] && source $HOME/.shell-functions +export SYS=`uname -s | tr A-Z a-z` +# Set this to a non-zero integer to see startup messages +export NOISY=0 + +print_info_noisy 1 "Initializing environment for $SYS system" PAGER="less" MANPAGER=$PAGER EDITOR="vim" @@ -33,7 +38,6 @@ PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin export PATH -# System specific environment settings case $SYS in darwin) export PATH=$HOME/Library/Python/2.7/bin:$PATH diff --git a/profile b/profile index f002eb5..cbcc10e 100644 --- a/profile +++ b/profile @@ -2,33 +2,9 @@ # vim: ft=zsh # Eryn Wells -# Gotta do some machine specific setup -arch=`uname -s` -case $arch in - Linux) - alias iptls='sudo iptables --line-numbers -nv -L' - alias ip6tls='sudo ip6tables --line-numbers -nv -L' - alias rlx="xrdb $HOME/.Xdefaults" - ;; - - Darwin) - alias indent='gnuindent' - alias acls='/bin/ls -le' - ;; -esac - -# NetHack options -# use color in the terminal -export NETHACKOPTIONS="color" - -[ -e $HOME/.profile-local ] && source $HOME/.profile-local - # Start SSH agent for password-less logins -if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ] -then +if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then + print_info_noisy 1 'Starting ssh-agent' eval `ssh-agent -s` trap "kill $SSH_AGENT_PID" 0 fi - -LEDGER_FILE=$HOME/Documents/Financial/personal.ledger -export LEDGER_FILE PATH diff --git a/rc b/rc index 2b0b4e2..9e95e27 100644 --- a/rc +++ b/rc @@ -3,8 +3,9 @@ # Generic interactive shell setup # Eryn Wells -. $HOME/.shell-functions +print_info_noisy 1 'Initializing interactive shell' +print_info_sub_noisy 2 'Creating aliases' alias j='jobs' alias h='history' alias df='df -h' @@ -37,16 +38,38 @@ case $SYS in alias la="$ls -A $ls_options" alias ll="$ls -l $ls_options" binary_exists gdircolors && alias dircolors='gdircolors' + alias indent='gnuindent' + alias acls='/bin/ls -le' ;; linux) alias ls="ls --color=auto" alias la="ls -A --color=auto" alias ll="ls -l --color=auto" alias l.="ls -d --color=auto .*" + # iptables aliases + alias iptls='sudo iptables --line-numbers -nv -L' + alias ip6tls='sudo ip6tables --line-numbers -nv -L' + alias rlx="xrdb $HOME/.Xdefaults" ;; *) print_error "What system %Bis%b this, anyway?" ;; esac +# Set up dircolors +if [ -e $HOME/.dircolors/$SYS.cfg ]; then + dircolors=$HOME/.dircolors/$SYS.cfg +else + dircolors=$HOME/.dircolors/default.cfg +fi +eval `dircolors $dircolors` + +# NetHack options +# use color in the terminal +export NETHACKOPTIONS="color" + +# Default ledger file +[ -e "$HOME/Documents/Financial/personal.ledger" ] && \ + LEDGER_FILE=$HOME/Documents/Financial/personal.ledger + [ -e $HOME/.rc.local ] && source $HOME/.rc.local diff --git a/shell-functions b/shell-functions index 403cd53..962fdaa 100644 --- a/shell-functions +++ b/shell-functions @@ -9,5 +9,16 @@ function print_msg { print -P "%F{$1}==>%f $2" } function print_info { print_msg 'blue' "$@" } function print_error { print_msg 'red' "$@" } +function print_msg_sub { print -P " %F{$1}*%f $2" } +function print_info_sub { print_msg_sub 'blue' "$@" } +function print_error_sub { print_msg_sub 'error' "$@" } + +# Print if $NOISY is set +function print_info_noisy { [ ${NOISY:-0} -ge $1 ] && print_info $@[2,-1] } +function print_error_noisy { [ ${NOISY:-0} -ge $1 ] && print_error $@[2,-1] } + +function print_info_sub_noisy { [ ${NOISY:-0} -ge $1 ] && print_info_sub $@[2,-1] } +function print_error_sub_noisy { [ ${NOISY:-0} -ge $1 ] && print_error_sub $@[2,-1] } + # Return 1 if the binary exists (according to hash); 0 otherwise. function binary_exists { return $(hash $1 1>/dev/null 2>&1) } diff --git a/zprofile b/zprofile index cb93fb4..bd45fbc 100644 --- a/zprofile +++ b/zprofile @@ -5,6 +5,8 @@ # # Eryn Wells +print_info_noisy 1 'Initializing login shell' + [ -e $HOME/.profile ] && source $HOME/.profile # Any ZSH stuff goes here. diff --git a/zshrc b/zshrc index 390cbfb..439e92e 100644 --- a/zshrc +++ b/zshrc @@ -25,6 +25,7 @@ else isroot="%(!.%{$fg_bold[red]%}%#%{$reset_color%}.%#)" fi +print_info_sub_noisy 2 'Setting prompt' PROMPT=" $hist $bgjob$isroot " @@ -72,6 +73,7 @@ precmd_git_rprompt() precmd_functions=(precmd_xterm_title precmd_separator_info precmd_git_rprompt) +print_info_sub_noisy 2 'Initializing ZSH' # Shell options setopt \ TRANSIENT_RPROMPT \ @@ -106,17 +108,6 @@ HISTSIZE=1000000 SAVEHIST=1000000 HISTFILE="$HOME/.zhistory" -#[ -n "$DISPLAY" ] && alias -s pdf='evince' -#[ -n "$DISPLAY" ] && alias -s dvi='evince' - -# Set up dircolors -if [ -e $HOME/.dircolors/$SYS.cfg ]; then - dircolors=$HOME/.dircolors/$SYS.cfg -else - dircolors=$HOME/.dircolors/default.cfg -fi -eval `dircolors $dircolors` - # emacs command line editing bindkey -v @@ -125,6 +116,8 @@ bindkey -v # Completion ### +print_info_sub_noisy 2 'Initializing completion' + # load completion system autoload -U compinit compinit