tb-dotfiles/chezmoi/dot_zshrc
2022-05-17 15:58:04 -04:00

142 lines
3.3 KiB
Bash

#!/usr/bin/zsh
zmodload zsh/datetime
# load the stat module but only with the `zstat` command
# leave `stat` to the system's stat command
zmodload -F zsh/stat b:zstat
autoload -Uz \
colors \
compinit \
select-word-style \
vcs_info \
zcalc
# make control w remove by word better
select-word-style bash
compinit
colors
autoload -Uz bashcompinit
bashcompinit
setopt \
ALWAYS_TO_END \
INC_APPEND_HISTORY \
AUTO_CD \
AUTO_PUSHD \
BEEP \
COMPLETE_IN_WORD \
EXTENDED_GLOB \
EXTENDED_HISTORY \
HIST_IGNORE_DUPS \
HIST_IGNORE_SPACE \
HIST_REDUCE_BLANKS \
HIST_VERIFY \
INTERACTIVE_COMMENTS \
LONG_LIST_JOBS \
NOTIFY \
NULL_GLOB \
PROMPT_SUBST \
PUSHD_IGNORE_DUPS \
PUSHD_MINUS \
SHARE_HISTORY
NEWLINE=$'\n'
PS_SEPARATOR=" > "
function precmd() {
vcs_info
vcs_info_hookadd set-message vcs_test_hook
}
VCS_ROOT_DIR=''
function +vi-git-vcs-set-message-hook() {
VCS_ROOT_DIR="${hook_com[base]}"
if [ -z "$VCS_ROOT_DIR" ]; then
return
fi
if [[ "${VCS_ROOT_DIR:0:${#HOME}}" = "${HOME}" ]]; then
VCS_ROOT_DIR="~${VCS_ROOT_DIR:${#HOME}}"
fi
hook_com[misc]="$(2> /dev/null git status --short | awk '{counts[$1]++} END {
printed = "";
for (count_type in counts) {
printf "%s%%B%s%%b%d", printed, substr(count_type, 1, 1), counts[count_type];
printed = " ";
}
}')"
}
zstyle ':vcs_info:git*' formats "%F{green}%b%f %m${PS_SEPARATOR}"
zstyle ':vcs_info:git*' actionformats "%F{green}%b%f %K{red}%F{white}(%a)%f%k %B%m%%b${PS_SEPARATOR}"
zstyle ':vcs_info:git*+set-message:*' hooks git-vcs-set-message-hook
function pretty_pwd() {
local CURRENT_DIRECTORY="$PWD"
if [[ "${CURRENT_DIRECTORY:0:${#HOME}}" = "${HOME}" ]]; then
CURRENT_DIRECTORY="~${CURRENT_DIRECTORY:${#HOME}}"
fi
if [ -n "$VCS_ROOT_DIR" ] && [[ "${CURRENT_DIRECTORY:0:${#VCS_ROOT_DIR}}" = "${VCS_ROOT_DIR}" ]]; then
local VCS_ROOT_DIR_BASENAME="${VCS_ROOT_DIR##*/}"
local VCS_ROOT_DIR_BASENAME_COLORIZED='%B${VCS_ROOT_DIR_BASENAME}%b'
local COLORIZED_VCS_ROOT_DIR="${VCS_ROOT_DIR/%${VCS_ROOT_DIR_BASENAME}/${VCS_ROOT_DIR_BASENAME_COLORIZED}}"
CURRENT_DIRECTORY="${COLORIZED_VCS_ROOT_DIR}${CURRENT_DIRECTORY:${#VCS_ROOT_DIR}}"
fi
print -P "%F{blue}${CURRENT_DIRECTORY}%f"
}
function ps1_ssh() {
if [ -z "$SSH_CONNECTION" ]; then
return
fi
echo "SSH from ${SSH_CONNECTION%% *}${PS_SEPARATOR}"
}
function ps1_weather() {
if ! weather_check_requirements; then
return
fi
local OUTPUT
OUTPUT="$(weather_short_status)"
echo "${OUTPUT//\%/%%} "
}
export PS1="%(?..%K{red}%F{white}%?%f%k${PS_SEPARATOR})\$(pretty_pwd)${PS_SEPARATOR}\${vcs_info_msg_0_}%F{${color[grey]:-white}}%*%f${NEWLINE}%(!.%F{red}#.%F{yellow}\$)%f "
export RPS1="%F{${color[grey]:-white}}\$(ps1_weather)\$(ps1_ssh)%n@%m%f"
HISTFILE="${HOME}/.histfile"
HISTSIZE=10485760
SAVEHIST=10485760
bindkey '^R' history-incremental-search-backward
bindkey -e
zstyle ':completion:*' menu select
# case-insensitive,partial-word and then substring completion
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
bindkey '^[[Z' reverse-menu-complete
export TERM='xterm-256color'
ZSH_COMPLETIONS_DIR="${HOME}/.zcompletions"
mkdir -p "$ZSH_COMPLETIONS_DIR"
fpath=("$ZSH_COMPLETIONS_DIR" $fpath)
# load any file that ends with .zsh or .sh and is executable
for SCRIPT in "${HOME}/.zshrc.d"/**/(.|?)*(.zsh|.sh); do
if ! [ -x "${SCRIPT}" ]; then
continue
fi
source "${SCRIPT}"
done
compinit
bashcompinit