zsh/zshrc
Kenneth Benzie (Benie) 0ab04406ec Fix macOS PATH being rewritten in /etc/zprofile
macOS is obnoxious and overwrites the PATH from a users ~/.zshenv, which is
sourced first, in /etc/zprofile by calling `/usr/libexec/path_helper -s` so
this is required so that PATH is once again set to the desired value.
2018-08-26 20:19:12 +01:00

187 lines
4.7 KiB
Bash

# .zshrc [2] Used for setting user's interactive shell configuration and
# executing commands, will be sourced when starting as an interactive shell.
# Load plugin scripts
source-plugin() {
if [ -d ~/.config/zsh/$1 ]; then
source ~/.config/zsh/$1/$1.plugin.zsh
else
echo "zsh plugin not found: $1"
fi
}
# Fish like automatic suggestions from command history
source-plugin zsh-autosuggestions
# Disable non end-of-line autosuggest accept widgets
ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(end-of-line vi-end-of-line)
# Search history with a command substring
source-plugin zsh-history-substring-search
# Command syntax highlighting
source-plugin fast-syntax-highlighting
fast-theme -q ~/.config/zsh/fresh.ini
# Automatically source .enter and .exit scripts on cd
source-plugin autoenv
# Build system helper commands
source-plugin build
# Project sandboxing commands
source-plugin sandbox
# Layout tmux window commands
[ "$TMUX" != "" ] && source-plugin layout
# Note taking commands
source-plugin notes
# Remove duplicates from history
setopt hist_ignore_all_dups
setopt hist_reduce_blanks
setopt hist_save_no_dups
# Enable multi-terminal history
setopt inc_append_history
# Enable comments in the prompt
setopt interactive_comments
# Disable '<Ctrl>D' to logout
setopt ignore_eof
# Disable sound
unsetopt beep
# Disable tty flow control, allows vim to use '<Ctrl>S'
unsetopt flow_control && stty -ixon
# Initialize completions
autoload -U compinit
compinit
# Add pip to the old completion engine if present
if which pip &> /dev/null; then
function _pip_completion {
local words cword
read -Ac words
read -cn cword
reply=( $( COMP_WORDS="$words[*]" \
COMP_CWORD=$(( cword-1 )) \
PIP_AUTO_COMPLETE=1 $words[1] ) )
}
compctl -K _pip_completion pip
fi
# Enable prompt themes
autoload -Uz promptinit
promptinit
prompt fresh
# Enable vi mode line editor keymap
bindkey -v
# Enable yank, change, and delete whole line with 'Y', 'cc', and 'dd'
bindkey -M vicmd 'Y' vi-yank-whole-line
# Edit the command line in vim
bindkey -M vicmd '^F' edit-command-line
# Enable undo with 'u' and redo with 'U'
bindkey -M vicmd 'u' undo
bindkey -M vicmd 'U' redo
# Enable toggle comment at start of line al la vim-commentary
bindkey -M vicmd 'gcc' vi-pound-insert
# TODO: vi-pipe???
# Enable accepting autosuggestions
bindkey '^O' forward-word
bindkey '^P' autosuggest-accept
# Enable substring history search with 'j' and 'k'
bindkey -M vicmd 'k' history-substring-search-up
bindkey -M vicmd 'j' history-substring-search-down
# Replace '<Esc>h' with 'K' to view help
bindkey -r '^[h'
bindkey -M vicmd 'K' run-help
# Disable Ex mode with ':'
bindkey -rM vicmd ':'
# Enable '<Shirt><Tab>' reverse order completions
bindkey '^[[Z' reverse-menu-complete
# Use editor to edit command line with '<Ctrl>V'
autoload -U edit-command-line
zle -N edit-command-line
bindkey -M vicmd '^V' edit-command-line
# Get the shells parent process name.
ppid_name() { echo $(ps -p $(ps -p $(echo $$) -o ppid=) -o comm=) }
# Enable changing cursor shape based on vi mode
if [ "$ITERM_PROFILE" != "" ] && [ "$TMUX" = "" ]; then
# iTerm2 cursor shape escape sequences outside tmux
cursor_block="\e]50;CursorShape=0\C-G"
cursor_line="\e]50;CursorShape=1\C-G"
elif [ "$(ppid_name)" != "python2" ]; then
# iTerm2 inside tmux or VTE compatible cursor shape escape sequences,
# exclude Guake even though it's VTE based it doesn't like these
cursor_block="\e[2 q"
cursor_line="\e[6 q"
fi
if [[ ! -z "$cursor_block" && ! -z "$cursor_line" ]]; then
# Change cursor shape when vi mode changes
function zle-keymap-select zle-line-init {
case $KEYMAP in
vicmd) print -n -- "$cursor_block" ;;
viins|main) print -n -- "$cursor_line" ;;
esac
zle reset-prompt
zle -R
}
# Change cursor shape when line editing is finished
function zle-line-finish { print -n -- "$cursor_block" }
# Register cursor shape hooks
zle -N zle-keymap-select
zle -N zle-line-init
zle -N zle-line-finish
fi
# Load work related config
[ -f ~/.config/work/zshrc ] && source ~/.config/work/zshrc
# Aliases
alias grep='grep --color=always'
which cmake &> /dev/null && \
alias cninja='cmake -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON'
which ssh &> /dev/null && \
alias ssh='TERM=xterm-256color ssh'
case `uname` in
Linux)
[ "$TMUX" = "" ] && \
alias cls="printf '\ec'" || \
alias cls="clear && printf '\e[3J'"
alias ls='ls -F --color=auto'
if which cgdb &> /dev/null; then
alias debug='cgdb --args'
elif which gdb &> /dev/null; then
alias debug='gdb --args'
fi
;;
Darwin)
alias cls="clear && printf '\e[3J'"
alias ls='ls -GFh'
which lldb &> /dev/null && \
alias debug='lldb --'
;;
esac