diff options
Diffstat (limited to '.config/zsh')
-rw-r--r-- | .config/zsh/.zlogin | 22 | ||||
-rw-r--r-- | .config/zsh/.zlogout | 7 | ||||
-rw-r--r-- | .config/zsh/.zprofile | 51 | ||||
-rw-r--r-- | .config/zsh/.zshenv | 5 | ||||
-rw-r--r-- | .config/zsh/.zshrc | 443 |
5 files changed, 528 insertions, 0 deletions
diff --git a/.config/zsh/.zlogin b/.config/zsh/.zlogin new file mode 100644 index 0000000..32f28cf --- /dev/null +++ b/.config/zsh/.zlogin @@ -0,0 +1,22 @@ +# +# Executes commands at login post-zshrc. +# +# Authors: +# Sorin Ionescu <sorin.ionescu@gmail.com> +# + +# 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 + fortune -a + print +fi + diff --git a/.config/zsh/.zlogout b/.config/zsh/.zlogout new file mode 100644 index 0000000..307314b --- /dev/null +++ b/.config/zsh/.zlogout @@ -0,0 +1,7 @@ +# +# Commands executed by zsh on logout. +# + +if [ $(id -u) -eq 0 ]; then + clear +fi diff --git a/.config/zsh/.zprofile b/.config/zsh/.zprofile new file mode 100644 index 0000000..4ec678f --- /dev/null +++ b/.config/zsh/.zprofile @@ -0,0 +1,51 @@ +# +# Executes commands at login pre-zshrc. + +# +# 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 +) + + +# +# Temporary Files +# + +if [[ ! -d "$TMPDIR" ]]; then + if [[ $USER == "root" ]]; then + export TMPDIR="/tmp/$USER" + else + export TMPDIR="$XDG_RUNTIME_DIR" + fi + mkdir -p -m 700 "$TMPDIR" +fi + +TMPPREFIX="${TMPDIR%/}/zsh" +if [[ ! -d "$TMPPREFIX" ]]; then + mkdir -p "$TMPPREFIX" +fi + + +[[ "$TTY" == /dev/tty* ]] || return 0 + +if command -v systemctl > /dev/null; then + export $(systemctl --user show-environment) + if [[ -z $DISPLAY && "$TTY" == "/dev/tty1" ]]; then + systemd-cat -t sway sway + systemctl --user stop sway-session.target + systemctl --user unset-environment DISPLAY WAYLAND_DISPLAY SWAYSOCK + fi +fi diff --git a/.config/zsh/.zshenv b/.config/zsh/.zshenv new file mode 100644 index 0000000..cdd5691 --- /dev/null +++ b/.config/zsh/.zshenv @@ -0,0 +1,5 @@ +# 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/.config/zsh/.zshrc b/.config/zsh/.zshrc new file mode 100644 index 0000000..86a6262 --- /dev/null +++ b/.config/zsh/.zshrc @@ -0,0 +1,443 @@ + +# functions +for config_file ($HOME/.config/zsh/functions/*.zsh) source $config_file + +# Environment +# + +# Smart URLs +autoload -Uz url-quote-magic +zle -N self-insert url-quote-magic + +# enable vi mode +setopt -o vi +bindkey -v +bindkey '^r' history-incremental-search-backward +bindkey '^a' beginning-of-line +bindkey '^e' end-of-line + +# General +setopt BRACE_CCL # Allow brace character class list expansion. +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. + +# Jobs +setopt LONG_LIST_JOBS # List jobs in the long format by default. +setopt AUTO_RESUME # Attempt to resume existing job before creating a new process. +setopt NOTIFY # Report status of background jobs immediately. +unsetopt BG_NICE # Don't run all background jobs at a lower priority. +unsetopt HUP # Don't kill jobs on shell exit. +unsetopt CHECK_JOBS # Don't report on jobs when shell exit. + +## Termcap +#if zstyle -t ':prezto:environment:termcap' color; then +# export LESS_TERMCAP_mb=$'\E[01;31m' # Begins blinking. +# export LESS_TERMCAP_md=$'\E[01;31m' # Begins bold. +# export LESS_TERMCAP_me=$'\E[0m' # Ends mode. +# export LESS_TERMCAP_se=$'\E[0m' # Ends standout-mode. +# export LESS_TERMCAP_so=$'\E[00;47;30m' # Begins standout-mode. +# export LESS_TERMCAP_ue=$'\E[0m' # Ends underline. +# export LESS_TERMCAP_us=$'\E[01;32m' # Begins underline. +#fi + +# Terminal +# + +# Do not override precmd/preexec; append to the hook array. +autoload -Uz add-zsh-hook + +# Sets the tab and window titles before the prompt is displayed. +#add-zsh-hook precmd _terminal-set-titles-with-path + +# Sets the tab and window titles before command execution. +#add-zsh-hook preexec _terminal-set-titles-with-command + +# no terminal input freezing (ctrl + s) and unfreezing (ctrl + q) +stty -ixon + +# Editor +# + +# Beep on error in line editor. +setopt BEEP + +# 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 + +# Allow command line editing in an external editor. +autoload -Uz edit-command-line +zle -N edit-command-line + +# 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 + + # Insert 'sudo ' at the beginning of the line. + bindkey -M "$keymap" "$key_info[Control]X$key_info[Control]S" prepend-sudo +done + +# Set the key layout to vi mode +bindkey -v +unset key{,map,bindings} + +# History +# +# The path to the history file +HISTFILE="$HOME/.zhistory" +# The maximum number of events to save in the internal history. +HISTSIZE=10000 +# The maximum number of events to save in the history file. +SAVEHIST=10000 + +# Treat the '!' character specially during expansion. +setopt BANG_HIST +# Write the history file in the ':start:elapsed;command' format. +setopt EXTENDED_HISTORY +# Write to the history file immediately, not when the shell exits. +setopt INC_APPEND_HISTORY +# Share history between all sessions. +setopt SHARE_HISTORY +# Expire a duplicate event first when trimming history. +setopt HIST_EXPIRE_DUPS_FIRST +# Do not record an event that was just recorded again. +setopt HIST_IGNORE_DUPS +# Delete an old recorded event if a new event is a duplicate. +setopt HIST_IGNORE_ALL_DUPS +# Do not display a previously found event. +setopt HIST_FIND_NO_DUPS +# Do not record an event starting with a space. +setopt HIST_IGNORE_SPACE +# Do not write a duplicate event to the history file. +setopt HIST_SAVE_NO_DUPS +# Do not execute immediately upon history expansion. +setopt HIST_VERIFY +# Beep when accessing non-existent history. +setopt HIST_BEEP + + +# Directory +# + +# Auto changes to a directory without typing cd. +setopt AUTO_CD +# Push the old directory onto the stack on cd. +setopt AUTO_PUSHD +# Do not store duplicates in the stack. +setopt PUSHD_IGNORE_DUPS +# Do not print the directory stack after pushd or popd. +setopt PUSHD_SILENT +# Push to home directory when no argument is given. +setopt PUSHD_TO_HOME +# Change directory to a path stored in a variable. +setopt CDABLE_VARS +# Auto add variable-stored paths to ~ list. +setopt AUTO_NAME_DIRS +# Write to multiple descriptors. +setopt MULTIOS +# Use extended globbing syntax. +setopt EXTENDED_GLOB +# Do not overwrite existing files with > and >>. +# Use >! and >>! to bypass. +unsetopt CLOBBER + + + +# Externals +# +# TODO: Add conditional to check for availability + +# Completion +# +zmodload zsh/complist + +# include completions path in directory +fpath=(/usr/share/zsh/site-functions/ $fpath) + +# Load and initialize the completion system ignoring insecure directories. +autoload -Uz compinit && compinit -i + +# +# Options +# + +# Complete from both ends of a word. +setopt COMPLETE_IN_WORD +# Move cursor to the end of a completed word. +setopt ALWAYS_TO_END +# Perform path search even on command names with slashes. +setopt PATH_DIRS +# Show completion menu on a successive tab press. +setopt AUTO_MENU +# Automatically list choices on ambiguous completion. +setopt AUTO_LIST +# If completed parameter is a directory, add a trailing slash. +setopt AUTO_PARAM_SLASH +# Do not autoselect the first completion entry. +unsetopt MENU_COMPLETE +# Disable start/stop characters in shell editor. +unsetopt FLOW_CONTROL + +# +# 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 "$HOME/.zcompcache" + +# Case-insensitive (all), partial-word, and then substring completion. +if zstyle -t ':prezto:module:completion:*' case-sensitive; then + zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' + setopt CASE_GLOB +else + zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' + unsetopt CASE_GLOB +fi + +# 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 + +# Media Players +zstyle ':completion:*:*:mpg123:*' file-patterns '*.(mp3|MP3):mp3\ files *(-/):directories' +zstyle ':completion:*:*:mpg321:*' file-patterns '*.(mp3|MP3):mp3\ files *(-/):directories' +zstyle ':completion:*:*:ogg123:*' file-patterns '*.(ogg|OGG|flac):ogg\ files *(-/):directories' +zstyle ':completion:*:*:mocp:*' file-patterns '*.(wav|WAV|mp3|MP3|ogg|OGG|flac):ogg\ files *(-/):directories' + +# Mutt +if [[ -s "$HOME/.mutt/aliases" ]]; then + zstyle ':completion:*:*:mutt:*' menu yes select + zstyle ':completion:*:mutt:*' users ${${${(f)"$(<"$HOME/.mutt/aliases")"}#alias[[:space:]]}%%[[:space:]]*} +fi + +# 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::*' + +# autosuggestions +autosuggestions=( "/usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh" + "/usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh" + "/usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh" ) +for p in ${autosuggestions}; do + if [ -f "$p" ]; then + source "$p" + fi +done +ZSH_AUTOSUGGEST_STRATEGY=('history') + +# syntax-highlighting +syntax_highlighting=( "/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" + "/usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" + "/usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" ) +for p in ${syntax_highlighting}; do + if [ -f "$p" ]; then + source "$p" + fi +done + +# history-substring-search +history_substring=( "/usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh" + "/usr/share/zsh-history-substring-search/zsh-history-substring-search.zsh" + "/usr/local/share/zsh-history-substring-search/zsh-history-substring-search.zsh" ) +for p in ${history_substring}; do + if [ -f "$p" ]; then + source "$p" + # Vi + bindkey -M vicmd "k" history-substring-search-up + bindkey -M vicmd "j" history-substring-search-down + + # Emacs and Vi + for keymap in 'viins'; do + bindkey -M "$keymap" "$key_info[Up]" history-substring-search-up + bindkey -M "$keymap" "$key_info[Down]" history-substring-search-down + done + fi +done + +# includes +for config_file ($HOME/.config/zsh/includes/*.zsh) source $config_file + +# use starship for prompt if it exists +(( ${+commands[starship]} )) && eval "$(starship init zsh)" |