Skip to content

Instantly share code, notes, and snippets.

@timothybasanov
Last active October 17, 2020 07:11
Show Gist options
  • Save timothybasanov/87df55aad8ca8afe40d2 to your computer and use it in GitHub Desktop.
Save timothybasanov/87df55aad8ca8afe40d2 to your computer and use it in GitHub Desktop.
Zsh configuration
# Timothy's zsh configuration file.
#
# Checkout into ~/.zsh
# ln -sv .zsh/.zshrc ~/.zshrc
#
# brew install zsh-completions zsh-syntax-highlighting
# brew cask install sublime-text
# chsh -s /bin/zsh
#
# sudo apt-get install zsh zsh-syntax-highlighting sublime-text-installer
# chsh -s /usr/bin/zsh
#
# Enable local overrides for zsh configuration
if [[ -s ~/.zsh/.zshrc.local ]]; then
source ~/.zsh/.zshrc.local
fi
# Add all files in ~/.zsh as autoloaded functions
fpath=(~/.zsh $fpath)
autoload $(ls ~/.zsh)
# Different useful things making Zsh more powerful
autoload -U zmv
setopt extended_glob
# Enable colored output for ls
export CLICOLOR=YES # MacOS
if which dircolors &>/dev/null; then
alias ls="ls --color=auto"
fi
# Use nano and subl if graphics is available
export EDITOR="nano"
if [[ -n "$DISPLAY" || "$TERM_PROGRAM" = "Apple_Terminal" ]]; then
export VISUAL="subl -w"
fi
# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
bindkey -e
# End of lines configured by zsh-newuser-install
# Share history between tmux windows
setopt SHARE_HISTORY
setopt hist_ignore_space
setopt histignoredups
# The following lines were added by compinstall
zstyle ':completion:*' completer _complete _ignored
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s'
zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*'
zstyle ':completion:*' menu select=1
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
zstyle :compinstall filename '~/.zshrc'
fpath=(/usr/local/share/zsh-completions $fpath)
autoload -Uz compinit
compinit -u
# End of lines added by compinstall
# Support TAB/TAB/TAB for repeated autocompletion
zmodload zsh/complist
bindkey -M menuselect '^I' accept-and-infer-next-history
# Workaround for zsh 5.2 release
autoload +X VCS_INFO_nvcsformats
functions[VCS_INFO_nvcsformats]=${functions[VCS_INFO_nvcsformats]/local -a msgs/}
# # Lines for vcs_info prompt configuration
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' stagedstr '%{%F{green}%B%}●%{%b%f%}'
zstyle ':vcs_info:*' unstagedstr '%{%F{red}%B%}●%{%b%f%}'
zstyle ':vcs_info:*' formats '%{%F{cyan}%}%45<…<%R%<</%{%f%}%{%F{green}%}(%25>…>%b%<<)%{%f%}%{%F{cyan}%}%S%{%f%}%c%u'
zstyle ':vcs_info:*' actionformats '%{%F{cyan}%}%45<…<%R%<</%{%f%}%{%F{red}%}(%a|%m)%{%f%}%{%F{cyan}%}%S%{%f%}%c%u'
zstyle ':vcs_info:*' nvcsformats '%{%F{cyan}%}%~%{%f%}'
zstyle ':vcs_info:git:*' patch-format '%10>…>%p%<< (%n applied)'
zstyle ':vcs_info:*+set-message:*' hooks home-path
function +vi-home-path() {
# Replace $HOME with ~
hook_com[base]="$(echo ${hook_com[base]} | sed "s/${HOME:gs/\//\\\//}/~/" )"
}
zstyle ':vcs_info:git+post-backend:*' hooks git-remote-staged
function +vi-git-remote-staged() {
# Show "unstaged" when changes are not staged or not committed
# Show "staged" when last committed is not pushed
#
# See original VCS_INFO_get_data_git for implementation details
# Set "unstaged" when git reports either staged or unstaged changes
if (( gitstaged || gitunstaged )) ; then
gitunstaged=1
fi
# Set "staged" when current HEAD is not present in the remote branch
if (( querystaged )) && \
[[ "$(${vcs_comm[cmd]} rev-parse --is-inside-work-tree 2> /dev/null)" == 'true' ]] ; then
# Default: off - these are potentially expensive on big repositories
if ${vcs_comm[cmd]} rev-parse --quiet --verify HEAD &> /dev/null ; then
gitstaged=1
if ${vcs_comm[cmd]} status --branch --short | head -n1 | grep -v ahead > /dev/null ; then
gitstaged=
fi
fi
fi
hook_com[staged]=$gitstaged
hook_com[unstaged]=$gitunstaged
}
autoload -Uz vcs_info
function precmd() { vcs_info }
setopt prompt_subst
PROMPT='%(?..%{%F{red}%}%?%{%f%} )%{%F{green}%}%n%{%f%}@%{%F{red}%}%m%{%f%}:${vcs_info_msg_0_}%{%B%}%(!.#.>)%{%b%E%} '
# End of lines for vcs_info prompt configuration
# Support keyboard navigation in the command prompt
bindkey "^[[1;3H" backward-word # Fn-Option-Left, Option-Home
bindkey "^[[1;3F" forward-word # Fn-Option-Right, Option-End
bindkey "${terminfo[khome]}" beginning-of-line # Fn-Left, Home
bindkey "${terminfo[kend]}" end-of-line # Fn-Right, End
# Ctrl-X-e and Ctrl-Space to edit in the editor
autoload -U edit-command-line
zle -N edit-command-line
bindkey '^Xe' edit-command-line
bindkey '^ ' edit-command-line
# Enable inline syntax highlighting
typeset -A ZSH_HIGHLIGHT_STYLES
ZSH_HIGHLIGHT_STYLES[path]='fg=cyan,bold'
ZSH_HIGHLIGHT_STYLES[path_prefix]='fg=cyan'
ZSH_HIGHLIGHT_STYLES[redirection]='fg=cyan,bold'
ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]='fg=magenta,bold'
if [[ -s /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]]; then
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
fi
if [[ -s /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]]; then
source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
fi
Copyright 2019 Timothy Basanov
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
exec $SHELL -l
while true; do "$@" ; echo "$? Retry: $@" ; sleep 2 ; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment