Last active
January 11, 2021 14:56
-
-
Save hector6872/4e77eb59ca5eaad980cb61e0ea35f591 to your computer and use it in GitHub Desktop.
My awesome Zsh prompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ALIAS | |
# ============= | |
alias ..='cd ..' | |
case `uname` in | |
Darwin) | |
alias flushdns='sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder;say cache flushed' | |
alias ls='ls -GpF' # Mac OSX specific | |
alias ll='ls -alGpF' # Mac OSX specific | |
;; | |
Linux) | |
alias ll='ls -al' | |
alias ls='ls --color=auto' | |
;; | |
esac | |
export LC_ALL="en_US.UTF-8" | |
export LANG="en_US.UTF-8" | |
# ============= | |
# EXPORT | |
# ============= | |
# support colors in less | |
export LESS_TERMCAP_mb=$'\E[01;31m' | |
export LESS_TERMCAP_md=$'\E[01;31m' | |
export LESS_TERMCAP_me=$'\E[0m' | |
export LESS_TERMCAP_se=$'\E[0m' | |
export LESS_TERMCAP_so=$'\E[01;44;33m' | |
export LESS_TERMCAP_ue=$'\E[0m' | |
export LESS_TERMCAP_us=$'\E[01;32m' | |
setopt PUSHDSILENT | |
# ============= | |
# HISTORY | |
# ============= | |
## Command history configuration | |
HISTFILE=$HOME/.zsh_history | |
HISTSIZE=1000000 | |
SAVEHIST=1000000 | |
setopt append_history | |
setopt extended_history | |
setopt hist_expire_dups_first | |
# ignore duplication command history list | |
setopt hist_ignore_dups | |
setopt hist_ignore_space | |
setopt hist_verify | |
setopt inc_append_history | |
# share command history data | |
setopt share_history | |
# ============= | |
# PROMPT | |
# ============= | |
autoload -U colors && colors | |
setopt promptsubst | |
local ret_status="%(?:%{$fg_bold[green]%}$:%{$fg_bold[green]%}$)" | |
PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)' | |
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}" | |
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " | |
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗" | |
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})" | |
# Outputs current branch info in prompt format | |
function git_prompt_info() { | |
local ref | |
if [[ "$(command git config --get customzsh.hide-status 2>/dev/null)" != "1" ]]; then | |
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \ | |
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0 | |
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX" | |
fi | |
} | |
# Checks if working tree is dirty | |
function parse_git_dirty() { | |
local STATUS='' | |
local FLAGS | |
FLAGS=('--porcelain') | |
if [[ "$(command git config --get customzsh.hide-dirty)" != "1" ]]; then | |
FLAGS+='--ignore-submodules=dirty' | |
STATUS=$(command git status ${FLAGS} 2> /dev/null | tail -n1) | |
fi | |
if [[ -n $STATUS ]]; then | |
echo "$ZSH_THEME_GIT_PROMPT_DIRTY" | |
else | |
echo "$ZSH_THEME_GIT_PROMPT_CLEAN" | |
fi | |
} | |
# =================== | |
# AUTOCOMPLETION | |
# =================== | |
# enable completion | |
autoload -Uz compinit | |
compinit | |
autoload bashcompinit | |
bashcompinit | |
zmodload -i zsh/complist | |
WORDCHARS='' | |
unsetopt menu_complete # do not autoselect the first completion entry | |
unsetopt flowcontrol | |
setopt auto_menu # show completion menu on successive tab press | |
setopt complete_in_word | |
setopt always_to_end | |
# autocompletion with an arrow-key driven interface | |
zstyle ':completion:*:*:*:*:*' menu select | |
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*' | |
zstyle ':completion:*' list-colors '' | |
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01' | |
zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm -w -w" | |
# Don't complete uninteresting users | |
zstyle ':completion:*:*:*:users' ignored-patterns \ | |
adm amanda apache at avahi avahi-autoipd beaglidx bin cacti canna \ | |
clamav daemon dbus distcache dnsmasq dovecot fax ftp games gdm \ | |
gkrellmd gopher hacluster haldaemon halt hsqldb ident junkbust kdm \ | |
ldap lp mail mailman mailnull man messagebus mldonkey mysql nagios \ | |
named netdump news nfsnobody nobody nscd ntp nut nx obsrun openvpn \ | |
operator pcap polkitd postfix postgres privoxy pulse pvm quagga radvd \ | |
rpc rpcuser rpm rtkit scard shutdown squid sshd statd svn sync tftp \ | |
usbmux uucp vcsa wwwrun xfs '_*' | |
zstyle '*' single-ignored show | |
# Automatically update PATH entries | |
zstyle ':completion:*' rehash true | |
# Keep directories and files separated | |
zstyle ':completion:*' list-dirs-first true | |
# =================== | |
# KEY BINDINGS | |
# =================== | |
# Use emacs-like key bindings by default: | |
bindkey -e | |
# [Ctrl-r] - Search backward incrementally for a specified string. The string | |
# may begin with ^ to anchor the search to the beginning of the line. | |
bindkey '^r' history-incremental-search-backward | |
if [[ "${terminfo[kpp]}" != "" ]]; then | |
bindkey "${terminfo[kpp]}" up-line-or-history # [PageUp] - Up a line of history | |
fi | |
if [[ "${terminfo[knp]}" != "" ]]; then | |
bindkey "${terminfo[knp]}" down-line-or-history # [PageDown] - Down a line of history | |
fi | |
if [[ "${terminfo[khome]}" != "" ]]; then | |
bindkey "${terminfo[khome]}" beginning-of-line # [Home] - Go to beginning of line | |
fi | |
if [[ "${terminfo[kend]}" != "" ]]; then | |
bindkey "${terminfo[kend]}" end-of-line # [End] - Go to end of line | |
fi | |
if [[ "${terminfo[kcbt]}" != "" ]]; then | |
bindkey "${terminfo[kcbt]}" reverse-menu-complete # [Shift-Tab] - move through the completion menu backwards | |
fi | |
bindkey '^?' backward-delete-char # [Backspace] - delete backward | |
if [[ "${terminfo[kdch1]}" != "" ]]; then | |
bindkey "${terminfo[kdch1]}" delete-char # [Delete] - delete forward | |
else | |
bindkey "^[[3~" delete-char | |
bindkey "^[3;5~" delete-char | |
bindkey "\e[3~" delete-char | |
fi | |
# =================== | |
# MISC SETTINGS | |
# =================== | |
# automatically remove duplicates from these arrays | |
typeset -U path PATH cdpath CDPATH fpath FPATH manpath MANPATH | |
# =================== | |
# PLUGINS | |
# =================== | |
# These are installed via brew | |
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh | |
source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
chsh -s $(which zsh)
vi ~/.zshrc
source ~/.zshrc