Make various init stages into functions in zshrc

This commit is contained in:
Eryn Wells 2012-11-29 13:26:49 -08:00
parent e63cdb9aa7
commit 6184eba778

203
zshrc
View file

@ -1,62 +1,108 @@
# .zshrc # .zshrc
# vim: ft=zsh # vim: ft=zsh fdm=marker
# #
# ZSH init for interactive shells # ZSH init for interactive shells
# #
# Eryn Wells <eryn@erynwells.me> # Eryn Wells <eryn@erynwells.me>
PROMPT_THEME='loquacious' PROMPT_THEME='loquacious'
ZLE_MODE='vim'
# load bash/zsh/ksh agnostic configurations # load bash/zsh/ksh agnostic configurations
[ -e $HOME/.rc ] && source $HOME/.rc [ -e $HOME/.rc ] && source $HOME/.rc
# Report seconds since shell was invoked in milliseconds
typeset -F SECONDS
print_info_noisy 1 "Initializing interactive Z Shell" print_info_noisy 1 "Initializing interactive Z Shell"
# Function path
function { function configure_general #{{{
{
print_info_sub_noisy 2 'Configuring general ZSH settings'
# Report seconds since shell was invoked in milliseconds
typeset -F SECONDS
print_info_sub_noisy 2 'Setting shell options'
# See zshoptions(1)
setopt EXTENDED_GLOB \
MULTIOS \
AUTO_REMOVE_SLASH \
COMPLETE_IN_WORD
} #}}}
function configure_zle #{{{
{
print_info_sub_noisy 2 'Configuring ZLE'
print_info_sub_noisy 5 "Using $ZLE_MODE command line editing mode"
[[ -z "$ZLE_MODE" ]] && ZLE_MODE='vim'
if [[ $ZLE_MODE == 'vim' ]]; then
bindkey -v
elif [[ $ZLE_MODE == 'emacs' ]]; then
bindkey -e
fi
# Allow deleting over the start of insert mode
zle -A .backward-delete-char vi-backward-delete-char
# Edit commands in $EDITOR on 'v' in command mode
autoload -Uz edit-command-line
zle -N edit-command-line
bindkey -M vicmd v edit-command-line
} #}}}
function configure_modules_and_functions #{{{
{
print_info_noisy 2 'Loading modules'
local myfpath="$HOME/.zsh/func" local myfpath="$HOME/.zsh/func"
print_info_sub_noisy 2 "Adding $myfpath to \$fpath"
fpath=($myfpath/makers $myfpath $fpath) fpath=($myfpath/makers $myfpath $fpath)
}
print_info_sub_noisy 2 "Loading vcs_info module" print_info_sub_noisy 3 'Loading vcs_info'
autoload -Uz vcs_info autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git zstyle ':vcs_info:*' enable git
load_module 'makers'
print_info_sub_noisy 3 "Loading pw module"
autoload pw
} #}}}
print_info_sub_noisy 2 "Configuring prompt: $PROMPT_THEME" function configure_prompt #{{{
autoload -U promptinit {
promptinit print_info_sub_noisy 2 "Configuring prompt: $PROMPT_THEME"
prompt $PROMPT_THEME autoload -U promptinit
promptinit
prompt $PROMPT_THEME
} #}}}
print_info_sub_noisy 2 'Setting shell options' function configure_zsh_aliases #{{{
setopt \ {
EXTENDED_GLOB \ print_info_sub_noisy 3 'Creating ZSH-specific aliases'
MULTIOS alias pd='pushd'
alias pod='popd'
#alias -g nc='netcat'
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'
} #}}}
print_info_sub_noisy 3 'Creating aliases' function configure_history #{{{
alias pd='pushd' {
alias pod='popd' print_info_sub_noisy 4 'Setting up history'
setopt \
#alias -g nc='netcat'
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'
setopt \
APPEND_HISTORY \ APPEND_HISTORY \
EXTENDED_HISTORY \ EXTENDED_HISTORY \
INC_APPEND_HISTORY \ INC_APPEND_HISTORY \
@ -66,72 +112,48 @@ setopt \
HIST_IGNORE_DUPS \ HIST_IGNORE_DUPS \
HIST_REDUCE_BLANKS HIST_REDUCE_BLANKS
HISTSIZE=1000000 HISTSIZE=1000000
SAVEHIST=1000000 SAVEHIST=1000000
HISTFILE="$HOME/.zhistory" 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
}
### function configure_completion #{{{
# Completion {
### print_info_sub_noisy 2 'Initializing completion system'
print_info_sub_noisy 2 'Initializing completion system' autoload -U compinit
compinit
# load completion system # Cache completions
autoload -U compinit zstyle ':completion::complete:*' use-cache 1
compinit zstyle ':completion::complete:*' cache-path ~/.zsh/cache
# Completion options # For rm, cp, and mv don't complete if file is on the line already
setopt \ zstyle ':completion:*:rm:*' ignore-line yes
AUTO_REMOVE_SLASH \ zstyle ':completion:*:cp:*' ignore-line yes
COMPLETE_IN_WORD zstyle ':completion:*:mv:*' ignore-line yes
# Cache completions # Remove trailing slashes in directory arguments
zstyle ':completion::complete:*' use-cache 1 zstyle ':completion:*' squeeze-slashes true
zstyle ':completion::complete:*' cache-path ~/.zsh/cache
# For rm, cp, and mv don't complete if file is on the line already # Never select parent directory
zstyle ':completion:*:rm:*' ignore-line yes zstyle ':completion:*:cd:*' ignore-parents parent pwd
zstyle ':completion:*:cp:*' ignore-line yes
zstyle ':completion:*:mv:*' ignore-line yes
# Remove trailing slashes in directory arguments # Expand partial paths
zstyle ':completion:*' squeeze-slashes true zstyle ':completion:*' expand 'yes'
# Never select parent directory # Show a pretty menu of killable processes
zstyle ':completion:*:cd:*' ignore-parents parent pwd zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:*:kill:*' menu yes select
} #}}}
# Expand partial paths
zstyle ':completion:*' expand 'yes'
# Show a pretty menu of killable processes
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:*:kill:*' menu yes select
### ###
# FUNCTIONS # FUNCTIONS
### ###
# Generate a password # Generate a password
print_info_sub_noisy 3 "Loading pw module"
autoload pw
# Maker module -- various functions for makin' stuff
print_info_sub_noisy 3 "Loading makers module"
for func in `ls $HOME/.zsh/func/makers`; do
autoload $func
done
# Go up $1 directories, where $1 is an integer (saves me from having to type ../ # Go up $1 directories, where $1 is an integer (saves me from having to type ../
# ad nauseum) # ad nauseum)
@ -148,6 +170,15 @@ function up {
fi fi
} }
configure_general
configure_zle
configure_fpath
configure_modules_and_functions
configure_zsh_aliases
configure_history
configure_completion
configure_prompt
if [ -e $HOME/.zshrc.$SYS ]; then if [ -e $HOME/.zshrc.$SYS ]; then
print_info_noisy 3 "Sourcing ${SYS}-specific Z Shell settings" print_info_noisy 3 "Sourcing ${SYS}-specific Z Shell settings"
source $HOME/.zshrc.$SYS source $HOME/.zshrc.$SYS