From 7bb0e8e1c7ec3c829a20bcd7a96ce2ebfbbc6731 Mon Sep 17 00:00:00 2001 From: Joe Groocock Date: Wed, 15 Nov 2017 23:06:29 +0000 Subject: [PATCH] Overhaul ZSH config, remove oh-my-zsh --- .config/zsh/fish-theme.zsh | 83 ++++++++++++++++++++++++++ .zshrc | 117 ++++++++++++++++++++----------------- 2 files changed, 147 insertions(+), 53 deletions(-) create mode 100644 .config/zsh/fish-theme.zsh diff --git a/.config/zsh/fish-theme.zsh b/.config/zsh/fish-theme.zsh new file mode 100644 index 0000000..9e961ce --- /dev/null +++ b/.config/zsh/fish-theme.zsh @@ -0,0 +1,83 @@ +# ZSH Theme emulating the Fish shell's default prompt. + +_fishy_collapsed_wd() { + echo $(pwd | perl -pe ' + BEGIN { + binmode STDIN, ":encoding(UTF-8)"; + binmode STDOUT, ":encoding(UTF-8)"; + }; s|^$ENV{HOME}|~|g; s|/([^/.])[^/]*(?=/)|/$1|g; s|/\.([^/])[^/]*(?=/)|/.$1|g +') +} + +git_prompt_info() { + ref=$(git symbolic-ref HEAD 2> /dev/null) || return + echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$ZSH_THEME_GIT_PROMPT_SUFFIX" +} +git_prompt_status() { + # Get the status of the working tree + INDEX=$(command git status --porcelain -b 2> /dev/null) + STATUS="" + if $(echo "$INDEX" | grep -E '^\?\? ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS" + fi + if $(echo "$INDEX" | grep '^A ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS" + elif $(echo "$INDEX" | grep '^M ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS" + fi + if $(echo "$INDEX" | grep '^ M ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" + elif $(echo "$INDEX" | grep '^AM ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" + elif $(echo "$INDEX" | grep '^ T ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" + fi + if $(echo "$INDEX" | grep '^R ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_RENAMED$STATUS" + fi + if $(echo "$INDEX" | grep '^ D ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" + elif $(echo "$INDEX" | grep '^D ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" + elif $(echo "$INDEX" | grep '^AD ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" + fi + if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then + STATUS="$ZSH_THEME_GIT_PROMPT_STASHED$STATUS" + fi + if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS" + fi + if $(echo "$INDEX" | grep '^## .*ahead' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_AHEAD$STATUS" + fi + if $(echo "$INDEX" | grep '^## .*behind' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_BEHIND$STATUS" + fi + if $(echo "$INDEX" | grep '^## .*diverged' &> /dev/null); then + STATUS="$ZSH_THEME_GIT_PROMPT_DIVERGED$STATUS" + fi + echo $STATUS +} + +# Required for dynamic prompt +setopt prompt_subst + +local user_color='green'; [ $UID -eq 0 ] && user_color='red' +PROMPT="%n@%m %F{$user_color}\$(_fishy_collapsed_wd)%f%(!.#.>) " +PROMPT2='%F{red}\ %f' + +local return_status="%F{red}%(?..%?)%f" +RPROMPT='${return_status}$(git_prompt_info)$(git_prompt_status)%{$reset_color%}' + +ZSH_THEME_GIT_PROMPT_PREFIX=" " +ZSH_THEME_GIT_PROMPT_SUFFIX="" +ZSH_THEME_GIT_PROMPT_DIRTY="" +ZSH_THEME_GIT_PROMPT_CLEAN="" + +ZSH_THEME_GIT_PROMPT_ADDED="%{$fg_bold[green]%}+" +ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg_bold[blue]%}!" +ZSH_THEME_GIT_PROMPT_DELETED="%{$fg_bold[red]%}-" +ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg_bold[magenta]%}>" +ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg_bold[yellow]%}#" +ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[cyan]%}?" diff --git a/.zshrc b/.zshrc index d7a3ff9..32c1c5e 100644 --- a/.zshrc +++ b/.zshrc @@ -1,22 +1,17 @@ unsetopt MULTIBYTE -# Path to your oh-my-zsh installation. -ZSH=$HOME/.local/share/oh-my-zsh - -# Set the theme -ZSH_THEME="fishy" -#DISABLE_AUTO_UPDATE="true" - +# Config and cache directory paths CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}" -ZSH_CONFIG_DIR=$CONFIG_DIR/zsh -ZSH_CACHE_DIR=$CONFIG_DIR/oh-my-zsh/cache -mkdir -p $ZSH_CACHE_DIR $ZSH_CONFIG_DIR +ZSH_DIR="$CONFIG_DIR/zsh" +ZSH_CACHE_DIR="$CONFIG_DIR/oh-my-zsh/cache" +ADOTDIR="$ZSH_DIR/antigen" # Antigen directory +ANTIGEN_LOG="$ADOTDIR/log/antigen-$(date +"%Y_%m_%d_%I_%M_%p").log" -HISTFILE=$ZSH_CONFIG_DIR/histfile -HISTSIZE=100000 -SAVEHIST=100000 -setopt sharehistory histignorealldups histignorespace histreduceblanks -setopt pathdirs autocd autopushd extendedglob alwaystoend dvorak +mkdir -p "$ZSH_CACHE_DIR" "$ZSH_DIR" "$ADOTDIR/log" + +HISTFILE="$ZSH_DIR/histfile" +HISTSIZE=999999 +SAVEHIST=999999 # Only set tty if running interactively if tty -s; then @@ -24,14 +19,38 @@ if tty -s; then export GPG_TTY="$(tty)" fi -export WORDCHARS='*?_[]~=&;!#$%^(){}' +# Set some useful ZSH/Bash options +setopt sharehistory histignorealldups histignorespace histreduceblanks +setopt pathdirs autocd autopushd extendedglob alwaystoend dvorak +# Load antigen & plugins +source "$ZSH_DIR/antigen.zsh" + +antigen bundle sudo +antigen bundle zsh-users/zsh-completions +antigen bundle zsh-users/zsh-autosuggestions +antigen bundle Tarrasch/zsh-syntax-highlighting +antigen bundle zsh-users/zsh-history-substring-search + +antigen apply + +# Completion initialisation +autoload -U compinit ; compinit +autoload -U bashcompinit ; bashcompinit + +# gopass completion +if gopass --help &>/dev/null; then + source <(gopass completion bash) +fi + +# Set some key-binds bindkey -e -bindkey "\e[1;3C" forward-word -bindkey "\e[1;3D" backward-word +bindkey "^[[1;3C" forward-word +bindkey "^[[1;3D" backward-word bindkey "^[[7~" beginning-of-line bindkey "^[[8~" end-of-line +export WORDCHARS='*?_[]~=&;!#$%^(){}' x-bash-backward-kill-word(){ WORDCHARS='' zle kill-word } @@ -39,60 +58,52 @@ zle -N x-bash-backward-kill-word bindkey '^[^[[3~' x-bash-backward-kill-word bindkey '^[^[[3^' x-bash-backward-kill-word -autoload -U up-line-or-beginning-search -autoload -U down-line-or-beginning-search -zle -N up-line-or-beginning-search -zle -N down-line-or-beginning-search -bindkey "^[[A" up-line-or-beginning-search # Up -bindkey "^[^[[A" up-line-or-beginning-search # Up -bindkey "^[[B" down-line-or-beginning-search # Down -bindkey "^[^[[B" down-line-or-beginning-search # Down +bindkey '^[[A' history-substring-search-up +bindkey '^[[B' history-substring-search-down zstyle ':completion:*:sudo|_::' environ PATH="/sbin:/usr/sbin:$PATH" HOME="/root" zstyle ':completion:*' matcher-list '' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'r:|[._-]=** r:|=**' 'l:|=* r:|=*' zstyle ':completion:*' rehash true zstyle :compinstall filename "$HOME/.zshrc" - -autoload -U compinit ; compinit -autoload -U bashcompinit ; bashcompinit - -plugins=(command-not-found history-substring-search sudo zsh-autosuggestions zsh-completions) -source $ZSH/oh-my-zsh.sh -source $ZSH/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh - -if gopass --help &>/dev/null; then - source <(gopass completion bash) -fi +zstyle ':completion:*:*:*:*:*' menu select +zstyle ':completion:*' list-colors "${(@s.:.)LS_COLORS}" ZSH_AUTOSUGGEST_CLEAR_WIDGETS=("${(@)ZSH_AUTOSUGGEST_CLEAR_WIDGETS:#(up|down)-line-or-history}") ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(history-substring-search-up history-substring-search-down) -ZSH_HIGHLIGHT_STYLES[default]='fg=blue' +HISTORY_SUBSTRING_SEARCH_FUZZY=true +HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=true +HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='underline' + +typeset -A ZSH_HIGHLIGHT_STYLES +ZSH_HIGHLIGHT_STYLES[default]='fg=12' ZSH_HIGHLIGHT_STYLES[unknown-token]='fg=red,bold' ZSH_HIGHLIGHT_STYLES[reserved-word]='fg=yellow' -ZSH_HIGHLIGHT_STYLES[alias]='fg=63' +ZSH_HIGHLIGHT_STYLES[alias]='fg=blue' ZSH_HIGHLIGHT_STYLES[suffix-alias]='fg=green,underline' -ZSH_HIGHLIGHT_STYLES[builtin]='fg=63' -ZSH_HIGHLIGHT_STYLES[function]='fg=63' -ZSH_HIGHLIGHT_STYLES[command]='fg=63' -ZSH_HIGHLIGHT_STYLES[precommand]='fg=63' -ZSH_HIGHLIGHT_STYLES[commandseparator]='fg=blue' +ZSH_HIGHLIGHT_STYLES[builtin]='fg=blue' +ZSH_HIGHLIGHT_STYLES[function]='fg=blue' +ZSH_HIGHLIGHT_STYLES[command]='fg=blue' +ZSH_HIGHLIGHT_STYLES[precommand]='fg=blue' +ZSH_HIGHLIGHT_STYLES[commandseparator]='fg=cyan' ZSH_HIGHLIGHT_STYLES[hashed-command]='fg=green' -ZSH_HIGHLIGHT_STYLES[path]='fg=63,underline' +ZSH_HIGHLIGHT_STYLES[path]='fg=blue' ZSH_HIGHLIGHT_STYLES[path_prefix]='fg=yellow,bold' -ZSH_HIGHLIGHT_STYLES[path_approx]='fg=red,bold,underline' +ZSH_HIGHLIGHT_STYLES[path_approx]='fg=red,bold' ZSH_HIGHLIGHT_STYLES[globbing]='fg=red' -ZSH_HIGHLIGHT_STYLES[history-expansion]='fg=blue' -ZSH_HIGHLIGHT_STYLES[single-hyphen-option]='fg=blue' -ZSH_HIGHLIGHT_STYLES[double-hyphen-option]='fg=blue' -ZSH_HIGHLIGHT_STYLES[back-quoted-argument]='none' +ZSH_HIGHLIGHT_STYLES[comment]='fg=7' +ZSH_HIGHLIGHT_STYLES[history-expansion]='fg=1' +ZSH_HIGHLIGHT_STYLES[single-hyphen-option]='fg=12' +ZSH_HIGHLIGHT_STYLES[double-hyphen-option]='fg=12' +ZSH_HIGHLIGHT_STYLES[back-quoted-argument]='fg=magenta' ZSH_HIGHLIGHT_STYLES[single-quoted-argument]='fg=yellow' ZSH_HIGHLIGHT_STYLES[double-quoted-argument]='fg=yellow' ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]='fg=yellow' ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]='fg=cyan' ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]='fg=cyan' ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]='fg=cyan' -ZSH_HIGHLIGHT_STYLES[assign]='none' -ZSH_HIGHLIGHT_STYLES[redirection]='none' +ZSH_HIGHLIGHT_STYLES[assign]='fg=green' +ZSH_HIGHLIGHT_STYLES[redirection]='fg=cyan' -source $DOTFILES/aliases +source "$ZSH_DIR/fish-theme.zsh" +source "$DOTFILES/aliases"