eval "$(starship init zsh)" # Include custom aliases/functions source "$HOME/.dotfiles/includes" install_zplug() { curl -sL --proto-redir -all,https https://raw.githubusercontent.com/zplug/installer/master/installer.zsh | zsh } rm_zplug() { rm -rf ~/.zplug } # Zplug settings # https://github.com/zplug/zplug source ~/.zplug/init.zsh # https://www.github.com/zsh-users/zsh-syntax-highlighting # Fish shell-like syntax highlighting for Zsh. zplug "zsh-users/zsh-syntax-highlighting" # You can type the beginning of a command and then use arrow keys to filter # previous commands in your history that share the same beginning # https://www.github.com/zsh-users/zsh-history-substring-search zplug "zsh-users/zsh-history-substring-search" # https://www.github.com/zsh-users/zsh-autosuggestions # Fish-like fast/unobtrusive autosuggestions for zsh. When you type a command a # second time it shows up but is shaded, use the right arrow to fully complete # the command zplug "zsh-users/zsh-autosuggestions" # https://www.github.com/zsh-users/zsh-completions # Additional completions for common command line tools zplug "zsh-users/zsh-completions" # Quick changing directories, z is a command line tool that allows you to jump # quickly to directories that you have visited frequently in the past, or # recently # https://www.github.com/agkozak/zsh-z zplug "agkozak/zsh-z" # Install plugins if there are plugins that have not been installed if ! zplug check --verbose; then printf "Install? [y/N]: " if read -q; then echo; zplug install fi fi # Then, source plugins and add commands to $PATH # Remove --verbose if you find the startup message annoying zplug load --verbose # If you see custom autocomplete files that you want to install, say from # someones dotfiles, Well create our own autocomplete folder where we can just # download/curl the files into and then we'll save them. # # For instance, what if we just wanted to use the _docker file from this repo # https://raw.githubusercontent.com/felixr/docker-zsh-completion install_docker_autocomplete() { curl -fsSL 'https://raw.githubusercontent.com/felixr/docker-zsh-completion/master/_docker' -o "$HOME/.dotfiles/autocompletes/_docker" } rm_docker_autocomplete() { rm ~/.dotfiles/autocompletes/_docker } fpath=($HOME/.dotfiles/autocompletes $fpath) # Highlight the current autocomplete option zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" # Auto-complete will group matches and describe. zstyle ':completion:*:*:*:*:*' menu select zstyle ':completion:*:matches' group 'yes' zstyle ':completion:*:options' description 'yes' zstyle ':completion:*:options' auto-description '%d' zstyle ':completion:*:corrections' format ' %F{green}-- %d (errors: %e) --%f' zstyle ':completion:*:descriptions' format ' %F{yellow}-- %d --%f' zstyle ':completion:*:messages' format ' %F{purple} -- %d --%f' zstyle ':completion:*:warnings' format ' %F{red}-- no matches found --%f' zstyle ':completion:*:default' list-prompt '%S%M matches%s' zstyle ':completion:*' format ' %F{yellow}-- %d --%f' zstyle ':completion:*' group-name '' zstyle ':completion:*' verbose yes # Simple ssh completion, don't ask how it works zstyle -e ':completion:*:hosts' hosts 'reply=( ${=${=${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) 2>/dev/null)"}%%[#| ]*}//\]:[0-9]*/ }//,/ }//\[/ } ${=${(f)"$(cat /etc/hosts(|)(N) <<(ypcat hosts 2>/dev/null))"}%%\#*} ${=${${${${(@M)${(f)"$(cat ~/.ssh/config 2>/dev/null)"}:#Host *}#Host }:#*\**}:#*\?*}} )' # Allow for autocomplete to be case insensitive zstyle ':completion:*' matcher-list '' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' \ '+l:|?=** r:|?=**' # Initialize autocompletes for zsh # Needs to come after the fpath is set autoload -Uz compinit && compinit -i # Example of how to assign a custom function the autocompletes of an existing # function sls() { ssh "$1" ls } compdef sls=ssh dex() { # Enter a container docker exec -it "$1" /bin/bash } # Set `dex` to use to autocompletes for `docker_containers`. # `docker_containers` is not a real function, but zsh will still search for the # autocomplete file `_docker_containers` on the fpath. Sometimes I use the same # autocompletes between multiple custom functions so I just make a "general" # autocompletes and compdef commands to in compdef dex=docker_containers # Extra Goodies # Source additional options if set if [[ -s "$HOME/.zshrc2" ]]; then source "$HOME/.zshrc2" fi # Set Editor export EDITOR='nvim' export VISUAL='nvim' export PAGER='less -S' export XDG_CONFIG_HOME="$HOME/.config" export COOKIECUTTER_CONFIG="$HOME/.config/cookiecutter/config.yml" # Set the Language, important for NERD Fonts export LANG=en_US.UTF-8 # Set the default Less options. # Mouse-wheel scrolling has been disabled by -X (disable screen clearing). # Remove -X and -F (exit if the content fits on one screen) to enable it. export LESS='-F -g -i -M -R -S -w -X -z-4' # Use `bindkey -v` to use vim line editing mode bindkey -e export KEYTIMEOUT=1 # FZF find function, ignore pyc files export FZF_DEFAULT_COMMAND='find * -type f | grep -v ".pyc"' # Vi mode changes a bunch on the commands that normal bash # provides so I bind these keys back to their original functions bindkey '^?' backward-delete-char bindkey '^w' backward-kill-word bindkey '^h' backward-delete-char bindkey '^u' backward-kill-line bindkey '^r' history-incremental-search-backward bindkey '^S' history-incremental-search-forward bindkey '^[[Z' reverse-menu-complete bindkey -M viins '\C-A' beginning-of-line bindkey -M viins '\C-E' end-of-line bindkey -M viins '^k' vi-cmd-mode # History Files Options HISTFILE="${ZDOTDIR:-$HOME}/.dotfiles/history" HISTSIZE=10000 SAVEHIST=10000 setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits. setopt HIST_IGNORE_SPACE # Do not record an event starting with a space. setopt BANG_HIST # Treat the '!' character specially during expansion. setopt EXTENDED_HISTORY # Write the history file in the ':start:elapsed;command' format. setopt HIST_IGNORE_DUPS # Do not record an event that was just recorded again. # Use vim to edit longer commands autoload -z edit-command-line zle -N edit-command-line bindkey "^X^E" edit-command-line # Alt m for easlier words. autoload -Uz copy-earlier-word zle -N copy-earlier-word bindkey "^[m" copy-earlier-word # Disable XON/XOFF flow control which causes ^-s to freeze instead of # searching forward through history stty -ixon # Append custom bins path+=("$HOME/.dotfiles/bin") # Allow brace expansions setopt BRACE_CCL # Ctrl-w delete word, when it's a path only delete to the '/' and ':' # Remove them from wordchars: A list of non-alphanumeric characters considered # part of a word by the line editor. my-backward-delete-word() { local WORDCHARS=${WORDCHARS/\//} WORDCHARS=${WORDCHARS/:/} zle backward-delete-word } zle -N my-backward-delete-word bindkey '^W' my-backward-delete-word # Make sure SSH Agent is present if ! pgrep -u "$USER" ssh-agent > /dev/null; then ssh-agent > ~/.ssh-agent-cache fi if [[ "$SSH_AGENT_PID" == "" ]]; then eval "$(<~/.ssh-agent-cache)" fi # For GPG signing commits export GPG_TTY=$(tty) # LS_COLORS config local ls_colors_file="$HOME/.zsh/ls_colors" if [[ -e "$ls_colors_file" ]]; then eval $(dircolors -b "$ls_colors_file") fi # Use direnv if [ -x "$(command -v direnv)" ]; then eval "$(direnv hook zsh)" fi # Autocompletes for kubectl if [ -x "$(command -v kubectl)" ]; then source <(kubectl completion zsh) fi [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh export GOPATH="$HOME/.go"