# Skip all this for non-interactive shells [[ -z "$PS1" ]] && return ######### # zplug # ######### export ZPLUG_HOME=~/.zplug source $ZPLUG_HOME/init.zsh zplug 'zplug/zplug', hook-build:'zplug --self-manage' # Set the priority when loading # e.g., zsh-syntax-highlighting must be loaded # after executing compinit command and sourcing other plugins # (If the defer tag is given 2 or above, run after compinit command) zplug "zsh-users/zsh-syntax-highlighting", defer:2 # Manage local plugins # zplug "~/.zsh", from:local # Theme # zplug "dracula/zsh", as:theme # zplug "marszall87/nodeys-zsh-theme", as:theme zplug "themes/frisk", as:theme, from:oh-my-zsh # Plugins zplug "zsh-users/zsh-autosuggestions" zplug "zsh-users/zsh-history-substring-search" zplug "zsh-users/zsh-completions" zplug "laurenkt/zsh-vimto" zplug "MichaelAquilina/zsh-autoswitch-virtualenv" # zplug "paulmelnikow/zsh-startup-timer" # zplug "lib/nvm", from:oh-my-zsh # 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 zplug load ################ # Zsh settings # ################ # Vi mode bindkey -v export KEYTIMEOUT=1 # backspace and ^h working even after # returning from command mode bindkey '^?' backward-delete-char bindkey '^h' backward-delete-char # ctrl-w removed word backwards bindkey '^w' backward-kill-word # ctrl-r starts searching history backward bindkey '^r' history-incremental-search-backward # History HISTFILE="$HOME/.zsh_history" HISTSIZE=10000000 SAVEHIST=$HISTSIZE setopt INC_APPEND_HISTORY setopt HIST_IGNORE_SPACE setopt SHARE_HISTORY setopt HIST_IGNORE_ALL_DUPS setopt HIST_REDUCE_BLANKS # Other options # Prompts for confirmation after 'rm *' etc setopt RM_STAR_WAIT #Background processes aren't killed on exit of shell setopt AUTO_CONTINUE # Don’t write over existing files with >, use >! instead setopt NOCLOBBER # Completion zmodload zsh/complist autoload -Uz compinit compinit zstyle :compinstall filename '${HOME}/.zshrc' zstyle ':completion:*' menu select setopt COMPLETE_ALIASES zstyle :compinstall filename '${HOME}/.zshrc' zstyle ':completion:*:pacman:*' force-list always zstyle ':completion:*:*:pacman:*' menu yes select zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} zstyle ':completion::complete:*' gain-privileges 1 # Completion selection by menu for kill zstyle ':completion:*:*:kill:*' menu yes select zstyle ':completion:*:kill:*' force-list always zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd' zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' zstyle ':completion:*:*:killall:*' menu yes select zstyle ':completion:*:killall:*' force-list always zstyle ':completion:*' use-cache on zstyle ':completion:*' cache-path ~/.zsh/cache # Calculator # autoload zcalc # Keybindings typeset -g -A key key[Home]="${terminfo[khome]}" key[End]="${terminfo[kend]}" key[Insert]="${terminfo[kich1]}" key[Backspace]="${terminfo[kbs]}" key[Delete]="${terminfo[kdch1]}" key[Up]="${terminfo[kcuu1]}" key[Down]="${terminfo[kcud1]}" key[Left]="${terminfo[kcub1]}" key[Right]="${terminfo[kcuf1]}" key[PageUp]="${terminfo[kpp]}" key[PageDown]="${terminfo[knp]}" key[Shift-Tab]="${terminfo[kcbt]}" # setup key accordingly [[ -n "${key[Home]}" ]] && bindkey -- "${key[Home]}" beginning-of-line [[ -n "${key[End]}" ]] && bindkey -- "${key[End]}" end-of-line [[ -n "${key[Insert]}" ]] && bindkey -- "${key[Insert]}" overwrite-mode [[ -n "${key[Backspace]}" ]] && bindkey -- "${key[Backspace]}" backward-delete-char [[ -n "${key[Delete]}" ]] && bindkey -- "${key[Delete]}" delete-char [[ -n "${key[Up]}" ]] && bindkey -- "${key[Up]}" history-substring-search-up [[ -n "${key[Down]}" ]] && bindkey -- "${key[Down]}" history-substring-search-down [[ -n "${key[Left]}" ]] && bindkey -- "${key[Left]}" backward-char [[ -n "${key[Right]}" ]] && bindkey -- "${key[Right]}" forward-char [[ -n "${key[PageUp]}" ]] && bindkey -- "${key[PageUp]}" beginning-of-buffer-or-history [[ -n "${key[PageDown]}" ]] && bindkey -- "${key[PageDown]}" end-of-buffer-or-history [[ -n "${key[Shift-Tab]}" ]] && bindkey -- "${key[Shift-Tab]}" reverse-menu-complete # Finally, make sure the terminal is in application mode, when zle is # active. Only then are the values from $terminfo valid. if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then autoload -Uz add-zle-hook-widget function zle_application_mode_start { echoti smkx } function zle_application_mode_stop { echoti rmkx } add-zle-hook-widget -Uz zle-line-init zle_application_mode_start add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop fi key[Control-Left]="${terminfo[kLFT5]}" key[Control-Right]="${terminfo[kRIT5]}" [[ -n "${key[Control-Left]}" ]] && bindkey -- "${key[Control-Left]}" backward-word [[ -n "${key[Control-Right]}" ]] && bindkey -- "${key[Control-Right]}" forward-word # emacs function vterm_printf(){ if [ -n "$TMUX" ]; then # Tell tmux to pass the escape sequences through # (Source: http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324) printf "\ePtmux;\e\e]%s\007\e\\" "$1" elif [ "${TERM%%-*}" = "screen" ]; then # GNU screen (screen, screen-256color, screen-256color-bce) printf "\eP\e]%s\007\e\\" "$1" else printf "\e]%s\e\\" "$1" fi } # Completely clear the buffer. With this, everything that is not on screen # is erased. if [[ "$INSIDE_EMACS" = 'vterm' ]]; then alias clear='vterm_printf "51;Evterm-clear-scrollback";tput clear' fi # With vterm_cmd you can execute Emacs commands directly from the shell. # For example, vterm_cmd message "HI" will print "HI". # To enable new commands, you have to customize Emacs's variable # vterm-eval-cmds. vterm_cmd() { local vterm_elisp vterm_elisp="" while [ $# -gt 0 ]; do vterm_elisp="$vterm_elisp""$(printf '"%s" ' "$(printf "%s" "$1" | sed -e 's|\\|\\\\|g' -e 's|"|\\"|g')")" shift done vterm_printf "51;E$vterm_elisp" } # This is to change the title of the buffer based on information provided by the # shell. See, http://tldp.org/HOWTO/Xterm-Title-4.html, for the meaning of the # various symbols. autoload -U add-zsh-hook add-zsh-hook -Uz chpwd (){ print -Pn "\e]2;%m:%2~\a" } # Sync directory and host in the shell with Emacs's current directory. # You may need to manually specify the hostname instead of $(hostname) in case # $(hostname) does not return the correct string to connect to the server. # # The escape sequence "51;A" has also the role of identifying the end of the # prompt vterm_prompt_end() { vterm_printf "51;A$(whoami)@$(hostname):$(pwd)"; } setopt PROMPT_SUBST PROMPT=$PROMPT'%{$(vterm_prompt_end)%}' # Load environment [ -f "$HOME/.aliasrc" ] && source "$HOME/.envrc" # Load aliases [ -f "$HOME/.aliasrc" ] && source "$HOME/.aliasrc"