Zsh: refactor rcfile functions

This commit is contained in:
Henrik Lissner 2014-09-05 16:54:15 -04:00
parent 77c38bed2a
commit 62a6fd9cea
4 changed files with 15 additions and 24 deletions

View file

@ -3,12 +3,6 @@
# Browser
[[ "$OSTYPE" == darwin* ]] && export BROWSER='open'
# Reset PATH to keep it from being clobbered in tmux
if [ -x /usr/libexec/path_helper ]; then
PATH=''
source /etc/zshenv
fi
## Editors
export EDITOR='vim'
export VISUAL='vim'
@ -28,20 +22,21 @@ typeset -gU cdpath fpath mailpath path
path=(
$HOME/.{py,rb}env/bin
$HOME/.dotfiles/bin
$HOME/.dotfiles/bin/`hostname`
/usr/local/{bin,sbin}
$path
/usr/{bin,sbin}
/{bin,sbin}
)
[[ "$OSTYPE" == darwin* ]] && path+="/usr/X11/bin"
fpath=(
$HOME/.zsh/themes
$HOME/.zsh/functions
$fpath
)
# Set the default Less options.
# Mouse-wheel scrolling has been disabled by -X (disable screen clearing).
# Remove -X and -F (exit if the content fits on one screen) to enable it.
export LESS='-F -g -i -M -R -S -w -X -z-4'
export LESS='-X -F -g -i -M -R -S -w -z-4'
# Set the Less input preprocessor.
if (( $+commands[lesspipe.sh] )); then

View file

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

View file

@ -11,23 +11,23 @@ if [ ! -z "$SSH_CLIENT" ]; then
_prompt_my_host=" %B%F{blue}| $(hostname | sed -e 's/\.local$//')%f%b"
fi
function prompt_my_pwd {
function _prompt_my_pwd {
local pwd="${PWD/#$HOME/~}"
if [[ "$pwd" == (#m)[/~] ]]; then
_prompt_my_pwd="$MATCH"
__prompt_my_pwd="$MATCH"
unset MATCH
else
_prompt_my_pwd="${${${(@j:/:M)${(@s:/:)pwd}##.#?}:h}%/}/${pwd:t}"
__prompt_my_pwd="${${${(@j:/:M)${(@s:/:)pwd}##.#?}:h}%/}/${pwd:t}"
fi
}
function prompt_my_precmd {
function _prompt_my_precmd {
setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS
# Format PWD.
prompt_my_pwd
_prompt_my_pwd
# Get Git repository information.
if (( $+functions[git-info] )); then
@ -44,7 +44,7 @@ function prompt_my_setup {
autoload -Uz add-zsh-hook
# Add hook for calling git-info before each command.
add-zsh-hook precmd prompt_my_precmd
add-zsh-hook precmd _prompt_my_precmd
# Set editor-info parameters.
zstyle ':prezto:module:editor:info:completing' format '%B%F{red}...%f%b'
@ -72,7 +72,7 @@ function prompt_my_setup {
'rprompt' '%A%B%S%a%d%m%r%U%u'
# Define prompts.
PROMPT='%F{cyan}${_prompt_my_pwd}%f${git_info:+${(e)git_info[prompt]}}%(!. %B%F{red}#%f%b.)${editor_info[keymap]} '
PROMPT='%F{cyan}${__prompt_my_pwd}%f${git_info:+${(e)git_info[prompt]}}%(!. %B%F{red}#%f%b.)${editor_info[keymap]} '
RPROMPT='${editor_info[overwrite]}%(?:: %F{red}⏎%f)${VIM:+" %B%F{green}V%f%b"}${git_info[rprompt]}${_prompt_my_host}'
# SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
}

8
zshrc
View file

@ -1,9 +1,3 @@
#!/bin/zsh
function command_exists {
command -v "$1" &> /dev/null
}
# Source Prezto.
if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
source ~/.zsh/preztorc
@ -11,8 +5,8 @@ if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
fi
# Source component rcfiles
source ~/.zsh/aliases
source ~/.zsh/config
source ~/.zsh/aliases
# Init extra niceties
command_exists "fasd" && eval "$(fasd --init auto)"