Skip to content

Instantly share code, notes, and snippets.

@m-goos
Last active October 13, 2020 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m-goos/27fef06063470b3fed23c1087f0419af to your computer and use it in GitHub Desktop.
Save m-goos/27fef06063470b3fed23c1087f0419af to your computer and use it in GitHub Desktop.
zshrc: config from @arjenbrandenburgh
# nano ~/.zshrc -> paste from line 5 onwards -> save (ctrl + o) -> exit (ctrl + x)
# source ~/.zshrc -> YES
# compaudit | xargs chmod g-w
# Tab completion
autoload -Uz compinit && compinit
# Bash completion
autoload bashcompinit && bashcompinit
# Case insensitive path-completion
zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*'
# Git completion
zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash
fpath=(~/.zsh $fpath)
alias ls='ls -GwF'
alias ll='ls -alh'
alias zshrc='code ~/.zshrc'
# Get Git branch of current directory
git_branch () {
if git rev-parse --git-dir >/dev/null 2>&1
# then echo -e "" git:\($(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')\)
then echo -e "" \($(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')\)
else
echo ""
fi
}
# Set a specific color for the status of the Git repo
git_color() {
local STATUS=`git status 2>&1`
if [[ "$STATUS" == *'Not a git repository'* ]]
then echo "" # nothing
else
if [[ "$STATUS" != *'working tree clean'* ]]
then echo -e '\033[0;31m' # red if need to commit
else
if [[ "$STATUS" == *'Your branch is ahead'* ]]
then echo -e '\033[0;33m' # yellow if need to push
else
echo -e '\033[0;32m' # else green
fi
fi
fi
}
autoload -Uz vcs_info
# zstyle ':vcs_info:git:*' formats ' [%b]'
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
}
precmd () { vcs_info }
setopt prompt_subst
# Bind keys
bindkey "^[[H" beginning-of-line # Fn + left
bindkey "^[[F" end-of-line # Fn + right
# Modify the prompt
export PS1="%F{214}%K{000}%n%F{015}%K{000}:%F{039}%K{000}\$vcs_info_msg_0_%F{015}%K{000}\$ "
# Add color to terminal
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
# Set default editor
export EDITOR=code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment