Refactor zsh config
This commit is contained in:
parent
82f7a1fd54
commit
05750535b9
|
@ -2,27 +2,26 @@
|
|||
# zshrc
|
||||
# By Henrik Lissner <henrik@lissner.net>
|
||||
|
||||
repo "tarjoilija/zgen" "$HOME/.zgen"
|
||||
if is-interactive; then
|
||||
repo "tarjoilija/zgen" "$HOME/.zgen"
|
||||
source "$HOME/.zgen/zgen.zsh"
|
||||
if ! zgen saved; then
|
||||
info "Creating zgen save"
|
||||
|
||||
source "$HOME/.zgen/zgen.zsh"
|
||||
if ! zgen saved; then
|
||||
info "Creating zgen save"
|
||||
cache-clear
|
||||
|
||||
cache-clear
|
||||
zgen load hlissner/zsh-autopair "autopair.zsh"
|
||||
zgen load zsh-users/zsh-history-substring-search
|
||||
zgen load zdharma/history-search-multi-word
|
||||
zgen load zsh-users/zsh-completions src
|
||||
|
||||
zgen load hlissner/zsh-autopair "autopair.zsh"
|
||||
zgen load zsh-users/zsh-history-substring-search
|
||||
zgen load zdharma/history-search-multi-word
|
||||
zgen load zsh-users/zsh-completions src
|
||||
if [[ -z $SSH_CONNECTION ]]; then
|
||||
zgen load zdharma/fast-syntax-highlighting
|
||||
fi
|
||||
|
||||
if [[ -z $SSH_CONNECTION ]]; then
|
||||
zgen load zdharma/fast-syntax-highlighting
|
||||
zgen save
|
||||
fi
|
||||
|
||||
zgen save
|
||||
fi
|
||||
|
||||
if is-interactive; then
|
||||
load shell/+zsh/completion.zsh
|
||||
load shell/+zsh/keybinds.zsh
|
||||
load shell/+zsh/prompt.zsh
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
## Plugin config
|
||||
AUTOPAIR_SPC_WIDGET=magic-space
|
||||
|
||||
## General
|
||||
# Treat these characters as part of a word.
|
||||
WORDCHARS='_-*?[]~&.;!#$%^(){}<>'
|
||||
|
@ -20,9 +23,9 @@ unsetopt HUP # Don't kill jobs on shell exit.
|
|||
unsetopt CHECK_JOBS # Don't report on jobs when shell exit.
|
||||
|
||||
## History
|
||||
HISTFILE="$CACHE_DIR/zhistory"
|
||||
HISTSIZE=10000 # Max events to store in internal history.
|
||||
SAVEHIST=10000 # Max events to store in history file.
|
||||
HISTFILE="${CACHE_DIR}/zhistory"
|
||||
HISTSIZE=1000 # Max events to store in internal history.
|
||||
SAVEHIST=1000 # Max events to store in history file.
|
||||
|
||||
setopt BANG_HIST # Don't treat '!' specially during expansion.
|
||||
setopt EXTENDED_HISTORY # Write the history file in the ':start:elapsed;command' format.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Ran into an issue where the surround module wasn't working if KEYTIMEOUT is <= 10.
|
||||
# Specifically, (delete|change)-surround immediately abort into insert mode if
|
||||
# KEYTIMEOUT <= 8, and if <= 10, then add-surround would do the same. At 11, all these
|
||||
# issues vanish. Very strange!
|
||||
# The surround module wasn't working if KEYTIMEOUT was <= 10. Specifically,
|
||||
# (delete|change)-surround immediately abort into insert mode if KEYTIMEOUT <=
|
||||
# 8. If <= 10, then add-surround does the same. At 11, all these issues vanish.
|
||||
# Very strange!
|
||||
export KEYTIMEOUT=15
|
||||
|
||||
autoload -U is-at-least
|
||||
|
@ -53,7 +53,6 @@ bindkey -M viins '^a' beginning-of-line
|
|||
bindkey -M viins '^e' end-of-line
|
||||
bindkey -M viins '^d' push-line-or-edit
|
||||
|
||||
bindkey -M viins ' ' magic-space
|
||||
bindkey -M vicmd '^k' kill-line
|
||||
bindkey -M vicmd 'H' run-help
|
||||
|
||||
|
@ -66,13 +65,13 @@ bindkey '^[[B' history-substring-search-down
|
|||
|
||||
# C-z to background *and* foreground processes
|
||||
fancy-ctrl-z () {
|
||||
if [[ $#BUFFER -eq 0 ]]; then
|
||||
BUFFER="fg"
|
||||
zle accept-line
|
||||
else
|
||||
zle push-input
|
||||
zle clear-screen
|
||||
fi
|
||||
if [[ $#BUFFER -eq 0 ]]; then
|
||||
BUFFER="fg"
|
||||
zle accept-line
|
||||
else
|
||||
zle push-input
|
||||
zle clear-screen
|
||||
fi
|
||||
}
|
||||
zle -N fancy-ctrl-z
|
||||
bindkey '^Z' fancy-ctrl-z
|
||||
|
@ -106,8 +105,8 @@ fi
|
|||
|
||||
# Vim's C-x C-l in zsh
|
||||
history-beginning-search-backward-then-append() {
|
||||
zle history-beginning-search-backward
|
||||
zle vi-add-eol
|
||||
zle history-beginning-search-backward
|
||||
zle vi-add-eol
|
||||
}
|
||||
zle -N history-beginning-search-backward-then-append
|
||||
bindkey -M viins '^x^l' history-beginning-search-backward-then-append
|
||||
|
@ -124,18 +123,3 @@ bindkey -M viins '^X,' _history-complete-newer \
|
|||
'^X/' _history-complete-older \
|
||||
'^X`' _bash_complete-word
|
||||
|
||||
# In-place search insertion
|
||||
autoload -Uz narrow-to-region
|
||||
function _history-incremental-preserving-pattern-search-backward
|
||||
{
|
||||
local state
|
||||
MARK=CURSOR # magick, else multiple ^R don't work
|
||||
narrow-to-region -p "$LBUFFER${BUFFER:+>>}" -P "${BUFFER:+<<}$RBUFFER" -S state
|
||||
zle end-of-history
|
||||
zle history-incremental-pattern-search-backward
|
||||
narrow-to-region -R state
|
||||
}
|
||||
zle -N _history-incremental-preserving-pattern-search-backward
|
||||
bindkey "^R" _history-incremental-preserving-pattern-search-backward
|
||||
bindkey -M isearch "^R" history-incremental-pattern-search-backward
|
||||
bindkey "^S" history-incremental-pattern-search-forward
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env zsh
|
||||
# Based off Pure <https://github.com/sindresorhus/pure>
|
||||
# Loosely based off Pure <https://github.com/sindresorhus/pure>
|
||||
|
||||
_strlen() { echo ${#${(S%%)1//$~%([BSUbfksu]|([FB]|){*})/}}; }
|
||||
|
||||
|
@ -7,9 +7,6 @@ _strlen() { echo ${#${(S%%)1//$~%([BSUbfksu]|([FB]|){*})/}}; }
|
|||
prompt_git_dirty() {
|
||||
is-callable git || return
|
||||
|
||||
# disable auth prompting on git 2.3+
|
||||
GIT_TERMINAL_PROMPT=0
|
||||
|
||||
# check if we're in a git repo
|
||||
[[ "$(command git rev-parse --is-inside-work-tree 2>/dev/null)" == "true" ]] || return
|
||||
# check if it's dirty
|
||||
|
@ -27,12 +24,16 @@ prompt_git_dirty() {
|
|||
prompt_hook_precmd() {
|
||||
vcs_info # get git info
|
||||
# Newline before prompt, except on init
|
||||
[[ -n "$_DONE" ]] && print ""; _DONE=1
|
||||
[[ $PROMPT_DONE ]] && print ""; PROMPT_DONE=1
|
||||
}
|
||||
|
||||
## Initialization ######################
|
||||
prompt_init() {
|
||||
ZLE_RPROMPT_INDENT=0 # prevent the extra space in the rprompt
|
||||
# prevent the extra space in the rprompt
|
||||
[[ $EMACS ]] || ZLE_RPROMPT_INDENT=0
|
||||
# prevent percentage showing up
|
||||
# if output doesn't end with a newline
|
||||
export PROMPT_EOL_MARK=
|
||||
|
||||
# prompt_opts=(cr subst percent)
|
||||
setopt PROMPTSUBST
|
||||
|
@ -55,11 +56,10 @@ prompt_init() {
|
|||
zstyle ':vcs_info:*' enable git
|
||||
zstyle ':vcs_info:*' use-simple true
|
||||
zstyle ':vcs_info:*' max-exports 2
|
||||
zstyle ':vcs_info:git*' formats ':%b'
|
||||
zstyle ':vcs_info:git*' actionformats ':%b (%a)'
|
||||
zstyle ':vcs_info:git*' formats '%b'
|
||||
zstyle ':vcs_info:git*' actionformats '%b (%a)'
|
||||
|
||||
# show username@host if logged in through SSH
|
||||
prompt_username=
|
||||
[[ $SSH_CONNECTION ]] && prompt_username='%F{magenta}%n%F{244}@%m '
|
||||
|
||||
RPROMPT='%F{cyan}%~ %F{magenta}${vcs_info_msg_0_}$(prompt_git_dirty)%f'
|
||||
|
|
Loading…
Reference in a new issue