Refactor zsh rcfiles

This commit is contained in:
Henrik Lissner 2014-09-20 16:38:40 -04:00
parent 25e019ab29
commit 2965548549
7 changed files with 54 additions and 105 deletions

View file

@ -1,7 +1,5 @@
# Executes commands at login pre-zshrc.
autoload -Uz command_exists
# Browser
[[ "$OSTYPE" == darwin* ]] && export BROWSER='open'
@ -22,7 +20,6 @@ typeset -gU cdpath fpath mailpath path
# Set the list of directories that Zsh searches for programs.
path=(
$HOME/.{py,rb}env/shims
$HOME/.{py,rb}env/bin
$HOME/.dotfiles/bin
/usr/local/{bin,sbin}
@ -54,18 +51,3 @@ fi
TMPPREFIX="${TMPDIR%/}/zsh"
[[ ! -d "$TMPPREFIX" ]] && mkdir -p "$TMPPREFIX"
# Init extra niceties
command_exists "rbenv" && eval "$(rbenv init - --no-rehash)"
if command_exists "pyenv"; then
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
fi
if command_exists "go"; then
export GOPATH="$HOME/Dropbox/Projects/dev/go"
export PATH="$GOPATH/bin:$PATH"
fi
if [ -n "$EMACS" ]; then
source ~/.zsh/aliases
fi

View file

@ -1,75 +1,14 @@
#!/bin/zsh
# ZSH-specific aliases. Find the rest in ~/.bash/aliases
source ~/.bash/aliases
# GIT
if command_exists 'git'; then
alias gi='git init'
alias ga='git add'
alias gap='git add --patch'
alias gt='git tag'
alias gtl='git describe --tags --abbrev=0'
git-move-root() {
git filter-branch --subdirectory-filter "$@" --prune-empty -- --all
}
git-undo-commit() {
git reset --soft "HEAD^"
}
fi
# Tmux
if command_exists 'tmux'; then
alias t='tmux new -s x || tmux attach -t x'
alias tl='tmux list-sessions'
alias ts='tmux switch'
function tmux-send {
tmux send-keys -s "x" $1 Enter
}
fi
# OS-specific aliases
if [[ "$OSTYPE" == darwin* ]]; then
alias codekit='open -a CodeKit'
alias b='brew'
alias v='vim'
alias e="emacsclient -n" # Emacs server must be running!
else
alias ipt='sudo iptables'
fi
# transmission-remote
if command_exists 'transmission-remote'; then
alias bt="transmission-remote server"
alias btl="bt -l"
alias bta="bt --add"
btr() { bt -t$1 -r }
bts() { bt -t$1 -S }
fi
alias va='vagrant'
alias r='noglob rake -g'
# Interpreters
alias rbe='rbenv'
alias rb='ruby'
alias pye='pyenv'
alias py='python'
alias be='bundle exec'
[ -e /Applications/love.app ] && alias love="/Applications/love.app/Contents/MacOS/love"
# Shell conveniences
alias wget='wget -c' # Resume download if possible
alias ls=' ls -G' # Hide from history
alias ag='nocorrect noglob ag'
alias rk='noglob rake'
alias rkg='noglob rake -g'
alias rename='noglob rename'
zman() {
PAGER="less -g -s '+/^ "$1"'" man zshall
}
# Make a directory and change to it
function mkd { mkdir "$@" && cd "$@" }
alias q='exit'
alias clr='clear'

View file

@ -1,3 +1,5 @@
export GIT_MERGE_AUTOEDIT=no
# Disable autocorrect behavior, very annoying!
# unsetopt correct_all

View file

@ -1,2 +0,0 @@
# Detect if a command exists
command -v "$1" &> /dev/null

View file

@ -18,21 +18,30 @@ zstyle ':prezto:*:*' color 'yes'
# Set the Prezto modules to load (browse modules).
# The order matters.
zstyle ':prezto:load' pmodule \
'environment' \
'terminal' \
'editor' \
'opp' \
'history' \
'history-substring-search' \
'directory' \
'spectrum' \
'utility' \
'completion' \
'prompt' \
'git' \
'syntax-highlighting' \
'osx'
if [[ -z "$EMACS" ]]; then
zstyle ':prezto:load' pmodule \
'environment' \
'terminal' \
'editor' \
'opp' \
'history' \
'history-substring-search' \
'directory' \
'spectrum' \
'utility' \
'completion' \
'prompt' \
'syntax-highlighting' \
'osx'
else
zstyle ':prezto:load' pmodule \
'environment' \
'history' \
'directory' \
'spectrum' \
'utility' \
'osx'
fi
# Editor

4
zshenv
View file

@ -2,3 +2,7 @@
if [[ "$SHLVL" -eq 1 && ! -o LOGIN && -s "${ZDOTDIR:-$HOME}/.zprofile" ]]; then
source "${ZDOTDIR:-$HOME}/.zprofile"
fi
if [[ -n "$EMACS" ]]; then
source "${ZDOTDIR:-$HOME}/.zshrc"
fi

19
zshrc
View file

@ -5,8 +5,23 @@ if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
fi
# Source component rcfiles
source ~/.zsh/config
if [[ -z "$EMACS" ]]; then
source ~/.zsh/config
is-callable 'fasd' && eval "$(fasd --init auto)"
fi
source ~/.zsh/aliases
# Init extra niceties
command_exists "fasd" && eval "$(fasd --init auto)"
is-callable 'rbenv' && eval "$(rbenv init - --no-rehash)"
if is-callable 'pyenv'; then
eval "$(pyenv init - --no-rehash)"
eval "$(pyenv virtualenv-init -)"
fi
if is-callable 'go'; then
export GOPATH="$HOME/Dropbox/Projects/dev/go"
export PATH="$GOPATH/bin:$PATH"
fi
# Restore git completion with g()
compdef g=git