zsh/zshrc

113 lines
3.4 KiB
Bash

# if using zgen must do 'zgen reset' after any changes to this file
emulate sh
source "${HOME}/.profile"
emulate zsh
autoload -Uz compinit
autoload -Uz colors
typeset -i updated_at=$(date +'%j' -r ~/.zcompdump 2>/dev/null || stat -f '%Sm' -t '%j' ~/.zcompdump 2>/dev/null)
if [ $(date +'%j') != $updated_at ]; then
compinit -i
else
compinit -C -i
fi
# https://wiki.archlinux.org/index.php/Zsh#xterm_title
autoload -Uz add-zsh-hook
function xterm_title_precmd () {
print -Pn -- '\e]2;%n@%m %~\a'
[[ "$TERM" == 'screen'* ]] && print -Pn -- '\e_\005{g}%n\005{-}@\005{m}%m\005{-} \005{B}%~\005{-}\e\\'
}
function xterm_title_preexec () {
print -Pn -- '\e]2;%n@%m %~ %# ' && print -n -- "${(q)1}\a"
[[ "$TERM" == 'screen'* ]] && { print -Pn -- '\e_\005{g}%n\005{-}@\005{m}%m\005{-} \005{B}%~\005{-} %# ' && print -n -- "${(q)1}\e\\"; }
}
if [[ "$TERM" == (alacritty*|gnome*|konsole*|putty*|rxvt*|screen*|tmux*|xterm*) ]]; then
add-zsh-hook -Uz precmd xterm_title_precmd
add-zsh-hook -Uz preexec xterm_title_preexec
fi
# zgen
# https://github.com/tarjoilija/zgen
# after changes must do:
# zgen reset
# to remove static init script
source "${HOME}/.config/zsh/zgen/zgen.zsh"
# if the init script doesn't exist
if ! zgen saved; then
# specify plugins here
zgen load denysdovhan/spaceship-prompt spaceship
zgen load zdharma/fast-syntax-highlighting
zgen load zsh-users/zsh-autosuggestions
zgen load zsh-users/zsh-history-substring-search
zgen load zsh-users/zsh-completions
zgen load wbingli/zsh-wakatime
zgen load supercrabtree/k
# generate the init script from plugins above
zgen save
fi
# HISTFILE=~/.histfile
# HISTSIZE=10000
# SAVEHIST=$HISTSIZE
setopt hist_ignore_all_dups # remove older duplicate entries from history
setopt hist_reduce_blanks # remove superfluous blanks from history items
setopt inc_append_history # save history entries as soon as they are entered
setopt share_history # share history between different instances of the shell
setopt auto_cd # cd by typing directory name if it's not a command
setopt correct_all # autocorrect commands
setopt auto_list # automatically list choices on ambiguous completion
setopt auto_menu # automatically use menu completion
setopt always_to_end # move cursor to end if word had one match
unsetopt BEEP
zstyle ':completion:*' menu select # select completions with arrow keys
zstyle ':completion:*' group-name '' # group results by category
zstyle ':completion:::::' completer _expand _complete _ignored _approximate # enable approximate matches
# use emacs style keymaps (ctrl+a, ctrl+e, etc)
bindkey -e
# The following line was added by compinstall
zstyle :compinstall filename '/home/ray/.zshrc'
zmodload -i zsh/complist
zstyle ':completion:*' menu select
zmodload zsh/complist
# use the vi navigation keys in menu completion
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -M menuselect 'j' vi-down-line-or-history
# zsh-history-subsrting-search settings
HISTORY_SUBSTRING_SEARCH_FUZZY=true
bindkey '^p' history-substring-search-up
bindkey '^n' history-substring-search-down
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=239'
#zsh-autosuggestion settings
bindkey '^f' autosuggest-accept
alias todone='task_done'
# remove duplicate PATH entries
# https://til.hashrocket.com/posts/7evpdebn7g-remove-duplicates-in-zsh-path
typeset -aU path
export STARSHIP_CONFIG=~/.config/starship/starship.toml