diff --git a/env b/env index 09f8c4d..a637661 100644 --- a/env +++ b/env @@ -1,20 +1,59 @@ # .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 +[ -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" +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 diff --git a/gitconfig b/gitconfig index 9c189a8..46db076 100644 --- a/gitconfig +++ b/gitconfig @@ -1,9 +1,9 @@ [user] - name = Eryn Wells - email = eryn@erynwells.me + name = Eryn Wells + email = eryn@erynwells.me [core] editor = vim - quotepath = false + quotepath = false [color] ui = auto [merge] @@ -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 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 97a6284..9e95e27 100644 --- a/rc +++ b/rc @@ -3,16 +3,21 @@ # 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 .*" +print_info_noisy 1 'Initializing interactive shell' + +print_info_sub_noisy 2 'Creating aliases' alias j='jobs' alias h='history' alias df='df -h' alias du='du -h' alias g='git' -alias l='ledger' +alias v='view' + +binary_exists ledger && 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 +25,51 @@ 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 binary_exists gls; 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" + 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/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 diff --git a/shell-functions b/shell-functions new file mode 100644 index 0000000..962fdaa --- /dev/null +++ b/shell-functions @@ -0,0 +1,24 @@ +#!/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' "$@" } + +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/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 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/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 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