Zsh: refactor rcfile functions
This commit is contained in:
parent
77c38bed2a
commit
62a6fd9cea
15
zprofile
15
zprofile
|
@ -3,12 +3,6 @@
|
||||||
# Browser
|
# Browser
|
||||||
[[ "$OSTYPE" == darwin* ]] && export BROWSER='open'
|
[[ "$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
|
## Editors
|
||||||
export EDITOR='vim'
|
export EDITOR='vim'
|
||||||
export VISUAL='vim'
|
export VISUAL='vim'
|
||||||
|
@ -28,20 +22,21 @@ typeset -gU cdpath fpath mailpath path
|
||||||
path=(
|
path=(
|
||||||
$HOME/.{py,rb}env/bin
|
$HOME/.{py,rb}env/bin
|
||||||
$HOME/.dotfiles/bin
|
$HOME/.dotfiles/bin
|
||||||
$HOME/.dotfiles/bin/`hostname`
|
|
||||||
/usr/local/{bin,sbin}
|
/usr/local/{bin,sbin}
|
||||||
$path
|
/usr/{bin,sbin}
|
||||||
|
/{bin,sbin}
|
||||||
)
|
)
|
||||||
|
[[ "$OSTYPE" == darwin* ]] && path+="/usr/X11/bin"
|
||||||
|
|
||||||
fpath=(
|
fpath=(
|
||||||
$HOME/.zsh/themes
|
$HOME/.zsh/functions
|
||||||
$fpath
|
$fpath
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set the default Less options.
|
# Set the default Less options.
|
||||||
# Mouse-wheel scrolling has been disabled by -X (disable screen clearing).
|
# 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.
|
# 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.
|
# Set the Less input preprocessor.
|
||||||
if (( $+commands[lesspipe.sh] )); then
|
if (( $+commands[lesspipe.sh] )); then
|
||||||
|
|
2
zsh/functions/command_exists
Normal file
2
zsh/functions/command_exists
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# Detect if a command exists
|
||||||
|
command -v "$1" &> /dev/null
|
|
@ -11,23 +11,23 @@ if [ ! -z "$SSH_CLIENT" ]; then
|
||||||
_prompt_my_host=" %B%F{blue}| $(hostname | sed -e 's/\.local$//')%f%b"
|
_prompt_my_host=" %B%F{blue}| $(hostname | sed -e 's/\.local$//')%f%b"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function prompt_my_pwd {
|
function _prompt_my_pwd {
|
||||||
local pwd="${PWD/#$HOME/~}"
|
local pwd="${PWD/#$HOME/~}"
|
||||||
|
|
||||||
if [[ "$pwd" == (#m)[/~] ]]; then
|
if [[ "$pwd" == (#m)[/~] ]]; then
|
||||||
_prompt_my_pwd="$MATCH"
|
__prompt_my_pwd="$MATCH"
|
||||||
unset MATCH
|
unset MATCH
|
||||||
else
|
else
|
||||||
_prompt_my_pwd="${${${(@j:/:M)${(@s:/:)pwd}##.#?}:h}%/}/${pwd:t}"
|
__prompt_my_pwd="${${${(@j:/:M)${(@s:/:)pwd}##.#?}:h}%/}/${pwd:t}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function prompt_my_precmd {
|
function _prompt_my_precmd {
|
||||||
setopt LOCAL_OPTIONS
|
setopt LOCAL_OPTIONS
|
||||||
unsetopt XTRACE KSH_ARRAYS
|
unsetopt XTRACE KSH_ARRAYS
|
||||||
|
|
||||||
# Format PWD.
|
# Format PWD.
|
||||||
prompt_my_pwd
|
_prompt_my_pwd
|
||||||
|
|
||||||
# Get Git repository information.
|
# Get Git repository information.
|
||||||
if (( $+functions[git-info] )); then
|
if (( $+functions[git-info] )); then
|
||||||
|
@ -44,7 +44,7 @@ function prompt_my_setup {
|
||||||
autoload -Uz add-zsh-hook
|
autoload -Uz add-zsh-hook
|
||||||
|
|
||||||
# Add hook for calling git-info before each command.
|
# 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.
|
# Set editor-info parameters.
|
||||||
zstyle ':prezto:module:editor:info:completing' format '%B%F{red}...%f%b'
|
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'
|
'rprompt' '%A%B%S%a%d%m%r%U%u'
|
||||||
|
|
||||||
# Define prompts.
|
# 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}'
|
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]? '
|
# SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
|
||||||
}
|
}
|
8
zshrc
8
zshrc
|
@ -1,9 +1,3 @@
|
||||||
#!/bin/zsh
|
|
||||||
|
|
||||||
function command_exists {
|
|
||||||
command -v "$1" &> /dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
# Source Prezto.
|
# Source Prezto.
|
||||||
if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
|
if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
|
||||||
source ~/.zsh/preztorc
|
source ~/.zsh/preztorc
|
||||||
|
@ -11,8 +5,8 @@ if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Source component rcfiles
|
# Source component rcfiles
|
||||||
source ~/.zsh/aliases
|
|
||||||
source ~/.zsh/config
|
source ~/.zsh/config
|
||||||
|
source ~/.zsh/aliases
|
||||||
|
|
||||||
# Init extra niceties
|
# Init extra niceties
|
||||||
command_exists "fasd" && eval "$(fasd --init auto)"
|
command_exists "fasd" && eval "$(fasd --init auto)"
|
||||||
|
|
Loading…
Reference in a new issue