Skip to content

Instantly share code, notes, and snippets.

@pprince
Created May 16, 2016 03:48
Show Gist options
  • Save pprince/bf19c42191f44dfd705259ba9d09d466 to your computer and use it in GitHub Desktop.
Save pprince/bf19c42191f44dfd705259ba9d09d466 to your computer and use it in GitHub Desktop.
teatime's zshrc
# ~/.zshrc
# ========
# This file is sourced only for interactive shells. It
# should contain commands to set up aliases, functions,
# options, key bindings, etc.
#
# Global Order: zshenv, zprofile, zshrc, zlogin
# ~83% of the following was shamelessly stolen from Debian 8's /etc/zsh/zshrc,
# and another 14% was lifted from https://github.com/lackac/prezto
### <Keybindings> ###
# Enable vi-like editing
bindkey -v
# Use the terminfo database to look-up what the current terminal sends
# for each special keys we may want to bind, and store them for later.
# ($key is here declared as an associative-array aka dictionary or hash-map.)
# TODO: define up to F24 (or, if possible, F35.)
typeset -A key
key=(
Control '\C-'
Escape '\e'
Meta '\M-'
BackSpace "${terminfo[kbs]}"
Up "${terminfo[kcuu1]}"
Down "${terminfo[kcud1]}"
Left "${terminfo[kcub1]}"
Right "${terminfo[kcuf1]}"
Home "${terminfo[khome]}"
End "${terminfo[kend]}"
Insert "${terminfo[kich1]}"
Delete "${terminfo[kdch1]}"
PageUp "${terminfo[kpp]}"
PageDown "${terminfo[knp]}"
BackTab "${terminfo[kcbt]}"
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]}"
)
# handy function; it lets you set bindings for multiple modes at once, i.e.:
# emacs (zsh default), viins (vi insert-mode), and vicmd (vi command-mode).
function bind2maps () {
local i sequence widget
local -a maps
while [[ "$1" != "--" ]]; do
maps+=( "$1" )
shift
done
shift
sequence="${key[$1]}"
widget="$2"
[[ -z "$sequence" ]] && return 1
for i in "${maps[@]}"; do
bindkey -M "$i" "$sequence" "$widget"
done
}
# Now we use it, to declare most of the same bindings that Debian had in
# their /etc/zsh/zshrc:
bind2maps emacs -- BackSpace backward-delete-char
bind2maps viins -- BackSpace vi-backward-delete-char
bind2maps vicmd -- BackSpace vi-backward-char
bind2maps emacs -- Home beginning-of-line
bind2maps viins vicmd -- Home vi-beginning-of-line
bind2maps emacs -- End end-of-line
bind2maps viins vicmd -- End vi-end-of-line
bind2maps emacs viins -- Insert overwrite-mode
bind2maps vicmd -- Insert vi-insert
bind2maps emacs -- Delete delete-char
bind2maps viins vicmd -- Delete vi-delete-char
bind2maps emacs -- Left backward-char
bind2maps viins vicmd -- Left vi-backward-char
bind2maps emacs -- Right forward-char
bind2maps viins vicmd -- Right vi-forward-char
# But also our new ones for searching the history. (However, we'll fall-back
# to vanilla behavior, if "{up,down}-line-or-beginning" search fails somehow.)
if autoload -Uz up-line-or-beginning-search && zle -N $_ && \
autoload -Uz down-line-or-beginning-search && zle -N $_
then
bind2maps emacs viins vicmd -- Up up-line-or-beginning-search
bind2maps emacs viins vicmd -- Down down-line-or-beginning-search
else
bind2maps emacs viins vicmd -- Up up-line-or-history
bind2maps emacs viins vicmd -- Down down-line-or-history
fi
# see: http://imgur.com/eeydewp
unfunction bind2maps
### </keybindings> ###
# "Editors are expected to switch to "application" mode using the "smkx"
# terminfo capability when they start, and to go back to the normal "cursor"
# mode ("rmkx") when they exit." -- otherwise, terminfo isn't valid/reliable.
if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
function zle-line-init () {
emulate -L zsh
printf '%s' ${terminfo[smkx]}
}
function zle-line-finish () {
emulate -L zsh
printf '%s' ${terminfo[rmkx]}
}
zle -N zle-line-init
zle -N zle-line-finish
fi
# A useful command for searching Zsh's $terminfo[]
printti() for 1 { print -r -- ${(k)terminfo[(Re)${(g:c:)1}]:-no entry} }
# this seems kindof useful: if we have a $PAGER set, tell Zsh to use it;
# otherwise fall-back to `more` (which is Zsh's default here anyway.)
READNULLCMD=${PAGER:-more}
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'
zstyle ':completion:*' completer _complete _ignored _approximate _prefix
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' menu select=0
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle :compinstall filename '/home/pprince/.zshrc'
autoload -Uz compinit
compinit
HISTFILE=~/.histfile
HISTSIZE=10000
SAVEHIST=10000
setopt inc_append_history share_history
setopt beep nomatch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment