aboutsummaryrefslogtreecommitdiff
path: root/zsh/modules
diff options
context:
space:
mode:
authorBen Beltran <ben@nsovocal.com>2020-02-16 14:40:26 +0100
committerBen Beltran <ben@nsovocal.com>2020-02-16 14:40:26 +0100
commitfa25023586cb94a1abf4fd3ff95ebe7c3c8ead09 (patch)
tree87404d2a291facd6d7fd567fe251bc1c12f688c8 /zsh/modules
parentf6272d88eae76c8553f237f3f318c4a97997f262 (diff)
Remove prezto
Diffstat (limited to 'zsh/modules')
-rw-r--r--zsh/modules/aliases.zsh39
-rw-r--r--zsh/modules/completion.zsh127
-rw-r--r--zsh/modules/directory.zsh23
-rw-r--r--zsh/modules/editor.zsh195
-rw-r--r--zsh/modules/environment.zsh1
-rw-r--r--zsh/modules/history.zsh32
-rw-r--r--zsh/modules/prompt.zsh102
-rw-r--r--zsh/modules/terminal.zsh0
8 files changed, 519 insertions, 0 deletions
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 <robby@planetargon.com>
+# Sorin Ionescu <sorin.ionescu@gmail.com>
+#
+
+# 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 <james@imaj.es>
+# Sorin Ionescu <sorin.ionescu@gmail.com>
+#
+
+#
+# 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 <sorin.ionescu@gmail.com>
+#
+
+# 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 <robby@planetargon.com>
+# Sorin Ionescu <sorin.ionescu@gmail.com>
+#
+
+#
+# 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/zsh/modules/prompt.zsh b/zsh/modules/prompt.zsh
new file mode 100644
index 0000000..945d9eb
--- /dev/null
+++ b/zsh/modules/prompt.zsh
@@ -0,0 +1,102 @@
+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"
+ else
+ venv="${VIRTUAL_ENV##*/}"
+ fi
+ echo "🐍${venv}"
+}
+
+function rvm_info {
+ if [[ -z "$RUBY_VERSION" ]]; then
+ rvminfo="default"
+ else
+ rvminfo=`rvm-prompt`
+ fi
+ echo "💎${rvminfo}"
+}
+
+function nvm_info {
+ if [[ -z "$NVM_BIN" ]]; then
+ nvminfo="default"
+ else
+ nvminfo=`nvm current`
+ fi
+ echo "💛${nvminfo}"
+}
+
+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%}"
+ 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
+
+#
+# Setup Prompt
+#
+
+function prompt_setup {
+ setopt LOCAL_OPTIONS
+ unsetopt XTRACE KSH_ARRAYS
+ prompt_opts=(cr percent subst)
+
+ # Load required functions.
+ autoload -Uz add-zsh-hook
+
+ # Add hook for calling git-info before each command.
+ add-zsh-hook precmd prompt_precmd
+
+ # Set git-info parameters.
+ 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.
+ PROMPT='
+%{%F{black}%}$(nvm_info) $(rvm_info) $(virtualenv_info)
+%{%F{magenta}%}%n%{%f%}@%{%F{yellow}%}$(box_name)%{%f%} %{%B%F{green}%}${PWD/#$HOME/~}%{%f%b%}${git_info[prompt]} %{%f%}
+%(?,,%{${%B%F{white}%}[%?]%{%f%b%} )$ '
+}
+
+prompt_setup "$@"
+setopt PROMPT_SUBST
diff --git a/zsh/modules/terminal.zsh b/zsh/modules/terminal.zsh
deleted file mode 100644
index e69de29..0000000
--- a/zsh/modules/terminal.zsh
+++ /dev/null