From: Ben Beltran Date: Sun, 16 Feb 2020 13:40:26 +0000 (+0100) Subject: Remove prezto X-Git-Url: https://git.r.bdr.sh/rbdr/dotfiles/commitdiff_plain/fa25023586cb94a1abf4fd3ff95ebe7c3c8ead09?hp=f6272d88eae76c8553f237f3f318c4a97997f262 Remove prezto --- diff --git a/runcoms/zlogin b/runcoms/zlogin new file mode 100644 index 0000000..8af0975 --- /dev/null +++ b/runcoms/zlogin @@ -0,0 +1,25 @@ +# +# Executes commands at login post-zshrc. +# +# Authors: +# Sorin Ionescu +# + +# Execute code that does not affect the current session in the background. +{ + # Compile the completion dump to increase startup speed. + zcompdump="${ZDOTDIR:-$HOME}/.zcompdump" + if [[ -s "$zcompdump" && (! -s "${zcompdump}.zwc" || "$zcompdump" -nt "${zcompdump}.zwc") ]]; then + zcompile "$zcompdump" + fi +} &! + +# Print a random, hopefully interesting, adage. +if (( $+commands[fortune] )); then + echo -en "\033[30m" + if [[ -t 0 || -t 1 ]]; then + fortune -s + print + fi + echo -en "\033[m" +fi diff --git a/zsh/modules/terminal.zsh b/runcoms/zlogout similarity index 100% rename from zsh/modules/terminal.zsh rename to runcoms/zlogout diff --git a/runcoms/zprofile b/runcoms/zprofile new file mode 100644 index 0000000..b18b307 --- /dev/null +++ b/runcoms/zprofile @@ -0,0 +1,74 @@ +# +# Executes commands at login pre-zshrc. +# +# Authors: +# Sorin Ionescu +# + +# +# Browser +# + +if [[ "$OSTYPE" == darwin* ]]; then + export BROWSER='open' +fi + +# +# Editors +# + +export EDITOR='vi' +export VISUAL='vi' +export PAGER='less' + +# +# Language +# + +if [[ -z "$LANG" ]]; then + export LANG='en_US.UTF-8' +fi + +# +# Paths +# + +# Ensure path arrays do not contain duplicates. +typeset -gU cdpath fpath mailpath path + +# Set the the list of directories that cd searches. +# cdpath=( +# $cdpath +# ) + +# Set the list of directories that Zsh searches for programs. +path=( + /usr/local/{bin,sbin} + $path +) + +# +# Less +# + +# Set the default Less options. +# Mouse-wheel scrolling has been disabled by -X (disable screen clearing). +# Remove -X and -F (exit if the content fits on one screen) to enable it. +export LESS='-F -g -i -M -R -S -w -X -z-4' + +# Set the Less input preprocessor. +# Try both `lesspipe` and `lesspipe.sh` as either might exist on a system. +if (( $#commands[(i)lesspipe(|.sh)] )); then + export LESSOPEN="| /usr/bin/env $commands[(i)lesspipe(|.sh)] %s 2>&-" +fi + +# +# Temporary Files +# + +if [[ ! -d "$TMPDIR" ]]; then + export TMPDIR="/tmp/$LOGNAME" + mkdir -p -m 700 "$TMPDIR" +fi + +TMPPREFIX="${TMPDIR%/}/zsh" diff --git a/runcoms/zshenv b/runcoms/zshenv new file mode 100644 index 0000000..2d97203 --- /dev/null +++ b/runcoms/zshenv @@ -0,0 +1,11 @@ +# +# Defines environment variables. +# +# Authors: +# Sorin Ionescu +# + +# Ensure that a non-login, non-interactive shell has a defined environment. +if [[ "$SHLVL" -eq 1 && ! -o LOGIN && -s "${ZDOTDIR:-$HOME}/.zprofile" ]]; then + source "${ZDOTDIR:-$HOME}/.zprofile" +fi diff --git a/runcoms/zshrc b/runcoms/zshrc new file mode 100644 index 0000000..189c40d --- /dev/null +++ b/runcoms/zshrc @@ -0,0 +1,64 @@ +################################################################################ +# Load Functions +################################################################################ +source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/functions/git-info.zsh" +source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/functions/dotenv.zsh" +source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/functions/graphviz.zsh" +source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/functions/short-uptime.zsh" + +################################################################################ +# Load Modules +################################################################################ +source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/modules/environment.zsh" +source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/modules/editor.zsh" +source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/modules/history.zsh" +source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/modules/directory.zsh" +source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/modules/prompt.zsh" +source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/modules/vendor/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" +source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/modules/completion.zsh" +source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/modules/aliases.zsh" + +################################################################################ +# ENV VARIABLES +################################################################################ +# Terminal related +export TERM=xterm-256color-italic + +# Paths +# export JAVA_HOME=$(/usr/libexec/java_home) # Enable if using JDK, otherwise disable for performance +export GOPATH=$HOME/Projects/go +export NODE_PATH=/usr/local/lib/node_modules:$NODE_PATH +export ANDROID_HOME=$HOME/Library/Android/sdk +export ANDROID_NDK_HOME=$HOME/Library/Android/sdk/ndk-bundle +export NVM_DIR=$HOME/.nvm +export PATH=/usr/local/bin:/usr/local/sbin:$PATH +export PATH=$PATH:$HOME/Library/Python/2.7/bin +export PATH=$PATH:$HOME:/usr/local/opt/go/libexec/bin:${GOPATH//://bin:}/bin +export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_NDK_HOME:/Applications/calibre.app/Contents/MacOS + +# Editor. +export EDITOR="vim" +export VISUAL="vim" + +# Python related variables +export VIRTUAL_ENV_DISABLE_PROMPT=1 +export WORKON_HOME=$HOME/.virtualenvs +export PROJECT_HOME=$HOME/Projects +export VIRTUALENVWRAPPER_PYTHON="/usr/local/bin/python" + +# GPG +export GPG_TTY=$(tty) + +# FZF Config +export FZF_DEFAULT_COMMAND='/usr/local/bin/rg --color never --files --hidden -g \!.git' +export FZF_DEFAULT_OPTS='--preview ''bat --style=numbers --color=always {} | head -500''' + +################################################################################ +# SECRET ENV VARS!! +################################################################################ + +if [[ -s "${ZDOTDIR:-$HOME}/.secrets.zsh" ]]; then + source "${ZDOTDIR:-$HOME}/.secrets.zsh" +fi + +eval $(/usr/libexec/path_helper -s) diff --git a/zsh/functions/dotenv.zsh b/zsh/functions/dotenv.zsh new file mode 100644 index 0000000..7594e6c --- /dev/null +++ b/zsh/functions/dotenv.zsh @@ -0,0 +1,6 @@ +# Dotenv Loading utility function +dotenv () { + set -a + [ -f ./.env ] && . ./.env + set +a +} diff --git a/zsh/functions/git-info.zsh b/zsh/functions/git-info.zsh new file mode 100644 index 0000000..e74bd6a --- /dev/null +++ b/zsh/functions/git-info.zsh @@ -0,0 +1,417 @@ +# Exposes Git repository information via the $git_info associative array. +# +# Authors: +# Sorin Ionescu +# + +# Gets the Git special action (am, bisect, cherry, merge, rebase). +# Borrowed from vcs_info and edited. +function _git-action { + local action_dir + local git_dir="$(git-dir)" + local apply_formatted + local bisect_formatted + local cherry_pick_formatted + local cherry_pick_sequence_formatted + local merge_formatted + local rebase_formatted + local rebase_interactive_formatted + local rebase_merge_formatted + + for action_dir in \ + "${git_dir}/rebase-apply" \ + "${git_dir}/rebase" \ + "${git_dir}/../.dotest" + do + if [[ -d "$action_dir" ]] ; then + zstyle -s ':git:info:action:apply' format 'apply_formatted' || apply_formatted='apply' + zstyle -s ':git:info:action:rebase' format 'rebase_formatted' || rebase_formatted='rebase' + + if [[ -f "${action_dir}/rebasing" ]] ; then + print "$rebase_formatted" + elif [[ -f "${action_dir}/applying" ]] ; then + print "$apply_formatted" + else + print "${rebase_formatted}/${apply_formatted}" + fi + + return 0 + fi + done + + for action_dir in \ + "${git_dir}/rebase-merge/interactive" \ + "${git_dir}/.dotest-merge/interactive" + do + if [[ -f "$action_dir" ]]; then + zstyle -s ':git:info:action:rebase-interactive' format 'rebase_interactive_formatted' || rebase_interactive_formatted='rebase-interactive' + print "$rebase_interactive_formatted" + return 0 + fi + done + + for action_dir in \ + "${git_dir}/rebase-merge" \ + "${git_dir}/.dotest-merge" + do + if [[ -d "$action_dir" ]]; then + zstyle -s ':git:info:action:rebase-merge' format 'rebase_merge_formatted' || rebase_merge_formatted='rebase-merge' + print "$rebase_merge_formatted" + return 0 + fi + done + + if [[ -f "${git_dir}/MERGE_HEAD" ]]; then + zstyle -s ':git:info:action:merge' format 'merge_formatted' || merge_formatted='merge' + print "$merge_formatted" + return 0 + fi + + if [[ -f "${git_dir}/CHERRY_PICK_HEAD" ]]; then + if [[ -d "${git_dir}/sequencer" ]] ; then + zstyle -s ':git:info:action:cherry-pick-sequence' format 'cherry_pick_sequence_formatted' || cherry_pick_sequence_formatted='cherry-pick-sequence' + print "$cherry_pick_sequence_formatted" + else + zstyle -s ':git:info:action:cherry-pick' format 'cherry_pick_formatted' || cherry_pick_formatted='cherry-pick' + print "$cherry_pick_formatted" + fi + + return 0 + fi + + if [[ -f "${git_dir}/BISECT_LOG" ]]; then + zstyle -s ':git:info:action:bisect' format 'bisect_formatted' || bisect_formatted='bisect' + print "$bisect_formatted" + return 0 + fi + + return 1 +} + +# Gets the Git status information. +function git-info { + # Extended globbing is needed to parse repository status. + setopt LOCAL_OPTIONS + setopt EXTENDED_GLOB + + local action + local action_format + local action_formatted + local added=0 + local added_format + local added_formatted + local ahead=0 + local ahead_and_behind + local ahead_and_behind_cmd + local ahead_format + local ahead_formatted + local ahead_or_behind + local behind=0 + local behind_format + local behind_formatted + local branch + local branch_format + local branch_formatted + local branch_info + local clean + local clean_formatted + local commit + local commit_format + local commit_formatted + local deleted=0 + local deleted_format + local deleted_formatted + local dirty=0 + local dirty_format + local dirty_formatted + local ignore_submodules + local indexed=0 + local indexed_format + local indexed_formatted + local -A info_formats + local info_format + local modified=0 + local modified_format + local modified_formatted + local position + local position_format + local position_formatted + local remote + local remote_cmd + local remote_format + local remote_formatted + local renamed=0 + local renamed_format + local renamed_formatted + local stashed=0 + local stashed_format + local stashed_formatted + local status_cmd + local status_mode + local unindexed=0 + local unindexed_format + local unindexed_formatted + local unmerged=0 + local unmerged_format + local unmerged_formatted + local untracked=0 + local untracked_format + local untracked_formatted + + # Clean up previous $git_info. + unset git_info + typeset -gA git_info + + # Return if not inside a Git repository work tree. + if [ "$(git rev-parse --is-inside-work-tree 2> /dev/null)" != 'true' ]; then + return 1 + fi + + if (( $# > 0 )); then + if [[ "$1" == [Oo][Nn] ]]; then + git config --bool prompt.showinfo true + elif [[ "$1" == [Oo][Ff][Ff] ]]; then + git config --bool prompt.showinfo false + else + print "usage: $0 [ on | off ]" >&2 + fi + return 0 + fi + + # Ignore submodule status. + zstyle -s ':git:status:ignore' submodules 'ignore_submodules' + + # Format commit. + zstyle -s ':git:info:commit' format 'commit_format' + if [[ -n "$commit_format" ]]; then + commit="$(git rev-parse HEAD 2> /dev/null)" + if [[ -n "$commit" ]]; then + zformat -f commit_formatted "$commit_format" "c:$commit" + fi + fi + + # Format stashed. + zstyle -s ':git:info:stashed' format 'stashed_format' + if [[ -n "$stashed_format" && -f "$(git-dir)/refs/stash" ]]; then + stashed="$(git stash list 2> /dev/null | wc -l | awk '{print $1}')" + if [[ -n "$stashed" ]]; then + zformat -f stashed_formatted "$stashed_format" "S:$stashed" + fi + fi + + # Format action. + zstyle -s ':git:info:action' format 'action_format' + if [[ -n "$action_format" ]]; then + action="$(_git-action)" + if [[ -n "$action" ]]; then + zformat -f action_formatted "$action_format" "s:$action" + fi + fi + + # Get the branch. + branch="${$(git symbolic-ref HEAD 2> /dev/null)#refs/heads/}" + + # Format branch. + zstyle -s ':git:info:branch' format 'branch_format' + if [[ -n "$branch" && -n "$branch_format" ]]; then + zformat -f branch_formatted "$branch_format" "b:$branch" + fi + + # Format position. + zstyle -s ':git:info:position' format 'position_format' + if [[ -z "$branch" && -n "$position_format" ]]; then + position="$(git describe --contains --all HEAD 2> /dev/null)" + if [[ -n "$position" ]]; then + zformat -f position_formatted "$position_format" "p:$position" + fi + fi + + # Format remote. + zstyle -s ':git:info:remote' format 'remote_format' + if [[ -n "$branch" && -n "$remote_format" ]]; then + # Gets the remote name. + remote_cmd='git rev-parse --symbolic-full-name --verify HEAD@{upstream}' + remote="${$(${(z)remote_cmd} 2> /dev/null)##refs/remotes/}" + if [[ -n "$remote" ]]; then + zformat -f remote_formatted "$remote_format" "R:$remote" + fi + fi + + zstyle -s ':git:info:ahead' format 'ahead_format' + zstyle -s ':git:info:behind' format 'behind_format' + if [[ -n "$branch" && ( -n "$ahead_format" || -n "$behind_format" ) ]]; then + # Gets the commit difference counts between local and remote. + ahead_and_behind_cmd='git rev-list --count --left-right HEAD...@{upstream}' + + # Get ahead and behind counts. + ahead_and_behind="$(${(z)ahead_and_behind_cmd} 2> /dev/null)" + + # Format ahead. + if [[ -n "$ahead_format" ]]; then + ahead="$ahead_and_behind[(w)1]" + if (( ahead > 0 )); then + zformat -f ahead_formatted "$ahead_format" "A:$ahead" + fi + fi + + # Format behind. + if [[ -n "$behind_format" ]]; then + behind="$ahead_and_behind[(w)2]" + if (( behind > 0 )); then + zformat -f behind_formatted "$behind_format" "B:$behind" + fi + fi + fi + + # Get status type. + if ! zstyle -t ':git:info' verbose; then + # Format indexed. + zstyle -s ':git:info:indexed' format 'indexed_format' + if [[ -n "$indexed_format" ]]; then + (( + indexed+=$( + git diff-index \ + --no-ext-diff \ + --name-only \ + --cached \ + --ignore-submodules=${ignore_submodules:-none} \ + HEAD \ + 2> /dev/null \ + | wc -l + ) + )) + if (( indexed > 0 )); then + zformat -f indexed_formatted "$indexed_format" "i:$indexed" + fi + fi + + # Format unindexed. + zstyle -s ':git:info:unindexed' format 'unindexed_format' + if [[ -n "$unindexed_format" ]]; then + (( + unindexed+=$( + git diff-files \ + --no-ext-diff \ + --name-only \ + --ignore-submodules=${ignore_submodules:-none} \ + 2> /dev/null \ + | wc -l + ) + )) + if (( unindexed > 0 )); then + zformat -f unindexed_formatted "$unindexed_format" "I:$unindexed" + fi + fi + + # Format untracked. + zstyle -s ':git:info:untracked' format 'untracked_format' + if [[ -n "$untracked_format" ]]; then + (( + untracked+=$( + git ls-files \ + --other \ + --exclude-standard \ + 2> /dev/null \ + | wc -l + ) + )) + if (( untracked > 0 )); then + zformat -f untracked_formatted "$untracked_format" "u:$untracked" + fi + fi + + (( dirty = indexed + unindexed + untracked )) + else + # Use porcelain status for easy parsing. + status_cmd="git status --porcelain --ignore-submodules=${ignore_submodules:-none}" + + # Get current status. + while IFS=$'\n' read line; do + # Count added, deleted, modified, renamed, unmerged, untracked, dirty. + # T (type change) is undocumented, see http://git.io/FnpMGw. + # For a table of scenarii, see http://i.imgur.com/2YLu1.png. + [[ "$line" == ([ACDMT][\ MT]|[ACMT]D)\ * ]] && (( added++ )) + [[ "$line" == [\ ACMRT]D\ * ]] && (( deleted++ )) + [[ "$line" == ?[MT]\ * ]] && (( modified++ )) + [[ "$line" == R?\ * ]] && (( renamed++ )) + [[ "$line" == (AA|DD|U?|?U)\ * ]] && (( unmerged++ )) + [[ "$line" == \?\?\ * ]] && (( untracked++ )) + (( dirty++ )) + done < <(${(z)status_cmd} 2> /dev/null) + + # Format added. + if (( added > 0 )); then + zstyle -s ':git:info:added' format 'added_format' + zformat -f added_formatted "$added_format" "a:$added" + fi + + # Format deleted. + if (( deleted > 0 )); then + zstyle -s ':git:info:deleted' format 'deleted_format' + zformat -f deleted_formatted "$deleted_format" "d:$deleted" + fi + + # Format modified. + if (( modified > 0 )); then + zstyle -s ':git:info:modified' format 'modified_format' + zformat -f modified_formatted "$modified_format" "m:$modified" + fi + + # Format renamed. + if (( renamed > 0 )); then + zstyle -s ':git:info:renamed' format 'renamed_format' + zformat -f renamed_formatted "$renamed_format" "r:$renamed" + fi + + # Format unmerged. + if (( unmerged > 0 )); then + zstyle -s ':git:info:unmerged' format 'unmerged_format' + zformat -f unmerged_formatted "$unmerged_format" "U:$unmerged" + fi + + # Format untracked. + if (( untracked > 0 )); then + zstyle -s ':git:info:untracked' format 'untracked_format' + zformat -f untracked_formatted "$untracked_format" "u:$untracked" + fi + fi + + # Format dirty and clean. + if (( dirty > 0 )); then + zstyle -s ':git:info:dirty' format 'dirty_format' + zformat -f dirty_formatted "$dirty_format" "D:$dirty" + else + zstyle -s ':git:info:clean' format 'clean_formatted' + fi + + # Format info. + zstyle -a ':git:info:keys' format 'info_formats' + for info_format in ${(k)info_formats}; do + zformat -f REPLY "$info_formats[$info_format]" \ + "a:$added_formatted" \ + "A:$ahead_formatted" \ + "B:$behind_formatted" \ + "b:$branch_formatted" \ + "C:$clean_formatted" \ + "c:$commit_formatted" \ + "d:$deleted_formatted" \ + "D:$dirty_formatted" \ + "i:$indexed_formatted" \ + "I:$unindexed_formatted" \ + "m:$modified_formatted" \ + "p:$position_formatted" \ + "R:$remote_formatted" \ + "r:$renamed_formatted" \ + "s:$action_formatted" \ + "S:$stashed_formatted" \ + "U:$unmerged_formatted" \ + "u:$untracked_formatted" + git_info[$info_format]="$REPLY" + done + + unset REPLY + + return 0 +} + +git-info "$@" diff --git a/zsh/functions/graphviz.zsh b/zsh/functions/graphviz.zsh new file mode 100644 index 0000000..d7b4e12 --- /dev/null +++ b/zsh/functions/graphviz.zsh @@ -0,0 +1,24 @@ +# Graphviz functions +dot-to-png () { + if [[ -n "${1+x}" ]]; then + dot -Tpng $1 -o ${1%.*}.png + else + echo 'Usage: dot-to-png ' + fi +} + +neat-to-png () { + if [[ -n "${1+x}" ]]; then + neato -Tpng $1 -o ${1%.*}.png + else + echo 'Usage: dot-to-png ' + fi +} + +seqdiag-to-png () { + if [[ -n "${1+x}" ]]; then + seqdiag -o ${1%.*}.png -f /System/Library/Fonts/SFNSText.ttf $1 + else + echo 'Usage: seqdiag-to-png ' + fi +} diff --git a/zsh/functions/short-uptime.zsh b/zsh/functions/short-uptime.zsh new file mode 100644 index 0000000..0ab9849 --- /dev/null +++ b/zsh/functions/short-uptime.zsh @@ -0,0 +1,3 @@ +short-uptime () { + uptime | awk '{print $(3)"d "$(5)" "$(NF+0)" "$(NF-1)" "$(NF-0)}' +} diff --git a/zsh/modules/aliases.zsh b/zsh/modules/aliases.zsh new file mode 100644 index 0000000..2db24d9 --- /dev/null +++ b/zsh/modules/aliases.zsh @@ -0,0 +1,39 @@ +# File operations +alias cp="cp -i" +alias mv="mv -i" +alias rm="rm -i" +alias ls="ls -FG" + +# Lazy rgs +alias rgjs="rg -g '*.js' -g '*.svelte' -g '*.vue'" +alias rgrb="rg -g '*.rb'" +alias rgcss="rg -g '*.css'" + +# tmux +alias ta="tmux attach -t" +alias tn="tmux new -s" + +# Simple python server +alias spawn-server="python -m SimpleHTTPServer" + +# Git aliases +alias g='git' +alias gst="git status" +alias gss="gst --short" +alias gL="git log --graph --decorate" +alias gc='git commit --verbose' +alias gl="git pull" +alias gm='git merge' +alias gp='git push' + +# Graphicsmagick override +alias grm="/usr/local/bin/gm" + +# JS friendly tree +alias arbol="tree -I 'node_modules|bower_components|doc'" + +# Load Script Version Managers because they slow +alias enable-nvm='source $(brew --prefix nvm)/nvm.sh' +alias workon="echo 'DISABLED: run enable-virtualenvwrapper to enable'" +alias enable-virtualenvwrapper="unalias workon; source /usr/local/bin/virtualenvwrapper.sh" +alias enable-rvm="source $HOME/.rvm/scripts/rvm" diff --git a/zsh/modules/completion.zsh b/zsh/modules/completion.zsh new file mode 100644 index 0000000..f1ed1d6 --- /dev/null +++ b/zsh/modules/completion.zsh @@ -0,0 +1,127 @@ +# +# Sets completion options. +# +# Authors: +# Robby Russell +# Sorin Ionescu +# + +# Return if requirements are not found. +if [[ "$TERM" == 'dumb' ]]; then + return 1 +fi + +# Load and initialize the completion system ignoring insecure directories. +autoload -Uz compinit && compinit -i + +# +# Options +# + +setopt COMPLETE_IN_WORD # Complete from both ends of a word. +setopt ALWAYS_TO_END # Move cursor to the end of a completed word. +setopt PATH_DIRS # Perform path search even on command names with slashes. +setopt AUTO_MENU # Show completion menu on a successive tab press. +setopt AUTO_LIST # Automatically list choices on ambiguous completion. +setopt AUTO_PARAM_SLASH # If completed parameter is a directory, add a trailing slash. +unsetopt MENU_COMPLETE # Do not autoselect the first completion entry. +unsetopt FLOW_CONTROL # Disable start/stop characters in shell editor. + +# +# Styles +# + +# Use caching to make completion for commands such as dpkg and apt usable. +zstyle ':completion::complete:*' use-cache on +zstyle ':completion::complete:*' cache-path "${ZDOTDIR:-$HOME}/.zcompcache" + +zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' +unsetopt CASE_GLOB + +# Group matches and describe. +zstyle ':completion:*:*:*:*:*' menu select +zstyle ':completion:*:matches' group 'yes' +zstyle ':completion:*:options' description 'yes' +zstyle ':completion:*:options' auto-description '%d' +zstyle ':completion:*:corrections' format ' %F{green}-- %d (errors: %e) --%f' +zstyle ':completion:*:descriptions' format ' %F{yellow}-- %d --%f' +zstyle ':completion:*:messages' format ' %F{purple} -- %d --%f' +zstyle ':completion:*:warnings' format ' %F{red}-- no matches found --%f' +zstyle ':completion:*:default' list-prompt '%S%M matches%s' +zstyle ':completion:*' format ' %F{yellow}-- %d --%f' +zstyle ':completion:*' group-name '' +zstyle ':completion:*' verbose yes + +# Fuzzy match mistyped completions. +zstyle ':completion:*' completer _complete _match _approximate +zstyle ':completion:*:match:*' original only +zstyle ':completion:*:approximate:*' max-errors 1 numeric + +# Increase the number of errors based on the length of the typed word. +zstyle -e ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)' + +# Don't complete unavailable commands. +zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec))' + +# Array completion element sorting. +zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters + +# Directories +zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} +zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories +zstyle ':completion:*:*:cd:*:directory-stack' menu yes select +zstyle ':completion:*:-tilde-:*' group-order 'named-directories' 'path-directories' 'users' 'expand' +zstyle ':completion:*' squeeze-slashes true + +# History +zstyle ':completion:*:history-words' stop yes +zstyle ':completion:*:history-words' remove-all-dups yes +zstyle ':completion:*:history-words' list false +zstyle ':completion:*:history-words' menu yes + +# Environmental Variables +zstyle ':completion::*:(-command-|export):*' fake-parameters ${${${_comps[(I)-value-*]#*,}%%,*}:#-*-} + +# Populate hostname completion. +zstyle -e ':completion:*:hosts' hosts 'reply=( + ${=${=${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) 2>/dev/null)"}%%[#| ]*}//\]:[0-9]*/ }//,/ }//\[/ } + ${=${(f)"$(cat /etc/hosts(|)(N) <<(ypcat hosts 2>/dev/null))"}%%\#*} + ${=${${${${(@M)${(f)"$(cat ~/.ssh/config 2>/dev/null)"}:#Host *}#Host }:#*\**}:#*\?*}} +)' + +# Don't complete uninteresting users... +zstyle ':completion:*:*:*:users' ignored-patterns \ + adm amanda apache avahi beaglidx bin cacti canna clamav daemon \ + dbus distcache dovecot fax ftp games gdm gkrellmd gopher \ + hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \ + mailman mailnull mldonkey mysql nagios \ + named netdump news nfsnobody nobody nscd ntp nut nx openvpn \ + operator pcap postfix postgres privoxy pulse pvm quagga radvd \ + rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs '_*' + +# ... unless we really want to. +zstyle '*' single-ignored show + +# Ignore multiple entries. +zstyle ':completion:*:(rm|kill|diff):*' ignore-line other +zstyle ':completion:*:rm:*' file-patterns '*:all-files' + +# Kill +zstyle ':completion:*:*:*:*:processes' command 'ps -u $LOGNAME -o pid,user,command -w' +zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;36=0=01' +zstyle ':completion:*:*:kill:*' menu yes select +zstyle ':completion:*:*:kill:*' force-list always +zstyle ':completion:*:*:kill:*' insert-ids single + +# Man +zstyle ':completion:*:manuals' separate-sections true +zstyle ':completion:*:manuals.(^1*)' insert-sections true + +# SSH/SCP/RSYNC +zstyle ':completion:*:(scp|rsync):*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *' +zstyle ':completion:*:(scp|rsync):*' group-order users files all-files hosts-domain hosts-host hosts-ipaddr +zstyle ':completion:*:ssh:*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *' +zstyle ':completion:*:ssh:*' group-order users hosts-domain hosts-host users hosts-ipaddr +zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*(.|:)*' loopback ip6-loopback localhost ip6-localhost broadcasthost +zstyle ':completion:*:(ssh|scp|rsync):*:hosts-domain' ignored-patterns '<->.<->.<->.<->' '^[-[:alnum:]]##(.[-[:alnum:]]##)##' '*@*' +zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))' '127.0.0.<->' '255.255.255.255' '::1' 'fe80::*' diff --git a/zsh/modules/directory.zsh b/zsh/modules/directory.zsh new file mode 100644 index 0000000..98a86f4 --- /dev/null +++ b/zsh/modules/directory.zsh @@ -0,0 +1,23 @@ +# +# Sets directory options and defines directory aliases. +# +# Authors: +# James Cox +# Sorin Ionescu +# + +# +# Options +# + +setopt AUTO_CD # Auto changes to a directory without typing cd. +setopt AUTO_PUSHD # Push the old directory onto the stack on cd. +setopt PUSHD_IGNORE_DUPS # Do not store duplicates in the stack. +setopt PUSHD_SILENT # Do not print the directory stack after pushd or popd. +setopt PUSHD_TO_HOME # Push to home directory when no argument is given. +setopt CDABLE_VARS # Change directory to a path stored in a variable. +setopt AUTO_NAME_DIRS # Auto add variable-stored paths to ~ list. +setopt MULTIOS # Write to multiple descriptors. +setopt EXTENDED_GLOB # Use extended globbing syntax. +unsetopt CLOBBER # Do not overwrite existing files with > and >>. + # Use >! and >>! to bypass. diff --git a/zsh/modules/editor.zsh b/zsh/modules/editor.zsh new file mode 100644 index 0000000..8bc4dae --- /dev/null +++ b/zsh/modules/editor.zsh @@ -0,0 +1,195 @@ +# +# Sets key bindings. +# +# Authors: +# Sorin Ionescu +# + +# Return if requirements are not found. +if [[ "$TERM" == 'dumb' ]]; then + return 1 +fi + +# +# Options +# + +# Beep on error in line editor. +setopt BEEP + +# +# Variables +# + +# Treat these characters as part of a word. +WORDCHARS='*?_-.[]~&;!#$%^(){}<>' + +# Use human-friendly identifiers. +zmodload zsh/terminfo +typeset -gA key_info +key_info=( + 'Control' '\C-' + 'ControlLeft' '\e[1;5D \e[5D \e\e[D \eOd' + 'ControlRight' '\e[1;5C \e[5C \e\e[C \eOc' + 'Escape' '\e' + 'Meta' '\M-' + 'Backspace' "^?" + 'Delete' "^[[3~" + 'F1' "$terminfo[kf1]" + 'F2' "$terminfo[kf2]" + 'F3' "$terminfo[kf3]" + 'F4' "$terminfo[kf4]" + 'F5' "$terminfo[kf5]" + 'F6' "$terminfo[kf6]" + 'F7' "$terminfo[kf7]" + 'F8' "$terminfo[kf8]" + 'F9' "$terminfo[kf9]" + 'F10' "$terminfo[kf10]" + 'F11' "$terminfo[kf11]" + 'F12' "$terminfo[kf12]" + 'Insert' "$terminfo[kich1]" + 'Home' "$terminfo[khome]" + 'PageUp' "$terminfo[kpp]" + 'End' "$terminfo[kend]" + 'PageDown' "$terminfo[knp]" + 'Up' "$terminfo[kcuu1]" + 'Left' "$terminfo[kcub1]" + 'Down' "$terminfo[kcud1]" + 'Right' "$terminfo[kcuf1]" + 'BackTab' "$terminfo[kcbt]" +) + +# Set empty $key_info values to an invalid UTF-8 sequence to induce silent +# bindkey failure. +for key in "${(k)key_info[@]}"; do + if [[ -z "$key_info[$key]" ]]; then + key_info[$key]='�' + fi +done + +# +# External Editor +# + +# Allow command line editing in an external editor. +autoload -Uz edit-command-line +zle -N edit-command-line + +# Enables terminal application mode and updates editor information. +function zle-line-init { + # The terminal must be in application mode when ZLE is active for $terminfo + # values to be valid. + if (( $+terminfo[smkx] )); then + # Enable terminal application mode. + echoti smkx + fi +} +zle -N zle-line-init + +# Disables terminal application mode and updates editor information. +function zle-line-finish { + # The terminal must be in application mode when ZLE is active for $terminfo + # values to be valid. + if (( $+terminfo[rmkx] )); then + # Disable terminal application mode. + echoti rmkx + fi +} +zle -N zle-line-finish + +# Displays an indicator when completing. +function expand-or-complete-with-indicator { + local indicator + zstyle -s ':prezto:module:editor:info:completing' format 'indicator' + print -Pn "$indicator" + zle expand-or-complete + zle redisplay +} +zle -N expand-or-complete-with-indicator + +# Inserts 'sudo ' at the beginning of the line. +function prepend-sudo { + if [[ "$BUFFER" != su(do|)\ * ]]; then + BUFFER="sudo $BUFFER" + (( CURSOR += 5 )) + fi +} +zle -N prepend-sudo + +# Reset to default key bindings. +bindkey -d + +# +# Vi Key Bindings +# + +# Edit command in an external editor. +bindkey -M vicmd "v" edit-command-line + +# Undo/Redo +bindkey -M vicmd "u" undo +bindkey -M vicmd "$key_info[Control]R" redo + +if (( $+widgets[history-incremental-pattern-search-backward] )); then + bindkey -M vicmd "?" history-incremental-pattern-search-backward + bindkey -M vicmd "/" history-incremental-pattern-search-forward +else + bindkey -M vicmd "?" history-incremental-search-backward + bindkey -M vicmd "/" history-incremental-search-forward +fi + +# +# Emacs and Vi Key Bindings +# + +for keymap in 'emacs' 'viins'; do + bindkey -M "$keymap" "$key_info[Home]" beginning-of-line + bindkey -M "$keymap" "$key_info[End]" end-of-line + + bindkey -M "$keymap" "$key_info[Insert]" overwrite-mode + bindkey -M "$keymap" "$key_info[Delete]" delete-char + bindkey -M "$keymap" "$key_info[Backspace]" backward-delete-char + + bindkey -M "$keymap" "$key_info[Left]" backward-char + bindkey -M "$keymap" "$key_info[Right]" forward-char + + # Expand history on space. + bindkey -M "$keymap" ' ' magic-space + + # Clear screen. + bindkey -M "$keymap" "$key_info[Control]L" clear-screen + + # Expand command name to full path. + for key in "$key_info[Escape]"{E,e} + bindkey -M "$keymap" "$key" expand-cmd-path + + # Duplicate the previous word. + for key in "$key_info[Escape]"{M,m} + bindkey -M "$keymap" "$key" copy-prev-shell-word + + # Use a more flexible push-line. + for key in "$key_info[Control]Q" "$key_info[Escape]"{q,Q} + bindkey -M "$keymap" "$key" push-line-or-edit + + # Bind Shift + Tab to go to the previous menu item. + bindkey -M "$keymap" "$key_info[BackTab]" reverse-menu-complete + + # Complete in the middle of word. + bindkey -M "$keymap" "$key_info[Control]I" expand-or-complete + + # Display an indicator when completing. + bindkey -M "$keymap" "$key_info[Control]I" \ + expand-or-complete-with-indicator + + # Insert 'sudo ' at the beginning of the line. + bindkey -M "$keymap" "$key_info[Control]X$key_info[Control]S" prepend-sudo +done + +# +# Layout +# + +# Set the key layout. +bindkey -v + +unset key{,map,bindings} diff --git a/zsh/modules/environment.zsh b/zsh/modules/environment.zsh index 4e95dac..9b23ac7 100644 --- a/zsh/modules/environment.zsh +++ b/zsh/modules/environment.zsh @@ -11,6 +11,7 @@ setopt COMBINING_CHARS # Combine zero-length punctuation characters (accents) # with the base character. setopt RC_QUOTES # Allow 'Henry''s Garage' instead of 'Henry'\''s Garage'. unsetopt MAIL_WARNING # Don't print a warning message if a mail file has been accessed. +setopt CORRECT # # Jobs diff --git a/zsh/modules/history.zsh b/zsh/modules/history.zsh new file mode 100644 index 0000000..0191b00 --- /dev/null +++ b/zsh/modules/history.zsh @@ -0,0 +1,32 @@ +# +# Sets history options and defines history aliases. +# +# Authors: +# Robby Russell +# Sorin Ionescu +# + +# +# Variables +# + +HISTFILE="${ZDOTDIR:-$HOME}/.zhistory" # The path to the history file. +HISTSIZE=10000 # The maximum number of events to save in the internal history. +SAVEHIST=10000 # The maximum number of events to save in the history file. + +# +# Options +# + +setopt BANG_HIST # Treat the '!' character specially during expansion. +setopt EXTENDED_HISTORY # Write the history file in the ':start:elapsed;command' format. +setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits. +setopt SHARE_HISTORY # Share history between all sessions. +setopt HIST_EXPIRE_DUPS_FIRST # Expire a duplicate event first when trimming history. +setopt HIST_IGNORE_DUPS # Do not record an event that was just recorded again. +setopt HIST_IGNORE_ALL_DUPS # Delete an old recorded event if a new event is a duplicate. +setopt HIST_FIND_NO_DUPS # Do not display a previously found event. +setopt HIST_IGNORE_SPACE # Do not record an event starting with a space. +setopt HIST_SAVE_NO_DUPS # Do not write a duplicate event to the history file. +setopt HIST_VERIFY # Do not execute immediately upon history expansion. +setopt HIST_BEEP # Beep when accessing non-existent history. diff --git a/prompt_ben_setup b/zsh/modules/prompt.zsh similarity index 55% rename from prompt_ben_setup rename to zsh/modules/prompt.zsh index d164fd9..945d9eb 100644 --- a/prompt_ben_setup +++ b/zsh/modules/prompt.zsh @@ -1,7 +1,21 @@ -function prompt_ben_precmd { +autoload -Uz promptinit && promptinit + +if [[ "$TERM" == (dumb|linux|*bsd*) ]] || (( $#prompt_argv < 1 )); then + prompt 'off' +fi + +# +# Precmd +# + +function prompt_precmd { git-info } +# +# Functions +# + function virtualenv_info { if [[ -z "$VIRTUAL_ENV" ]]; then venv="default" @@ -33,16 +47,30 @@ function box_name { [ -f ~/.box-name ] && cat ~/.box-name || hostname -s } +# +# ZLE widgets +# + function zle-line-init zle-keymap-select { - local return_status="%{%F{red}%}%(?..✘)%{$reset_color%}" - RPS1="${${KEYMAP/vicmd/-- NORMAL --}/(main|viins)/-- INSERT --}${return_status}%{$reset_color%}" + local return_status="%{%F{red}%}%(?..🆇)%{$reset_color%}" + if [ $KEYMAP = 'vicmd' ]; then + local edit_status="%{%F{cyan}%}🅽" + else + local edit_status="%{%F{green}%}🅸" + fi + + RPS1="${edit_status} ${return_status}%{$reset_color%}" RPS2=$RPS1 zle reset-prompt } zle -N zle-line-init zle -N zle-keymap-select -function prompt_ben_setup { +# +# Setup Prompt +# + +function prompt_setup { setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS prompt_opts=(cr percent subst) @@ -51,16 +79,16 @@ function prompt_ben_setup { autoload -Uz add-zsh-hook # Add hook for calling git-info before each command. - add-zsh-hook precmd prompt_ben_precmd + add-zsh-hook precmd prompt_precmd # Set git-info parameters. - zstyle ':prezto:module:git:info' verbose 'yes' - zstyle ':prezto:module:git:info:branch' format '@%F{cyan}%b%f' - zstyle ':prezto:module:git:info:clean' format '' - zstyle ':prezto:module:git:info:added' format '%{%F{green}%}!' - zstyle ':prezto:module:git:info:modified' format '%{%F{green}%}?' - zstyle ':prezto:module:git:info:untracked' format '%{%F{magenta}%}?' - zstyle ':prezto:module:git:info:keys' format \ + zstyle ':git:info' verbose 'no' + zstyle ':git:info:branch' format '@%F{cyan}%b%f' + zstyle ':git:info:clean' format '' + zstyle ':git:info:added' format '%{%F{green}%}!' + zstyle ':git:info:modified' format '%{%F{green}%}?' + zstyle ':git:info:untracked' format '%{%F{magenta}%}?' + zstyle ':git:info:keys' format \ 'prompt' '%b%a%m%u' # Define prompts. @@ -70,13 +98,5 @@ function prompt_ben_setup { %(?,,%{${%B%F{white}%}[%?]%{%f%b%} )$ ' } -prompt_ben_setup "$@" - -#setopt PROMPT_SUBST - -ZSH_THEME_GIT_PROMPT_PREFIX="@%{%F{cyan}%}" -ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" -ZSH_THEME_GIT_PROMPT_DIRTY="%{%F{green}%}!" -ZSH_THEME_GIT_PROMPT_UNTRACKED="%{%F{green}%}?" -ZSH_THEME_GIT_PROMPT_CLEAN="" - +prompt_setup "$@" +setopt PROMPT_SUBST