rc/zshrc
2020-12-23 16:46:18 +01:00

244 lines
8.2 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# zshrc originaly inspired by ECP VIA's debian course file,
# and David_5-1's numerous improvements
#
# Regularly improved and tweaked by lhark since 2015
#
# Uses the following plugins:
# https://github.com/zsh-users/zsh-syntax-highlighting
# https://github.com/zsh-users/zsh-autosuggestions
# Uncomment this line for perfomance analysis
#zmodload zsh/zprof
export PATH="$PATH:/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/sbin"
# Get rc dir path
#RC_PATH=$(dirname "$(readlink -f ${(%):-%x})")
# https://stackoverflow.com/questions/9901210/bash-source0-equivalent-in-zsh#comment45012039_23259585
RC_PATH=$(dirname "$(realpath -- "${(%):-%x}")")
export PATH="$PATH:$RC_PATH/bin:~/bin:/opt/cuda/bin:~/.cargo/bin:~/go/bin"
# Add ruby gems to path
if which ruby >/dev/null && which gem >/dev/null; then
PATH="$(ruby -r rubygems -e 'puts Gem.user_dir')/bin:$PATH"
fi
# Add emscripten to path
if [ -d "$HOME/emsdk" ]; then
PATH="$PATH:~/emsdk:~/emsdk/node/12.9.1_64bit/bin:~/emsdk/fastcomp/emscripten" #:~/emsdk/fastcomp/emscripten/tools"
fi
export BROWSER='/usr/bin/w3m -T "text/html"'
if which nvim > /dev/null 2>&1; then
export EDITOR=/usr/bin/nvim
else
export EDITOR=/usr/bin/vim
fi
# Disable `less` history file
export LESSHISTFILE='/dev/null'
export GPG_TTY="$(tty)"
# Prevent mime associations by wine
export WINEPREFIX="$HOME/.wine"
export WINEDLLOVERRIDES="winemenubuilder.exe=d"
export CUDA_ROOT=/opt/cuda
# Android SDK setup
export ANDROID_HOME="/opt/android-sdk"
export PATH="$PATH:$ANDROID_HOME/tools/bin:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools"
# Use Wayland when available
export MOZ_ENABLE_WAYLAND=1
# Configuration for virtualenv
export WORKON_HOME=$HOME/.virtualenvs
source /usr/bin/virtualenvwrapper_lazy.sh > /dev/null 2>&1
# disables prompt mangling in virtual_env/bin/activate
export VIRTUAL_ENV_DISABLE_PROMPT=1
# Configuration for ROS
source /opt/ros/indigo/setup.zsh > /dev/null 2>&1
export PYTHONPATH=/opt/ros/indigo/lib/python2.7/site-packages:$PYTHONPATH
export PKG_CONFIG_PATH="/opt/ros/indigo/lib/pkgconfig:$PKG_CONFIG_PATH"
# Import utility functions
# Colors needed for the prompt definition
autoload -U colors
colors
. "$RC_PATH/functions"
. "$RC_PATH/aliases"
. "$RC_PATH/prompt"
# Detect if we have GNU coreutils or BSD
if date --version > /dev/null 2>&1 ;then
# Setup colors for GNU ls
eval "$(dircolors -b)"
fi
# Check for rc updates in the background
(check_rc_update&) 2> /dev/null
# Check for system updates inthe background
(check_sys_update&) 2> /dev/null
# Term specific hacks
case $TERM in
*kitty)
preexec () {
print -n "\e]0;kitty - $1 - ${HOST} - ${PWD}\a"
}
alias ssh='ssh_kitty'
;;
xterm*)
preexec () {
print -n "\e]0;xterm - $1 - ${HOST} - ${PWD}\a"
}
;;
# Fix broken ssh with st
st*)
preexec () {
print -n "\e]0;st - $1 - ${HOST} - ${PWD}\a"
}
alias ssh='TERM=xterm ssh -A'
;;
esac
# Prevent CTRL-S from locking the terminal
stty -ixon
###############
# ZSH options #
###############
# man zshoptions
unsetopt rm_star_silent # Ask before running 'rm *' or 'rm path/*'
unsetopt promptsubst # ZLE is handling prompt recalculation
setopt clobber # Allow file overwrite with > instead of >|
setopt chase_links # cd resolves symbolic links
setopt hist_verify # check the result of !! before executing
setopt hist_ignore_all_dups # Only keep last version of duplicate command
setopt sharehistory # Import new cmds from hist file & append typed cmds
setopt hist_ignore_space # Ignore cmds with leading space
setopt autopushd # cd pushes old dir to dir stack
setopt pushdsilent # Silent pushd & popd
setopt pushdtohome # pushd = pushd $HOME
setopt pushdignoredups
setopt pushdminus # This reverts the +/- operators for pushd.
setopt nobeep # Beeps are a pain
EXPORTTIME=0 # (Disabled) Display command execution time
HISTSIZE=10000000
SAVEHIST=10000000
HISTFILE=~/.history
HISTTIMEFORMAT="%d/%m %H:%M:%S "
######################
# Load ZSH functions #
######################
zmodload zsh/complist
autoload -U compinit promptinit
compinit
colors
autoload -U zsh-mime-setup
######################
# Completion options #
######################
unsetopt glob_dots # (disabled) Do not require a leading '.' in a filename to be matched explicitly.
setopt auto_remove_slash # Auto remove slash at the end of autocomp when appropriate
setopt complete_in_word # If the cursor is inside a word, completion is done from both ends
setopt extended_glob # Treat '#', '~' and '^' chars as part of patterns for filenames, etc.
setopt glob_complete # When the current word has a glob pattern, do not insert all the words resulting from the expansion
unsetopt null_glob # Error when no glob match found, instead of deleting
# man zshmodules (zstyle)
# man zshcompsys (styles)
# man zshcompwid (COMPLETION MATCHING CONTROL)
#zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}'
# Max errors allowed while attempting completion
zstyle ':completion:*' max-errors 3 numeric
# Disable legacy completion
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' auto-description 'specify: %d'
#zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' completer _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
# Start menu style completion if there are more than 2 matches
zstyle ':completion:*' menu select=2
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors "=(#b) #([0-9]#)*=36=31"
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' verbose true
# Add colors to the completion menu, eg. kill -9 <tab><tab>
zstyle ':completion:*:*:kill:*:processes' list-colors "=(#b) #([0-9]#)*=36=31"
zstyle ':completion:*:processes' command 'ps -au$USER -o pid,time,cmd|grep -v "ps -au$USER -o pid,time,cmd"'
# Separate man page sections. Neat.
zstyle ':completion:*:manuals' separate-sections true
# Create completions cache
# Useful for slow completions like with package managers
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zs
# Enable ssh completion for kitty ssh
compdef ssh_kitty=ssh
################
# Prompt setup #
################
autoload -Uz vcs_info
promptinit
# Set timeout to 0.1s for switching to normal mode (might interfere with other apps)
export KEYTIMEOUT=1
zle -N zle-line-init
zle -N zle-keymap-select
##################
# Keyboard setup #
##################
bindkey -v # Vim type keybinds for ZLE (line editing)
# Handling of special keys
# CTRL+V then press the key to display the code
typeset -A key
# CTRL + arrows keys
bindkey ";5D" beginning-of-line
bindkey ";5C" end-of-line
bindkey ";5A" up-line-or-history
bindkey ";5B" down-line-or-history
bindkey "^[[1;5D" beginning-of-line
bindkey "^[[1;5C" end-of-line
# Vim style incremental search
bindkey -M vicmd "/" history-incremental-search-backward
bindkey -M vicmd "?" history-incremental-search-forward
# Push the current command to the stack. ZLE will pop it on the next prompt
bindkey -M vicmd "q" push-line
# Page Up/Down
bindkey "^[[5~" history-beginning-search-backward
bindkey "^[[6~" history-beginning-search-forward
# CTRL + Page UP/Down
bindkey "^[[5;5~" beginning-of-buffer-or-history
bindkey "^[[6;5~" end-of-buffer-or-history
# Begin / End (numpad)
bindkey "^[[H" beginning-of-line
bindkey "^[[4~" end-of-line
# Begin / End
bindkey "^[OH" beginning-of-line
bindkey "^[OF" end-of-line
bindkey "^[[F" end-of-line
# Delete
bindkey "[3~" delete-char
# Shift-Tab
bindkey "^[[Z" reverse-menu-complete
ZSH_AUTOSUGGEST_STRATEGY=(history)
source "${RC_PATH}/zsh-autosuggestions/zsh-autosuggestions.zsh"
# ZSH syntax highlighting : /!\ keep at the bottom !
source "${RC_PATH}/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh"