2022-08-28 02:52:37 -07:00
|
|
|
|
# Main zsh config file
|
|
|
|
|
|
|
|
|
|
# Some utility stuff
|
|
|
|
|
autoload -U compinit && compinit
|
|
|
|
|
fpath+=("${ZSH_CONFIG_DIR}/functions")
|
|
|
|
|
ZSH_PLUGIN_DIR="${ZSH_CONFIG_DIR}/plugins"
|
|
|
|
|
# load_plugin <name>
|
|
|
|
|
function load_plugin {
|
|
|
|
|
source "${ZSH_PLUGIN_DIR}/${1}/${1}.plugin.zsh"
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-08 22:15:32 -08:00
|
|
|
|
ZSH_EARLY_LOCAL_FILE="${ZSH_CONFIG_DIR}/local-early.zsh"
|
|
|
|
|
[ -e "${ZSH_EARLY_LOCAL_FILE}" ] && source "${ZSH_EARLY_LOCAL_FILE}"
|
2022-08-28 02:52:37 -07:00
|
|
|
|
|
|
|
|
|
# Some options
|
|
|
|
|
setopt autocd extendedglob rm_star_silent
|
|
|
|
|
unsetopt beep notify
|
|
|
|
|
|
|
|
|
|
# Show which completion we are on
|
|
|
|
|
zstyle ':completion:*' menu select
|
|
|
|
|
|
|
|
|
|
# Some general, random configuration
|
|
|
|
|
# History stuff
|
|
|
|
|
[ -v HISTFILE ] || HISTFILE="${HOME}/.cache/zsh/history"
|
|
|
|
|
[ ! -d "$(dirname "${HISTFILE}")" ] && mkdir -p "$(dirname "${HISTFILE}")"
|
|
|
|
|
HISTSIZE=1000
|
|
|
|
|
SAVEHIST=10000
|
|
|
|
|
|
2022-09-26 14:46:10 -07:00
|
|
|
|
# Set some random stuff
|
2022-08-28 02:52:37 -07:00
|
|
|
|
export BROWSER=firefox
|
2022-12-01 00:01:48 -08:00
|
|
|
|
export READER=zathura
|
2022-10-30 17:52:52 -07:00
|
|
|
|
alias clip="xclip -selection clipboard"
|
2022-08-28 02:52:37 -07:00
|
|
|
|
|
2022-09-26 14:46:10 -07:00
|
|
|
|
# Neovim stuff
|
|
|
|
|
if [[ -v NVIM ]]; then
|
|
|
|
|
export EDITOR=nvr
|
|
|
|
|
alias n=nvr
|
|
|
|
|
alias nvim=nvr
|
|
|
|
|
else
|
|
|
|
|
export EDITOR=nvim
|
|
|
|
|
alias n=nvim
|
|
|
|
|
fi
|
|
|
|
|
export VISUAL="${EDITOR}"
|
2022-08-28 02:52:37 -07:00
|
|
|
|
alias se=sudoedit
|
|
|
|
|
|
|
|
|
|
# I mess this up a lot
|
|
|
|
|
alias cd..="cd .."
|
|
|
|
|
|
|
|
|
|
# Enable mouse support in less
|
|
|
|
|
export LESS="--mouse"
|
|
|
|
|
|
|
|
|
|
# Safer file functions
|
2022-12-01 07:40:17 -08:00
|
|
|
|
local rm_confirm_flag='-i'
|
|
|
|
|
uname | grep -i linux >/dev/null && rm_confirm_flag='-I'
|
|
|
|
|
alias rm="rm ${rm_confirm_flag}"
|
2022-08-28 02:52:37 -07:00
|
|
|
|
alias cp="cp -i"
|
|
|
|
|
alias mv="mv -i"
|
|
|
|
|
|
|
|
|
|
# Use vi mode
|
|
|
|
|
bindkey -v
|
|
|
|
|
# Implement a replace mode
|
|
|
|
|
bindkey -N virep viins
|
|
|
|
|
bindkey -M vicmd "R" overwrite-mode
|
|
|
|
|
function overwrite-mode {
|
|
|
|
|
zle -K virep
|
|
|
|
|
zle .overwrite-mode
|
|
|
|
|
}
|
|
|
|
|
zle -N overwrite-mode
|
|
|
|
|
|
|
|
|
|
# Bat configuration
|
|
|
|
|
if which bat >/dev/null 2>&1; then
|
|
|
|
|
# Pager
|
|
|
|
|
export PAGER="bat --paging=always"
|
|
|
|
|
|
|
|
|
|
# Less syntax highlighting in interactive shells
|
|
|
|
|
alias less="bat --paging=always"
|
|
|
|
|
|
|
|
|
|
# Use bat instead of cat
|
|
|
|
|
alias cat="bat --paging=never"
|
|
|
|
|
alias pcat="bat -pp"
|
|
|
|
|
alias ncat="bat -pp --color=never"
|
|
|
|
|
|
|
|
|
|
# Bat as man pager
|
2022-08-29 01:50:56 -07:00
|
|
|
|
export MANPAGER="zsh -c 'col -bx | bat -l man -p --paging=always'"
|
2022-08-28 02:52:37 -07:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Exa configuration
|
|
|
|
|
if which exa >/dev/null 2>&1; then
|
|
|
|
|
alias ls="exa --git -F"
|
|
|
|
|
alias la="ls -a"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Git aliases
|
|
|
|
|
alias ga="git add"
|
|
|
|
|
alias gaa="git add -A"
|
|
|
|
|
alias gco="git commit"
|
2022-11-07 14:42:44 -08:00
|
|
|
|
gcm() {
|
|
|
|
|
local args
|
|
|
|
|
for arg; do
|
|
|
|
|
args="${args} ${arg}"
|
|
|
|
|
done
|
|
|
|
|
git commit -m "${args}"
|
|
|
|
|
}
|
2022-08-28 02:52:37 -07:00
|
|
|
|
alias gca="git commit -a"
|
2022-12-01 21:33:48 -08:00
|
|
|
|
gcam() {
|
|
|
|
|
local args
|
|
|
|
|
for arg; do
|
|
|
|
|
args="${args} ${arg}"
|
|
|
|
|
done
|
|
|
|
|
git commit -am "${args}"
|
|
|
|
|
}
|
2022-08-28 02:52:37 -07:00
|
|
|
|
alias gp="git push"
|
|
|
|
|
alias gu="git pull"
|
|
|
|
|
alias gf="git fetch"
|
|
|
|
|
alias gt="git status"
|
|
|
|
|
|
|
|
|
|
# Sudo last line with <Esc><Esc>
|
|
|
|
|
sudo-command-line() {
|
|
|
|
|
[[ -z $BUFFER ]] && zle up-history
|
|
|
|
|
if [[ $BUFFER == sudo\ * ]]; then
|
|
|
|
|
LBUFFER="${LBUFFER#sudo }"
|
|
|
|
|
elif [[ $BUFFER == $EDITOR\ * ]]; then
|
|
|
|
|
LBUFFER="${LBUFFER#$EDITOR }"
|
|
|
|
|
LBUFFER="sudoedit $LBUFFER"
|
|
|
|
|
elif [[ $BUFFER == sudoedit\ * ]]; then
|
|
|
|
|
LBUFFER="${LBUFFER#sudoedit }"
|
|
|
|
|
LBUFFER="$EDITOR $LBUFFER"
|
|
|
|
|
else
|
|
|
|
|
LBUFFER="sudo $LBUFFER"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
zle -N sudo-command-line
|
2022-11-30 23:28:40 -08:00
|
|
|
|
bindkey -M vicmd "^f" sudo-command-line
|
|
|
|
|
bindkey -M viins "^f" sudo-command-line
|
2022-08-28 02:52:37 -07:00
|
|
|
|
|
|
|
|
|
# Autosuggestions
|
|
|
|
|
load_plugin zsh-autosuggestions
|
2022-12-02 10:31:48 -08:00
|
|
|
|
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
|
|
|
|
|
bindkey '^ ' autosuggest-accept
|
2022-08-28 02:52:37 -07:00
|
|
|
|
|
2022-11-30 23:28:40 -08:00
|
|
|
|
# Fancy prompt (starship)
|
|
|
|
|
eval "$(starship init zsh)"
|
2022-08-28 02:52:37 -07:00
|
|
|
|
# Change cursor shape for different vi modes.
|
2022-11-20 03:17:52 -08:00
|
|
|
|
function __zsh_vim_key_prompt_handler {
|
2022-08-28 02:52:37 -07:00
|
|
|
|
SPACESHIP_CHAR_SYMBOL="❮"
|
|
|
|
|
local _shape=0
|
|
|
|
|
case "${KEYMAP}" in
|
2022-11-30 23:28:40 -08:00
|
|
|
|
main) _shape=6 ;; # vi insert: line
|
|
|
|
|
viins) _shape=6 ;; # vi insert: line
|
2022-08-28 02:52:37 -07:00
|
|
|
|
isearch) _shape=6 ;; # inc search: line
|
|
|
|
|
virep) _shape=4 ;; # vi replace: underscore
|
|
|
|
|
command) _shape=4 ;; # read a command: underscore
|
|
|
|
|
vicmd) _shape=2 ;; # vi cmd: block
|
|
|
|
|
visual) _shape=2 ;; # vi visual mode: block
|
|
|
|
|
viopp) _shape=1 ;; # vi operation pending: blinking block
|
|
|
|
|
*) _shape=0 ;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
zle reset-prompt
|
|
|
|
|
printf '\e[%d q' "${_shape}"
|
|
|
|
|
}
|
2022-11-20 03:17:52 -08:00
|
|
|
|
function zle-keymap-select {
|
|
|
|
|
__zsh_vim_key_prompt_handler
|
|
|
|
|
}
|
2022-11-30 23:28:40 -08:00
|
|
|
|
function zle-line-init {
|
|
|
|
|
printf '\e[6 q'
|
|
|
|
|
}
|
2022-08-28 02:52:37 -07:00
|
|
|
|
zle -N zle-keymap-select
|
|
|
|
|
zle -N zle-line-init
|
|
|
|
|
|
2022-11-30 23:28:40 -08:00
|
|
|
|
# Fast switch of modes
|
|
|
|
|
KEYTIMEOUT=1
|
2022-11-20 03:17:52 -08:00
|
|
|
|
|
2022-11-21 03:22:22 -08:00
|
|
|
|
# Direnv
|
2022-11-30 23:28:40 -08:00
|
|
|
|
if which direnv >/dev/null 2>&1; then
|
|
|
|
|
eval "$(direnv hook zsh)"
|
|
|
|
|
fi
|
2022-11-21 03:22:22 -08:00
|
|
|
|
|
2022-08-28 02:52:37 -07:00
|
|
|
|
# Bookmarks
|
|
|
|
|
[ -v ZSH_BOOKMARK_DIR ] || ZSH_BOOKMARK_DIR="${HOME}/.cache/zsh/bookmarks"
|
|
|
|
|
[ -v ZSH_BOOKMARK_LS ] || ZSH_BOOKMARK_LS=true
|
|
|
|
|
source "${ZSH_CONFIG_DIR}/bookmark.zsh"
|
|
|
|
|
|
2022-12-02 10:31:48 -08:00
|
|
|
|
# Platform specific stuff
|
|
|
|
|
[ -f /usr/bin/pacman ] && source "${ZSH_CONFIG_DIR}/arch.zsh"
|
|
|
|
|
|
2022-08-28 02:52:37 -07:00
|
|
|
|
__ZSH_LOCAL_FILE="${ZSH_CONFIG_DIR}/local.zsh"
|
|
|
|
|
[ -e "${__ZSH_LOCAL_FILE}" ] && source "${__ZSH_LOCAL_FILE}"
|
|
|
|
|
|
|
|
|
|
# THE FOLLOWING PLUGINS MUST COME LAST
|
|
|
|
|
|
2022-10-03 04:07:06 -07:00
|
|
|
|
# FZF Integration
|
|
|
|
|
load_plugin fzf-tab
|
|
|
|
|
# Disable sort when completing `git checkout`
|
|
|
|
|
zstyle ':completion:*:git-checkout:*' sort false
|
|
|
|
|
# Set descriptions format to enable group support
|
|
|
|
|
zstyle ':completion:*:descriptions' format '[%d]'
|
|
|
|
|
# Set list-colors to enable filename colorizing
|
|
|
|
|
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
|
|
|
|
|
# Preview directory's content with exa when completing cd
|
|
|
|
|
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'exa -1 --color=always $realpath'
|
|
|
|
|
# Remove the '.' prefix at the start of every completion
|
|
|
|
|
zstyle ':fzf-tab:*' prefix ''
|
|
|
|
|
# Switch groups
|
|
|
|
|
zstyle ':fzf-tab:*' switch-group 'ctrl-h' 'ctrl-l'
|
|
|
|
|
# Toggle selected for all visible entries
|
|
|
|
|
zstyle ':fzf-tab:*' fzf-bindings 'ctrl-a:toggle-all'
|
|
|
|
|
|
2022-08-28 02:52:37 -07:00
|
|
|
|
# More completions
|
|
|
|
|
load_plugin zsh-completions
|
|
|
|
|
|
|
|
|
|
# Syntax highlighting
|
|
|
|
|
load_plugin zsh-syntax-highlighting
|
|
|
|
|
|
|
|
|
|
# History substring search
|
|
|
|
|
load_plugin zsh-history-substring-search
|
|
|
|
|
bindkey '^[[A' history-substring-search-up
|
|
|
|
|
bindkey '^[[B' history-substring-search-down
|
2022-11-29 20:08:19 -08:00
|
|
|
|
bindkey '^k' history-substring-search-up
|
|
|
|
|
bindkey '^j' history-substring-search-down
|
2022-08-28 02:52:37 -07:00
|
|
|
|
bindkey -M vicmd 'k' history-substring-search-up
|
|
|
|
|
bindkey -M vicmd 'j' history-substring-search-down
|
|
|
|
|
bindkey -M emacs '^P' history-substring-search-up
|
|
|
|
|
bindkey -M emacs '^N' history-substring-search-down
|
|
|
|
|
|
|
|
|
|
# Only match at the begining of the line
|
|
|
|
|
HISTORY_SUBSTRING_SEARCH_PREFIXED="true"
|
|
|
|
|
HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND=""
|
|
|
|
|
setopt histignoredups
|
|
|
|
|
|
|
|
|
|
# Clean up internal functions
|
|
|
|
|
unfunction load_plugin
|
|
|
|
|
|
|
|
|
|
# Run fortune and cowsay if we are not in nvim
|
2022-09-19 20:22:20 -07:00
|
|
|
|
[[ -v NVIM ]] || fortune | cowsay -felephant-in-snake -n
|