├── .gitignore ├── .gitmodules ├── Makefile ├── ant-zsh.zsh ├── lib ├── S00.misc.zsh ├── S05.alias.zsh ├── S05.color.zsh ├── S05.function.zsh ├── S10.termsupport.zsh ├── S15.edit-command-line.zsh ├── S15.key-binding.zsh ├── S15.spectrum.zsh ├── S20.completion.zsh ├── S20.correction.zsh ├── S20.directory.zsh ├── S20.grep.zsh ├── S20.history.zsh ├── S30.rvm.zsh ├── S40.plugin.zsh ├── S40.theme.zsh └── S99.post-plugin.zsh ├── plugin ├── ccache │ └── ccache.plugin.zsh ├── cowfortune │ └── cowfortune.plugin.zsh └── virtualenv │ └── virtualenv.plugin.zsh ├── template ├── zshenv.zsh-template └── zshrc.zsh-template └── theme └── anthraxx.zsh /.gitignore: -------------------------------------------------------------------------------- 1 | /cache 2 | /plugin/repos/ 3 | /plugin/bundles/ 4 | /plugin/revert-info 5 | /plugin/.zcompdump* 6 | /plugin/*.log 7 | plugin/.resources 8 | plugin/init.zsh* 9 | *.zwc 10 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "plugin/antigen"] 2 | path = plugin/antigen 3 | url = git://github.com/zsh-users/antigen.git 4 | ignore = dirty 5 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | RED=$(shell tput setaf 1) 2 | GREEN=$(shell tput setaf 2) 3 | YELLOW=$(shell tput setaf 3) 4 | BOLD=$(shell tput bold) 5 | RST=$(shell tput sgr0) 6 | 7 | INIT_ZSH=ant-zsh.zsh 8 | 9 | .PHONY: all submodule test test-zshrc test-source test-env-var install install-zshrc install-zshenv 10 | 11 | all: submodule 12 | 13 | test: test-zshrc test-source test-env-var 14 | 15 | test-zshrc: 16 | @if test ! -e "$(HOME)/.zshrc" ; then \ 17 | echo "$(BOLD)$(RED)[-] $(RST)$(BOLD)$(HOME)/.zshrc$(RST) not found"; \ 18 | echo " $(BOLD)^^^ fix: $(RST)run $(BOLD)make install-zshrc$(RST)"; \ 19 | exit 1; \ 20 | fi 21 | @echo "$(BOLD)$(GREEN)[+] $(RST)$(BOLD)found $(HOME)/.zshrc$(RST)" 22 | 23 | test-source: 24 | @if test -z "$(shell grep 'source $$ZSH/$(INIT_ZSH)' $(HOME)/.zshrc)" ; then \ 25 | echo "$(BOLD)$(RED)[-] $(RST)missing $(BOLD)$(INIT_ZSH)$(RST) include in $(BOLD)$(HOME)/.zshrc$(RST)"; \ 26 | echo " $(BOLD)^^^ fix: $(RST)add >> $(BOLD)source \$$ZSH/$(INIT_ZSH)$(RST) << in your $(BOLD).zshrc$(RST)"; \ 27 | echo " $(BOLD)^^^ or: $(RST)remove your $(BOLD).zshrc$(RST) and run $(BOLD)make install-zshrc$(RST)"; \ 28 | exit 1; \ 29 | fi 30 | @echo "$(BOLD)$(GREEN)[+] $(RST)$(BOLD)found $(INIT_ZSH) include$(RST)" 31 | 32 | test-env-var: 33 | @if test ! -e "$(shell zsh -c 'echo $$ZSH')" ; then \ 34 | echo "$(BOLD)$(RED)[-] $(RST)missing $(BOLD)\$$ZSH$(RST) env var$(RST)"; \ 35 | echo " $(BOLD)^^^ fix: $(RST)add >> $(BOLD)export ZSH=$(shell pwd)$(RST) << in your $(BOLD).zshenv$(RST)"; \ 36 | echo " $(BOLD)^^^ or: $(RST)remove your $(BOLD).zshenv$(RST) and run $(BOLD)make install-zshenv$(RST)"; \ 37 | exit 1; \ 38 | fi 39 | @echo "$(BOLD)$(GREEN)[+] $(RST)$(BOLD)found \$$ZSH at $(shell zsh -c 'echo $$ZSH')$(RST)" 40 | 41 | install: install-zshrc install-zshenv 42 | 43 | install-zshrc: 44 | @if test -e "$(HOME)/.zshrc" ; then \ 45 | echo "$(BOLD)$(RED)[-] $(RST)$(BOLD)$(HOME)/.zshrc$(RST) already exists"; \ 46 | echo " $(BOLD)^^^$(RST) remove or backup manually before overwriting!$(RST)"; \ 47 | exit 1; \ 48 | fi 49 | @cp template/zshrc.zsh-template $(HOME)/.zshrc 50 | @echo "$(BOLD)$(GREEN)[+] $(RST)$(BOLD)installed default $(HOME)/.zshrc$(RST)" 51 | 52 | install-zshenv: 53 | @if test -e "$(HOME)/.zshenv" ; then \ 54 | echo "$(BOLD)$(RED)[-] $(RST)$(BOLD)$(HOME)/.zshenv$(RST) already exists"; \ 55 | echo " $(BOLD)^^^$(RST) remove or backup manually before overwriting!$(RST)"; \ 56 | exit 1; \ 57 | fi 58 | @cp template/zshenv.zsh-template $(HOME)/.zshenv 59 | @echo 'ZSH=$(shell pwd)' >> $(HOME)/.zshenv 60 | @echo "$(BOLD)$(GREEN)[+] $(RST)$(BOLD)installed default $(HOME)/.zshenv$(RST)" 61 | 62 | submodule: 63 | @git submodule update --recursive --init --rebase 64 | @echo "$(BOLD)$(GREEN)[+] $(RST)$(BOLD)initialized submodules$(RST)" 65 | 66 | update: submodule 67 | zsh -c "source ant-zsh.zsh && zsh_update" || true 68 | 69 | update-antigen: 70 | @echo "$(BOLD)$(GREEN)[+] $(RST)$(BOLD)updating antigen from remote...$(RST)" 71 | @git submodule update --recursive --init --rebase --remote plugin/antigen 72 | -------------------------------------------------------------------------------- /ant-zsh.zsh: -------------------------------------------------------------------------------- 1 | # some pre-checks 2 | if [ -z "$ZSH" ]; then 3 | echo "\033[00;31mERROR: missing ZSH env var! read the README!" 4 | return 5 | fi 6 | if [ ! -d "$ZSH" ]; then 7 | echo "\033[00;31mERROR: ZSH env var leads nowhere: '$ZSH'" 8 | return 9 | fi 10 | 11 | # include all lib config files 12 | for config_file ($ZSH/lib/*.zsh) source $config_file 13 | 14 | # load antigen 15 | ADOTDIR="${ZSH}/plugin" 16 | source "${ZSH}/plugin/antigen/antigen.zsh" 17 | 18 | # define and load the plugins 19 | if [ "$ZSH_DEFAULT_PLUGINS_DISABLE" != "1" ]; then 20 | default_plugins=(cowfortune virtualenv ccache) 21 | fi 22 | load_plugin $default_plugins $plugins 23 | 24 | antigen bundles </dev/null 2>&1; then 12 | alias l='ls++ --potsf -lAh --color' 13 | alias ll='ls++ --potsf -lAh --color' 14 | else 15 | alias l='ls -lAh --color' 16 | alias ll='ls -lAh --color' 17 | fi 18 | 19 | # grep 20 | alias grep='grep --color=auto' 21 | alias fgrep='fgrep --color=auto' 22 | alias egrep='egrep --color=auto' 23 | alias agrep='ack-grep --color' 24 | -------------------------------------------------------------------------------- /lib/S05.color.zsh: -------------------------------------------------------------------------------- 1 | autoload colors; colors; 2 | 3 | export LSCOLORS="Gxfxcxdxbxegedabagacad" 4 | # export LS_COLORS via dircolors for compretion 5 | if [ -z "$LS_COLORS" ] 6 | then 7 | eval $(dircolors) 8 | fi 9 | 10 | # enable ls colors 11 | if [ "$DISABLE_LS_COLORS" != "true" ] 12 | then 13 | # Find the option for using colors in ls, depending on the version: Linux or BSD 14 | ls --color -d . &>/dev/null 2>&1 && alias ls='ls --color=tty' || alias ls='ls -G' 15 | fi 16 | 17 | # enable ip colors 18 | if [ "$DISABLE_IP_COLORS" != "true" ] 19 | then 20 | ip --color -br link &>/dev/null 2>&1 && alias ip='ip --color -br' 21 | fi 22 | 23 | # enable diff colors 24 | if [ "$DISABLE_DIFF_COLORS" != "true" ] 25 | then 26 | diff --color=auto --version &>/dev/null 2>&1 && alias diff='diff --color=auto' 27 | fi 28 | 29 | # enable ncdu colors 30 | if [ "$DISABLE_NCDU_COLORS" != "true" ] 31 | then 32 | ncdu --color=dark -version &>/dev/null 2>&1 && alias ncdu='ncdu --color=dark' 33 | fi 34 | 35 | if [ "$DISABLE_S_COLORS" != "true" ] 36 | then 37 | export S_COLORS=auto 38 | fi 39 | 40 | # set some colors 41 | for COLOR in RED GREEN BLUE YELLOW WHITE BLACK CYAN; do 42 | eval PR_$COLOR='%{$fg[${(L)COLOR}]%}' 43 | eval PR_BRIGHT_$COLOR='%{$fg_bold[${(L)COLOR}]%}' 44 | done 45 | PR_RST="%{${reset_color}%}" 46 | PR_RESET="%{%b%s%u$reset_color%}" 47 | PR_BG="%{%(?.$PR_RESET.%S)%}" 48 | -------------------------------------------------------------------------------- /lib/S05.function.zsh: -------------------------------------------------------------------------------- 1 | function zsh_stats() { 2 | history | awk '{print $2}' | sort | uniq -c | sort -rn | head 3 | } 4 | 5 | function take() { 6 | mkdir -p "$1" 7 | cd "$1" 8 | } 9 | 10 | function mkdircd() { 11 | take "$1" 12 | } 13 | 14 | function zc () { 15 | for exp in $argv; do 16 | print "$exp = $(( exp ))"; 17 | done 18 | } 19 | 20 | function psgrep() { 21 | grep "$1" =(ps aux) 22 | } 23 | 24 | function run-with-sudo() { 25 | LBUFFER="sudo $LBUFFER" 26 | } 27 | zle -N run-with-sudo 28 | 29 | function zsh_update() { 30 | pushd "${ZSH}" 31 | git pull --rebase origin master 32 | git submodule update --init --recursive --rebase 33 | antigen reset 34 | antigen update 35 | popd 2>/dev/null 36 | } 37 | -------------------------------------------------------------------------------- /lib/S10.termsupport.zsh: -------------------------------------------------------------------------------- 1 | #usage: title short_tab_title looooooooooooooooooooooggggggg_windows_title 2 | #http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1 3 | #Fully support screen, iterm, and probably most modern xterm and rxvt 4 | #Limited support for Apple Terminal (Terminal can't set window or tab separately) 5 | function title { 6 | if [[ "$DISABLE_AUTO_TITLE" == "true" ]] || [[ "$EMACS" == *term* ]]; then 7 | return 8 | fi 9 | if [[ "$TERM" == screen* ]]; then 10 | print -Pn "\ek$1:q\e\\" #set screen hardstatus, usually truncated at 20 chars 11 | elif [[ "$TERM" == xterm* ]] || [[ $TERM == rxvt* ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then 12 | print -Pn "\e]2;$2:q\a" #set window name 13 | print -Pn "\e]1;$1:q\a" #set icon (=tab) name (will override window name on broken terminal) 14 | fi 15 | } 16 | 17 | ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD 18 | ZSH_THEME_TERM_TITLE_IDLE="%n@%m: %~" 19 | 20 | #Appears when you have the prompt 21 | function omz_termsupport_precmd { 22 | title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE 23 | } 24 | 25 | #Appears at the beginning of (and during) of command execution 26 | function omz_termsupport_preexec { 27 | emulate -L zsh 28 | setopt extended_glob 29 | local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd 30 | title "$CMD" "%100>...>$2%<<" 31 | } 32 | 33 | autoload -U add-zsh-hook 34 | add-zsh-hook precmd omz_termsupport_precmd 35 | add-zsh-hook preexec omz_termsupport_preexec 36 | -------------------------------------------------------------------------------- /lib/S15.edit-command-line.zsh: -------------------------------------------------------------------------------- 1 | autoload -U edit-command-line 2 | zle -N edit-command-line 3 | bindkey '\C-x\C-e' edit-command-line 4 | -------------------------------------------------------------------------------- /lib/S15.key-binding.zsh: -------------------------------------------------------------------------------- 1 | setopt vi 2 | bindkey -v 3 | bindkey '\ew' kill-region 4 | bindkey -s '\el' "ls\n" 5 | bindkey '^E' history-incremental-search-backward 6 | 7 | # bind internal functions 8 | bindkey '^Xs' run-with-sudo 9 | 10 | # zaw bindings 11 | bindkey '^W' zaw-bookmark 12 | bindkey '^R' zaw-history 13 | 14 | # make search up and down work, so partially type and hit up/down to find relevant stuff 15 | bindkey '^[[A' up-line-or-search 16 | bindkey '^[[B' down-line-or-search 17 | 18 | bindkey "^[[H" beginning-of-line 19 | bindkey "^[[1~" beginning-of-line 20 | bindkey "^[OH" beginning-of-line 21 | bindkey "^[[F" end-of-line 22 | bindkey "^[[4~" end-of-line 23 | bindkey "^[OF" end-of-line 24 | bindkey ' ' magic-space # also do history expansion on space 25 | 26 | bindkey "^[[1;5D" backward-word 27 | bindkey "^[[1;5C" forward-word 28 | 29 | bindkey '^[[Z' reverse-menu-complete 30 | 31 | # Make the delete key (or Fn + Delete on the Mac) work instead of outputting a ~ 32 | bindkey '^?' backward-delete-char 33 | bindkey "^[[3~" delete-char 34 | bindkey "^[3;5~" delete-char 35 | bindkey "\e[3~" delete-char 36 | 37 | bindkey "\e[5~" history-beginning-search-backward # PageUp 38 | bindkey "\e[6~" history-beginning-search-forward # PageDown 39 | bindkey "\e[1~" beginning-of-line # Home 40 | bindkey "\e[4~" end-of-line # End 41 | # for rxvt 42 | bindkey "\e[7~" beginning-of-line # Home 43 | bindkey "\e[8~" end-of-line # End 44 | # for xterm 45 | bindkey "\eOH" beginning-of-line 46 | bindkey "\eOF" end-of-line 47 | # for guake 48 | bindkey "\eOF" end-of-line 49 | bindkey "\eOH" beginning-of-line 50 | bindkey "\e[3~" delete-char # Del 51 | -------------------------------------------------------------------------------- /lib/S15.spectrum.zsh: -------------------------------------------------------------------------------- 1 | #! /bin/zsh 2 | # A script to make using 256 colors in zsh less painful. 3 | # P.C. Shyamshankar 4 | # Copied from http://github.com/sykora/etc/blob/master/zsh/functions/spectrum/ 5 | 6 | typeset -Ag FX FG BG 7 | 8 | FX=( 9 | reset "%{%}" 10 | bold "%{%}" no-bold "%{%}" 11 | italic "%{%}" no-italic "%{%}" 12 | underline "%{%}" no-underline "%{%}" 13 | blink "%{%}" no-blink "%{%}" 14 | reverse "%{%}" no-reverse "%{%}" 15 | ) 16 | 17 | for color in {000..255}; do 18 | FG[$color]="%{[38;5;${color}m%}" 19 | BG[$color]="%{[48;5;${color}m%}" 20 | done 21 | 22 | # Show all 256 colors with color number 23 | function spectrum_ls() { 24 | for code in {000..255}; do 25 | print -P -- "$code: %F{$code}Test%f" 26 | done 27 | } 28 | 29 | -------------------------------------------------------------------------------- /lib/S20.completion.zsh: -------------------------------------------------------------------------------- 1 | unsetopt menu_complete # do not autoselect the first completion entry 2 | unsetopt flowcontrol 3 | setopt auto_menu # show completion menu on succesive tab press 4 | setopt completeinword # we want completion to be done from cursor in word 5 | setopt alwaystoend 6 | setopt extendedglob 7 | setopt case_glob # case sensitive globbing 8 | 9 | WORDCHARS='' 10 | 11 | zmodload -i zsh/complist 12 | 13 | zstyle ':completion:*' use-cache on 14 | zstyle ':completion:*' cache-path "${ZSH}/cache" 15 | zstyle ':completion:*' completer _expand _complete _ignored _approximate 16 | zstyle ':completion:*' matcher-list '+m:{a-z}={A-Z} r:|[._-]=** r:|=**' '' '' '+m:{a-z}={A-Z} r:|[._-]=** r:|=**' 17 | zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} 18 | 19 | zstyle ':completion:*:*:*:*:*' menu select 20 | zstyle ':completion:*' menu select=2 21 | zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s' 22 | zstyle ':completion::complete:*' use-cache 1 23 | zstyle ':completion:*:descriptions' format '%U%F{cyan}%d%f%u' 24 | zstyle ':completion:*:*:xdvi:*' menu yes select 25 | zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01' 26 | zstyle ':completion:*:kill:*' force-list always 27 | zstyle ':completion:*:*:*:*:processes' command "ps -u `whoami` -o pid,user,comm -w -w" 28 | 29 | # disable named-directories autocompletion 30 | zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories 31 | cdpath=(.) 32 | 33 | # use /etc/hosts and known_hosts for hostname completion 34 | [ -r /etc/ssh/ssh_known_hosts ] && _global_ssh_hosts=(${${${${(f)"$( /dev/null) || return 4 | echo "($ruby_version)" 5 | } 6 | 7 | 8 | -------------------------------------------------------------------------------- /lib/S40.plugin.zsh: -------------------------------------------------------------------------------- 1 | # check if a plugin is valid withhin a base 2 | is_plugin() { 3 | local base_dir=$1 4 | local name=$2 5 | is_plugin_source $1 $2 \ 6 | || test -f $base_dir/plugin/$name/_$name 7 | } 8 | 9 | # check if a plugin is a source script 10 | is_plugin_source() { 11 | local base_dir=$1 12 | local name=$2 13 | test -f $base_dir/plugin/$name/$name.plugin.zsh 14 | } 15 | 16 | # load all plugins passed as parameters 17 | load_plugin() { 18 | for plugin ($*); do 19 | # add all defined plugins to fpath 20 | # must be done before running compinit 21 | if is_plugin $ZSH_CUSTOM $plugin; then 22 | fpath=($ZSH_CUSTOM/plugin/$plugin $fpath) 23 | elif is_plugin $ZSH $plugin; then 24 | fpath=($ZSH/plugin/$plugin $fpath) 25 | fi 26 | # load the plugin if a plugin file exists 27 | if is_plugin $ZSH_CUSTOM $plugin; then 28 | source $ZSH_CUSTOM/plugin/$plugin/$plugin.plugin.zsh 29 | elif is_plugin $ZSH $plugin; then 30 | source $ZSH/plugin/$plugin/$plugin.plugin.zsh 31 | else 32 | antigen bundle $plugin 33 | fi 34 | done 35 | } 36 | 37 | -------------------------------------------------------------------------------- /lib/S40.theme.zsh: -------------------------------------------------------------------------------- 1 | # ls colors 2 | autoload -U promptinit 3 | promptinit 4 | 5 | setopt no_beep 6 | setopt auto_cd 7 | setopt multios 8 | setopt cdablevarS 9 | 10 | if [[ x$WINDOW != x ]] 11 | then 12 | SCREEN_NO="%B$WINDOW%b " 13 | else 14 | SCREEN_NO="" 15 | fi 16 | 17 | # Apply theming defaults 18 | PS1="%n@%m:%~%# " 19 | 20 | # Setup the prompt with pretty colors 21 | setopt prompt_subst 22 | -------------------------------------------------------------------------------- /lib/S99.post-plugin.zsh: -------------------------------------------------------------------------------- 1 | # zaw 2 | BOOKMARKFILE=~/.config/zsh/zaw-bookmarks 3 | mkdir -p $(dirname "$BOOKMARKFILE") 4 | bindkey '^W' zaw-bookmark 5 | bindkey '^R' zaw-history 6 | -------------------------------------------------------------------------------- /plugin/ccache/ccache.plugin.zsh: -------------------------------------------------------------------------------- 1 | # check if ccache module is disabled 2 | if [ "$ZSH_CCACHE_DISABLE" = "1" ]; then return; fi 3 | 4 | # check if ccache already in PATH 5 | case $PATH in */usr/lib/ccache/bin* ) return;; esac 6 | 7 | # prepend ccache bin dir to PATH 8 | if [ -d "/usr/lib/ccache/bin" ]; then 9 | export PATH="/usr/lib/ccache/bin/:$PATH" 10 | fi 11 | -------------------------------------------------------------------------------- /plugin/cowfortune/cowfortune.plugin.zsh: -------------------------------------------------------------------------------- 1 | # check if cowfortune is disabled 2 | if [ "$ZSH_COWFORTUNE_DISABLE" = "1" ]; then return; fi 3 | 4 | # check if cowfortune exists 5 | if [ ! -f "$(which cowfortune)" ]; then return; fi 6 | 7 | cowfortune 8 | -------------------------------------------------------------------------------- /plugin/virtualenv/virtualenv.plugin.zsh: -------------------------------------------------------------------------------- 1 | # disables prompt mangling in virtual_env/bin/activate 2 | export VIRTUAL_ENV_DISABLE_PROMPT=1 3 | 4 | # source virtualenvwrapper.sh if it exists 5 | ZSH_VIRTUALENV_WRAPPER=$(which virtualenvwrapper.sh 2>/dev/null) 6 | if [ 0 -eq $? ]; then 7 | source ${ZSH_VIRTUALENV_WRAPPER} 8 | fi 9 | 10 | # virtualenv prompt theme options 11 | ZSH_THEME_VIRTUALENV_PROMPT_PREFIX="%{${reset_color}%}%{$fg[red]%}[%{${reset_color}%}" 12 | ZSH_THEME_VIRTUALENV_PROMPT_SUFFIX="%{${reset_color}%}%{$fg[red]%}]%{${reset_color}%}" 13 | ZSH_THEME_VIRTUALENV_PROMPT_ENVNAME="%{${reset_color}%}%{$fg_bold[yellow]%}" 14 | ZSH_THEME_VIRTUALENV_PROMPT_EMPTY="" 15 | 16 | function virtualenv_prompt_info(){ 17 | if [[ -n $VIRTUAL_ENV ]]; then 18 | printf "%s%s%s%s" "${ZSH_THEME_VIRTUALENV_PROMPT_PREFIX}" "${ZSH_THEME_VIRTUALENV_PROMPT_ENVNAME}" "${${VIRTUAL_ENV}:t}" "${ZSH_THEME_VIRTUALENV_PROMPT_SUFFIX}" 19 | return 20 | fi 21 | printf "%s" "${ZSH_THEME_VIRTUALENV_PROMPT_EMPTY}" 22 | } 23 | -------------------------------------------------------------------------------- /template/zshenv.zsh-template: -------------------------------------------------------------------------------- 1 | skip_global_compinit=1 2 | ZSH=~/.zsh 3 | -------------------------------------------------------------------------------- /template/zshrc.zsh-template: -------------------------------------------------------------------------------- 1 | # set the zsh theme 2 | ZSH_THEME=anthraxx 3 | 4 | # source the init script that loads everything 5 | source $ZSH/ant-zsh.zsh 6 | 7 | -------------------------------------------------------------------------------- /theme/anthraxx.zsh: -------------------------------------------------------------------------------- 1 | autoload -Uz vcs_info 2 | setopt transientrprompt 3 | 4 | PR_GIT_UPDATE=1 5 | PR_PROMPT_COLUMNS= 6 | ZSH_THEME_GIT_PROMPT_PREFIX="%{${reset_color}%}%{$fg[red]%}[%{${reset_color}%}" 7 | ZSH_THEME_GIT_PROMPT_SUFFIX="%{${reset_color}%}%{$fg[red]%}]%{${reset_color}%}" 8 | ZSH_THEME_GIT_PROMPT_SEPARATOR="%{${reset_color}%}%{$fg[red]%}|%{${reset_color}%}" 9 | ZSH_THEME_GIT_PROMPT_BRANCH="%{${reset_color}%}%{$fg_bold[blue]%}" 10 | update_current_git_vars 11 | 12 | N=$'%1(l.\n.)' 13 | MODE_INDICATOR="%{$fg_bold[yellow]%}vi %{$fg[red]%}<%{$reset_color%}" 14 | RPS1='$(vi_mode_prompt_info)' 15 | VIRTUALENV_INDICATOR='$(virtualenv_prompt_info)' 16 | 17 | prompt_anthraxx_setup () { 18 | local -a pcc 19 | local -A pc 20 | local p_date p_tty p_plat p_userpwd p_apm p_shlvlhist p_rc p_end p_win 21 | local p_first 22 | 23 | pcc[1]=${1:-${${SSH_CLIENT+'yellow'}:-'red'}} 24 | pcc[2]=${2:-'blue'} 25 | pcc[3]=${3:-'green'} 26 | pcc[4]=${4:-'yellow'} 27 | pcc[5]=${5:-'white'} 28 | 29 | pc['\[']="%F{$pcc[1]}[" 30 | pc['\]']="%F{$pcc[1]}]" 31 | pc['<']="%F{$pcc[1]}<" 32 | pc['>']="%F{$pcc[1]}>" 33 | pc['\(']="%F{$pcc[1]}(" 34 | pc['\)']="%F{$pcc[1]})" 35 | 36 | p_date="$pc['\[']%F{$pcc[2]}%D{%a %y/%m/%d %R %Z}$pc['\]']" 37 | p_tty="$pc['\[']%F{$pcc[3]}%l$pc['\]']" 38 | p_plat="$pc['\[']%F{$pcc[2]}${MACHTYPE}/${OSTYPE}/$(uname -r)$pc['\]']" 39 | 40 | [[ -n "$WINDOW" ]] && p_win="$pc['\(']%F{$pcc[4]}$WINDOW$pc['\)']" 41 | 42 | p_userpwd="$pc['\[']%F{$pcc[3]}%n%F{$pcc[1]}@%F{$pcc[3]}%m$p_win%F{$pcc[5]}:%F{$pcc[4]}%~$pc['\]']" 43 | p_vcs='$(git_super_status)' 44 | 45 | p_shlvlhist="$pc['\[']%F{$pcc[2]}zsh%(2L./$SHLVL.)$pc['\]']$pc['\[']%F{$pcc[4]}%h%b$pc['\]']" 46 | p_rc="%(?..[%F{$pcc[2]}%?%1v$pc['\]'])" 47 | p_end="%F{$pcc[2]}%F{$pcc[5]}%B> %b%f" 48 | 49 | zle_highlight[(r)default:*]=default:$pcc[2] 50 | p_first="$p_date$p_tty$p_plat" 51 | local p_first_end="" 52 | local prompt_line_width=${#${(S%%)p_first//(\%([KF1]|)\{*\}|\%[Bbkf])}} 53 | local prompt_line_end_width=${#${(S%%)p_first_end//(\%([KF1]|)\{*\}|\%[Bbkf])}} 54 | local prompt_padding_size=$(( COLUMNS - prompt_line_width - prompt_line_end_width )) 55 | if (( prompt_padding_size > 0 )); then 56 | local prompt_padding 57 | eval "prompt_padding=\${(l:${prompt_padding_size}::─:)_empty_zz}" 58 | p_first="$p_first$prompt_padding$p_first_end" 59 | fi 60 | 61 | prompt="$p_first$N$p_userpwd$N$p_shlvlhist$p_rc${VIRTUALENV_INDICATOR}$p_vcs$p_end" 62 | PS2='%(4_.\.)%3_> %E' 63 | } 64 | 65 | prompt_anthraxx_precmd () { 66 | setopt noxtrace noksharrays localoptions 67 | local exitstatus=$? 68 | local git_dir git_ref 69 | 70 | psvar=() 71 | [[ $exitstatus -ge 128 ]] && psvar[1]=" $signals[$exitstatus-127]" || 72 | psvar[1]="" 73 | 74 | [[ -o interactive ]] && jobs -l 75 | 76 | if [[ -n "$PR_GIT_UPDATE" ]] ; then 77 | vcs_info 'prompt' 78 | PR_GIT_UPDATE= 79 | fi 80 | if [[ $COLUMNS -ne $PR_PROMPT_COLUMNS ]] ; then 81 | prompt_anthraxx_setup 82 | PR_PROMPT_COLUMNS="$COLUMNS" 83 | fi 84 | } 85 | 86 | prompt_anthraxx_preexec() { 87 | case $(history $HISTCMD) in 88 | git*|hub*|gh*|stg*) 89 | PR_GIT_UPDATE=1 90 | ;; 91 | esac 92 | } 93 | 94 | prompt_anthraxx_chpwd() { 95 | PR_GIT_UPDATE=1 96 | } 97 | 98 | add-zsh-hook precmd prompt_anthraxx_precmd 99 | add-zsh-hook preexec prompt_anthraxx_preexec 100 | add-zsh-hook chpwd prompt_anthraxx_chpwd 101 | prompt_anthraxx_setup 102 | 103 | --------------------------------------------------------------------------------