dotfiles/zshrc

196 lines
4.3 KiB
Bash
Raw Normal View History

2011-05-03 21:53:50 -07:00
# .zshrc
2012-04-16 12:19:58 -07:00
# vim: ft=zsh
#
# ZSH init for interactive shells
#
# Eryn Wells <eryn@erynwells.me>
2011-05-03 21:53:50 -07:00
2012-04-16 12:19:58 -07:00
# load bash/zsh/ksh agnostic configurations
2012-04-17 23:35:27 -07:00
[ -e $HOME/.rc ] && source $HOME/.rc
2012-04-16 12:19:58 -07:00
print_info_noisy 1 "Initializing interactive Z Shell"
2011-05-03 21:53:50 -07:00
# PROMPT
# ' histnum bgjobsflag time (%|#)'
# Colors are determined based on zsh capability (>= version 4.3.7)
# With elevated privilieges, % is a red #
# RPROMPT
# Hostname:Current directory to three places
2011-05-03 21:53:50 -07:00
autoload is-at-least
if (is-at-least '4.3.7'); then
bgjob="%(1j.%B%F{magenta}* %F{default}%b.)"
2012-10-01 11:34:31 -07:00
cmdstat="%(0?..%B%F{red}! %F{default}%b)"
isroot="%(!.%B%F{red}%#%F{default}%b.%#)"
2011-05-03 21:53:50 -07:00
else
bgjob="%(1j.%{$fg_bold[magenta]%}* %{$reset_color%}.)"
2012-10-01 11:34:31 -07:00
cmdstat="%(0?.%h.%{$fg_bold[red]%}%h%{$reset_color%})"
isroot="%(!.%{$fg_bold[red]%}%#%{$reset_color%}.%#)"
2011-05-03 21:53:50 -07:00
fi
print_info_sub_noisy 2 'Setting prompt'
2012-10-01 11:34:31 -07:00
PROMPT_LINE="$cmdstat$bgjob$isroot "
2011-05-03 21:53:50 -07:00
precmd_xterm_title()
2011-05-03 21:53:50 -07:00
{
# Set xterm and screen titles
[ -n $DISPLAY ] && print -Pn "\e]2;%n@%m\a"
}
2012-10-01 11:34:31 -07:00
precmd_info()
{
2012-10-01 11:34:31 -07:00
PROMPT_NAME='%B%F{magenta}%n%f%b'
PROMPT_HOST='%B%F{red}%m%f%b'
PROMPT_CWD='%B%F{green}%~%f%b'
}
2012-10-01 11:34:31 -07:00
precmd_git_prompt()
{
#local gstat=`git status 2>/dev/null`
local branch=`git branch 2>/dev/null | grep '^\*' | cut -d' ' -f2`
2012-10-01 11:34:31 -07:00
if [[ $? -eq 0 ]]; then
PROMPT_REPO="%B%F{cyan}$branch%f%b"
fi
#echo $gstat | grep '^nothing' 1>/dev/null 2>&1
#if [[ $? != 0 ]]; then
# RPROMPT="%B%F{red}*%f%b$RPROMPT"
#fi
}
2012-10-01 11:34:31 -07:00
precmd_assemble_prompt()
{
PROMPT="
$PROMPT_NAME on $PROMPT_HOST at $PROMPT_CWD on $PROMPT_REPO
$PROMPT_LINE"
}
precmd_functions=(precmd_xterm_title precmd_info precmd_git_prompt)
print_info_sub_noisy 2 'Setting options'
2011-05-03 21:53:50 -07:00
# Shell options
setopt \
TRANSIENT_RPROMPT \
EXTENDED_GLOB \
MULTIOS
print_info_sub_noisy 3 'Creating aliases'
2011-11-30 13:08:57 -08:00
alias pd='pushd'
alias pod='popd'
2011-09-14 16:51:40 -07:00
#alias -g nc='netcat'
2011-05-03 21:53:50 -07:00
alias -g lessnw='less -S'
# suffix aliases
alias -s c='vim'
alias -s tex='vim'
alias -s txt='vim'
alias -s xml='vim'
alias -s jar='java -jar'
# History settings
print_info_sub_noisy 4 'Setting up history'
2011-05-03 21:53:50 -07:00
setopt \
APPEND_HISTORY \
EXTENDED_HISTORY \
INC_APPEND_HISTORY \
HIST_FIND_NO_DUPS \
HIST_IGNORE_SPACE \
HIST_NO_STORE \
HIST_IGNORE_DUPS \
HIST_REDUCE_BLANKS
HISTSIZE=1000000
SAVEHIST=1000000
2011-05-03 21:53:50 -07:00
HISTFILE="$HOME/.zhistory"
# command line editing mode
function {
local mode='vim'
print_info_sub_noisy 5 "Using $mode command line editing mode"
if [[ $mode == 'vim' ]]; then
bindkey -v
elif [[ $mode == 'emacs' ]]; then
bindkey -e
fi
}
2011-05-03 21:53:50 -07:00
2012-04-16 12:19:58 -07:00
###
2011-05-03 21:53:50 -07:00
# Completion
2012-04-16 12:19:58 -07:00
###
2011-05-03 21:53:50 -07:00
print_info_sub_noisy 2 'Initializing completion system'
2011-05-03 21:53:50 -07:00
# load completion system
autoload -U compinit
compinit
# Completion options
setopt \
AUTO_REMOVE_SLASH \
COMPLETE_IN_WORD
# Cache completions
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path ~/.zsh/cache
# For rm, cp, and mv don't complete if file is on the line already
zstyle ':completion:*:rm:*' ignore-line yes
zstyle ':completion:*:cp:*' ignore-line yes
zstyle ':completion:*:mv:*' ignore-line yes
# Remove trailing slashes in directory arguments
zstyle ':completion:*' squeeze-slashes true
# Never select parent directory
zstyle ':completion:*:cd:*' ignore-parents parent pwd
# Expand partial paths
zstyle ':completion:*' expand 'yes'
###
# FUNCTIONS
###
# function path
fpath=($HOME/.zsh/func $fpath)
# Wikipedia lookup, courtesy of msanders@github
autoload wiki
2012-04-16 12:19:58 -07:00
# Make a Maildir
2011-05-03 21:53:50 -07:00
autoload mkmdir
2012-04-16 12:19:58 -07:00
# Generate a password
2011-05-03 21:53:50 -07:00
autoload pw
2012-04-16 12:19:58 -07:00
# Make a C module (.c and .h pair)
2011-05-03 21:53:50 -07:00
autoload mkcmod
2011-12-18 22:51:02 -08:00
# Go up $1 directories, where $1 is an integer (saves me from having to type ../
# ad nauseum)
2011-09-14 16:50:33 -07:00
function up {
if [[ -z $1 ]]; then
pushd ..
else
2011-12-18 22:51:02 -08:00
local updir=''
for (( i=0; $i < $1; i++ ))
do
updir="../$updir"
done
pushd $updir
2011-09-14 16:50:33 -07:00
fi
}
if [ -e $HOME/.zshrc.$SYS ]; then
print_info_noisy 3 "Sourcing ${SYS}-specific Z Shell settings"
source $HOME/.zshrc.$SYS
fi
if [ -e $HOME/.zshrc.local ]; then
print_info_noisy 3 "Sourcing local Z Shell settings"
source $HOME/.zshrc.local
fi
2012-10-01 11:34:31 -07:00
# Put this down here 'cause some of the local stuff might modify the prompt or
# add functions to $precmd_functions. Doing this here ensures it's always the
# last function to be executed before the prompt is displayed.
precmd_functions+=(precmd_assemble_prompt)