zsh: Divide zshrc into zshrc.d

Move every file from plugins into zshrc.d as well as all bigger blobs in
the zshrc into their own files there.
Some stuff is still in there that I am not all too sure where it
belongs. TODO: Move.

Because all external plugins are now sourced over a symlink I had to
create a fork of fzf-tab for now that supports that.
See: https://github.com/Aloxaf/fzf-tab/pull/153
This commit is contained in:
2020-11-10 02:58:22 +01:00
parent 301b109f0d
commit bf46c5f687
22 changed files with 108 additions and 351 deletions

View File

@@ -0,0 +1,31 @@
setopt AUTO_CONTINUE # Stopped jobs with 'disown' are automatically sent a CONT signal to make them running.
setopt AUTO_LIST # Automatically list choices on an ambiguous completion.
setopt AUTO_PARAM_SLASH # Add a trailing slash when completing directories
setopt AUTO_PUSHD # Make cd push the old directory onto the directory stack.
setopt NO_AUTO_REMOVE_SLASH # Keeps trailing slash for directories when auto completing.
setopt NO_BEEP # Do not beep on error in ZLE.
setopt CDABLE_VARS # Expand named directories without leading '~'.
setopt C_BASES # Output hexadecimal numbers in the standard C format ('16#FF' -> '0xFF').
setopt CHASE_LINKS # Resolve symbolic links to their true values when changing directory.
setopt NO_CLOBBER # '>!' or '>|' must be used to truncate a file, and '>>!' or '>>|' to create a file.
setopt NO_COMPLETE_ALIASES # Substitute internally before completion.
setopt COMPLETE_IN_WORD # Complete from the cursor rather than from the end of the word
setopt CORRECT # Try to correct the spelling of a command
setopt CORRECT_ALL # Try to correct the spelling of all arguments
CORRECT_IGNORE_FILE=".*" # Do not offer hidden files as correction
setopt EXTENDED_HISTORY # Save in format : <beginning time>:<elapsed seconds>;<command>
setopt EXTENDED_GLOB # Treat the `#', `~' and `^' characters as part of patterns for filename generation, etc.
setopt NO_FLOW_CONTROL # Disables output flow control in the shell's editor via start/stop characters (usually ^S/^Q).
setopt GLOB_DOTS # Do not require a leading `.' in a filename to be matched explicitly.
setopt HIST_IGNORE_DUPS # Do not enter command lines into the history list if they are duplicates of the previous event.
setopt HIST_IGNORE_SPACE # History should ignore commands beginning with a space
setopt HIST_VERIFY # perform history expansion and reload line in editing buffer instead of executing it directly
setopt NO_INC_APPEND_HISTORY # Do not write lines as soon as they are entered (breaks exec time otherwise)
setopt INC_APPEND_HISTORY_TIME # Write lines after they are finished
setopt INTERACTIVE_COMMENTS # Allow comments even in interactive shells.
setopt LIST_AMBIGUOUS # Insert unambiguous prefix without completion list (auto_list set)
setopt LIST_PACKED # Make completion list smaller by printing matches in columns with different widths.
setopt NO_MENU_COMPLETE # Do not autoselect the first entry when completing
setopt PUSHD_IGNORE_DUPS # Don't push multiple copies of the same directory onto the directory stack.
setopt NO_SHARE_HISTORY # Do not write + read history after every command (messes up exec time otherwise)
setopt SH_WORD_SPLIT # Causes field splitting to be performed on unquoted parameter expansions

View File

@@ -0,0 +1,32 @@
[[ ! -d "$ZSH_CONF/completion" ]] || fpath=("$ZSH_CONF/completion" $fpath)
autoload -Uz compinit
compinit -d "${XDG_CACHE_HOME:-$HOME/.cache}/zsh/zcompdump-$ZSH_VERSION"
zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
zstyle ':completion:*' menu select
zstyle -e ':completion:*:users' users 'local user; getent passwd | while IFS=: read -rA user; do (( user[3] >= 1000 || user[3] == 0 )) && reply+=($user[1]); done'
# Include hidden files in completion.
_comp_options+=(globdots)
# Don't complete the same argument twice for these programs.
# Taken from http://leahneukirchen.org/dotfiles/.zshrc
zstyle ':completion:*:(diff|meld|trash):*' ignore-line yes

View File

@@ -0,0 +1,134 @@
## Author: druckdev
## Created: 2019-01-16
# Default flags
alias ls='ls-show-hidden --color=auto --group-directories-first -p -v'
alias grep='grep --color'
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -I'
alias less='less -N'
alias lsblk='lsblk -f'
alias feh='feh -.'
# XDG Base Directory Specification
alias tmux='tmux -f "${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf"'
alias tmsu='tmsu -D "${XDG_DATA_HOME:-$HOME/.local/share}/tmsu/db"'
alias yarn='yarn --use-yarnrc "${XDG_CONFIG_HOME:-$HOME/.config}"/yarn/config'
alias bash='bash --rcfile "${XDG_CONFIG_HOME:-$HOME/.config}"/bash/bashrc'
# Global
alias -g G='| grep'
alias -g no2='2>/dev/null'
# Git
alias gs='git status --short'
alias ga='git add'
alias gc="git commit"
alias gpush='git push'
alias gpull='git pull'
alias gd='git diff'
# Commit, but put the last written commit message into the editor buffer.
# Useful for example when the commit-msg hook fails but only slight
# modifications are needed.
alias git-commit-last-msg='() {
local gitdir="$(git rev-parse --git-dir)" || return
git commit -eF <(grep -v "^#" "$gitdir/COMMIT_EDITMSG")
}'
# Save keystrokes and my memory
alias la='ls -A'
alias l='ls -lh --time-style=long-iso'
alias ll='l -A'
alias cd..='cd ..'
alias cl='() { cd "$@" && ls }'
alias getclip="xclip -selection c -o"
alias setclip="perl -pe 'chomp if eof' | xclip -selection c"
alias pdf='zathura --fork &>/dev/null'
alias geeqie='launch qeeqie'
alias rd='rmdir'
alias md='mkdir -p'
alias o='xdg-open'
alias :{q,Q}='exit'
alias update='
sudo apt update \
&& sudo apt upgrade -y \
&& sudo apt autoremove -y
[[ ! -e /var/run/reboot-required ]] \
|| printf "\n\nSystem restart required.\n"
'
alias pdf2t{e,}xt='pdftotext'
alias rm='printf "\033[1;031mUse trash!\n\033[0m"; false'
alias battery='cat /sys/class/power_supply/BAT0/capacity'
alias qrdecode='zbarimg'
alias loadhist='fc -RI'
alias hex='xxd'
alias bin='xxd -b -c4 | cut -d" " -f2-5'
! command -v nvim &>/dev/null || alias vim=nvim
alias vi='vim'
alias vimdiff='vim --cmd "set list" -c "set listchars=tab:>·,space:·" -d'
alias resetCursor='echo -ne "\e[5 q"'
alias makeThisScratchpad='echo -ne "\033]0;scratchpad-terminal\007"'
# grep filenames and date entries in exiftool
alias grepdate='grep -E "(={8})|([:0-9]{10} [:0-9]{8})"'
# 'Temporary' shell in alternate mode for hiding commands in scrollback.
alias tmpshell='tput smcup && zsh && tput rmcup'
# List options and their value (on|off) line by line. This makes it a lot
# easier to grep for activated options than using `setopt` and `unsetopt`.
alias listopts='printf "%s %s\n" "${(kv)options[@]}"'
# Launch program independent and detached from shell.
alias launch='() { ${aliases[$1]:-$1} "${@[2,-1]}" &>/dev/null &| }'
# Launch program after reducing the screen resolution.
alias lowres='() {
xrandr -s 1920x1080; $1 "${@[2,-1]}"; xrandr -s 3200x1800
}'
# Create copy with .bkp extension
alias bkp='() { for f; do command cp -i "$f"{,.bkp}; done }'
# Reverse bkp()
alias unbkp='() { for f; do command cp -i "$f" "${f%.bkp}; done }'
# Grep in history file
alias histgrep='() { grep "$@" "${HISTFILE:-$HOME/.zsh_history}" }'
# URL-encode
alias urlenc='() {
python3 -c \
"from urllib import parse; print(parse.quote(\"$*\"), end=\"\")"
}'
# URL-decode
alias urldec='() {
python3 -c \
"from urllib import parse; print(parse.unquote(\"$*\"), end=\"\")"
}'
# Workaround for stack smash when using stderred
alias gpg='
env LD_PRELOAD="$(
sed "s/[^:]*libstderred.so:\?//;s/:$//" <<<"$LD_PRELOAD"
)" gpg'
# Use a reasonable time format
alias date='env LC_TIME=tk_TM date'
# Named directories
for dir in "$HOME"/[^.]*(/); do
[[ ! ${dir:t} =~ " " ]] || continue
hash -d ${dir:t}="$dir"
done
hash="$(xdg-user-dir DOCUMENTS 2>/dev/null || echo docs)"
hash="$(basename "$hash")"
if (( $+nameddirs[$hash] )); then
hash -d cheat=~$hash/cheat_sheets
hash -d uni=~$hash/uni
hash -d work=~$hash/work
fi
unset hash
if (( $+nameddirs[projs] )); then
hash -d dot{,s}=~projs/dotfiles
fi
if (( $+nameddirs[uni] )); then
# Use the first match in ~uni/[0-9][0-9]-{So,Wi}Se sorted in descending
# numeric order (most recent semester). The echo is necessary as else
# filename generation will include the wise= and nothing is matched.
# TODO!
hash -d sose="$(echo ~uni/[0-9][0-9]-SoSe(NnOn[1]))"
hash -d wise="$(echo ~uni/[0-9][0-9]-WiSe(NnOn[1]))"
fi

View File

@@ -0,0 +1,342 @@
## Author: druckdev
## Created: 2019-08-28
## Compares two pdfs based on the result of pdftotext
pdfdiff() {
if [[ $# -eq 2 && -r "$1" && -r "$2" ]]; then
diff <(pdftotext "$1" -) <(pdftotext "$2" -)
else
echo "something went wrong" 2>&1
return 1
fi
}
## Gets Passwd from bitwarden and copies it into the clipboard
bwpwd() {
if bw "get" "password" "$@" >/dev/null; then
bw "get" "password" "$@" | tr -d '\n' | setclip
else
bw "get" "password" "$@"
fi
}
## creates directory and changes into it
mkcd () {
# Create directory
mkdir "$@"
# shift arguments if mkdir options were used
while [[ $# -gt 1 ]]; do
shift
done
if [[ -d "$1" ]]; then
cd "$1"
pwd
fi
}
## Encode and decode qr-codes
qr() {
if [[ $# -eq 1 && -r "$1" ]]; then
zbarimg "$1"
else
qrencode "$@"
fi
}
## Edit config file
conf() {
local CONF_EDITOR
if [[ -n "$EDITOR" ]]; then
CONF_EDITOR="$EDITOR"
elif command -v vim &>/dev/null; then
CONF_EDITOR=vim
elif command -v nano &>/dev/null; then
CONF_EDITOR=nano
else
CONF_EDITOR=cat
fi
# Parse otions
while getopts "e:" opt 2>/dev/null; do
case $opt in
e) CONF_EDITOR="$OPTARG";;
*) printf "\033[1;31mUsage: $0 [-e <editor>] <program>[/subdirs] [<config_file>]\n\033[0m" >&2
return 1 ;;
esac
done
shift $(( $OPTIND - 1 ))
# conf needs an argument
if [[ $# -eq 0 ]]; then
printf "\033[1;31mPlease specify a config.\n\033[0m" >&2
return 1
fi
# search for program name in XDG_CONFIG_HOME and $HOME
local CONF_DIR="$(_get_config_dir "$1")"
if (( $? )); then
printf "\033[1;31mFalling back to $HOME.\n\033[0m" >&2
CONF_DIR="$HOME"
fi
# If specific name is given, open file.
if [[ $# -gt 1 ]]; then
"$CONF_EDITOR" "$CONF_DIR/$2"
return
fi
# possible config-file names + same but hidden
local -a CONF_PATTERNS
CONF_PATTERNS=(
"$1.conf"
"$1.config"
"${1}rc"
"config"
"conf"
"$1.yml"
"$1.yaml"
"config.ini"
"$1"
)
# check if config file exists
for config in $CONF_PATTERNS; do
if [[ -e "$CONF_DIR/$config" ]]; then
$CONF_EDITOR "$CONF_DIR/$config"
return 0
elif [[ -e "$CONF_DIR/.$config" ]]; then
$CONF_EDITOR "$CONF_DIR/.$config"
return 0
fi
done
# if no config was found in a location other than HOME, look again in HOME.
# (For cases like default vim with ~/.vim/ and ~/.vimrc)
if [[ "$CONF_DIR" != "$HOME" ]];then
for config in $CONF_PATTERNS; do
# Only look for hidden files
if [[ -e "$HOME/.$config" ]]; then
$CONF_EDITOR "$HOME/.$config"
return 0
fi
done
fi
printf "\033[1;31mCould not find config file.\n\033[0m" >&2
return 1
}
## Change into config dir
c() {
CONF_DIR="$(_get_config_dir $*)"
if [[ $? -eq 0 ]]; then
cd "$CONF_DIR"
else
printf "$CONF_DIR" >&2
return 1
fi
}
## Get config directory
_get_config_dir() {
if [[ $# -gt 1 ]]; then
printf "\033[1;31mPlease specify one config.\n\033[0m" >&2
return 1
elif [[ $# -eq 0 ]]; then
echo "${XDG_CONFIG_HOME:-$HOME/.config}"
elif [[ -d "${XDG_CONFIG_HOME:-$HOME/.config}/$1" ]]; then
echo "${XDG_CONFIG_HOME:-$HOME/.config}/$1"
elif [[ -d "$HOME/.$1" ]]; then
echo "$HOME/.$1"
else
printf "\033[1;31mCould not find config home.\n\033[0m" >&2
return 1
fi
}
## Function that resolves a command to the end
resolve() {
# TODO: comment!!
# In script mode only the result and its arguments are printed
# The result can then be used directly by other scripts without further
# manipulation
typeset SCRIPT_MODE VERBOSE_MODE 1>&2
while getopts "sv" opt 2>/dev/null; do
case $opt in
s) SCRIPT_MODE=1;;
v) VERBOSE_MODE=1;;
*) echo "Unknown flag!" >&2
return 1;;
esac
done
shift $(( $OPTIND - 1 ))
if (( $SCRIPT_MODE )) && (( $VERBOSE_MODE )); then
echo "Script and verbose mode do no work together." >&2
return 1
fi
typeset THIS THIS_COMMAND THIS_ARGUMENTS 1>&2
# When receiving a command with arguments, do not differ between
# one and multiple arguments.
THIS="$*"
THIS_COMMAND="${THIS%% *}"
# ${THIS%%* } would result in THIS_COMMAND when no arguements are specified.
# We want an empty string in this case.
THIS_ARGUMENTS="${THIS#${THIS_COMMAND}}"
# Resolve all aliases
while [[ "$(which $THIS_COMMAND | head -n1)" =~ "^${THIS_COMMAND}: aliased to " ]]; do
if (( $VERBOSE_MODE )); then
echo $THIS_COMMAND$THIS_ARGUMENTS
fi
THIS="$(which "$THIS_COMMAND" | cut -d' ' -f4-)"
THIS_COMMAND="${THIS%% *}"
THIS_ARGUMENTS="${THIS#${THIS_COMMAND}}$THIS_ARGUMENTS"
done
command_type="$(type $THIS_COMMAND)"
if [[ "$command_type" =~ "^$THIS_COMMAND is a shell function from " ]]; then
if (( $SCRIPT_MODE )); then
echo -n "$THIS_COMMAND$THIS_ARGUMENTS"
return 0
elif (( $VERBOSE_MODE )); then
echo "$THIS_COMMAND$THIS_ARGUMENTS"
else
echo "$* is resolved to:\n$THIS_COMMAND$THIS_ARGUMENTS"
fi
echo -n "${command_type}:"
from_file="$(echo $command_type | cut -d' ' -f7-)"
# from_file=${command_type##* }
grep -En -m1 "(function[ \t]+${THIS_COMMAND}[ \t]*(\(\)|)[ \t]*{|${THIS_COMMAND}[ \t]*\(\)[ \t]*{)" "$from_file" \
| cut -d: -f1
else
if (( $VERBOSE_MODE )); then
echo "$THIS_COMMAND$THIS_ARGUMENTS"
fi
THIS_COMMAND="$(which $THIS_COMMAND)"
if [[ $? -ne 0 ]]; then
echo "${THIS_COMMAND%% *} not found." >&2
return 1
fi
if (( $VERBOSE_MODE )); then
echo -n "$THIS_COMMAND"
NEXT_STEP="$(file -bh $THIS_COMMAND | cut -d' ' -f4-)"
if [[ "${NEXT_STEP:0:1}" != '/' ]]; then
NEXT_STEP="${THIS_COMMAND%/*}/$NEXT_STEP"
fi
while [[ "$(file -bh $THIS_COMMAND)" =~ "^symbolic link to" && "$NEXT_STEP" != "$THIS_COMMAND" ]]; do
THIS_COMMAND=$NEXT_STEP
NEXT_STEP="$(file -bh $THIS_COMMAND | cut -d' ' -f4-)"
if [[ "${NEXT_STEP:0:1}" != '/' ]]; then
NEXT_STEP="${THIS_COMMAND%/*}/$NEXT_STEP"
fi
echo -n "\n$THIS_COMMAND"
done
echo $THIS_ARGUMENTS
return 0
fi
THIS_COMMAND="$(realpath $THIS_COMMAND)"
if (( $SCRIPT_MODE )); then
echo -n "$THIS_COMMAND$THIS_ARGUMENTS"
return 0
fi
echo "$* is resolved to:\n$THIS_COMMAND$THIS_ARGUMENTS"
fi
}
## Grep a keyword at the beginning of a line (ignoring whitespace) in a man page
mangrep() {
if [[ $# -lt 2 ]]; then
printf "usage: mangrep <man page> <pattern> [<man flags>]\n" >&2
printf "example: mangrep bash \"(declare|typeset)\"\n" >&2
return 1
fi
local page="$1" pattern="$2"
shift 2
man -P "less -p \"^ *${pattern}\"" "$@" "${file}"
}
safe-remove() {
[[ $# -gt 0 ]] || return 1
[[ -e "$1" ]] || return 1
sync
if ! udisksctl unmount -b "$1"; then
lsof "$1"
return 1
fi
udisksctl power-off -b "/dev/$(lsblk -no pkname "$1")"
}
crypt-mount() {
[[ $# -gt 0 ]] || return 1
[[ -e "$1" ]] || return 1
sudo cryptsetup open "$1" crypt_"${1##*/}" || return 1
udisksctl mount -b /dev/mapper/crypt_"${1##*/}"
}
crypt-umount() {
[[ $# -gt 0 ]] || return 1
[[ -e "$1" ]] || return 1
sync
if ! udisksctl unmount -b /dev/mapper/crypt_"${1##*/}"; then
lsof /dev/mapper/crypt_"${1##*/}"
return 1
fi
if ! sudo cryptsetup close crypt_"${1##*/}"; then
sudo cryptsetup status crypt_"${1##*/}"
return 1
fi
udisksctl power-off -b "$1"
}
## List items in trash if no argument is specified
trash() {
if (( ! $# )); then
command trash-list
else
command trash "$@"
fi
}
## Open nemo in current directory if no argument is specified
nemo() {
if (( ! $# )); then
command nemo .
else
command nemo "$@"
fi
}
## Move a file but keep a symlink to the new location.
mvln() {
# DST will not exist if `mv` is used for renaming.
[[ -e $1 ]] && [[ -d $2 || -d "$(dirname "$2")" ]] || return 1
mv "$1" "$2" || return
if [[ -d $2 ]]; then
ln -s "${2:A}/$(basename "$1")" "$1"
else
ln -s "${2:A}" "$1"
fi
}
## cd wrapper that when called without arguments, moves into the root of the
## current repo instead of HOME. (Except when already there)
cd() {
if [[ $# -gt 0 ]]; then
builtin cd "$@"
return
fi
local toplevel
toplevel="$(git rev-parse --show-toplevel 2>/dev/null)"
if (( $? )) || [[ $PWD = $toplevel ]]; then
builtin cd
else
builtin cd "$toplevel"
fi
}

View File

@@ -0,0 +1 @@
../../plugins/powerlevel10k/powerlevel10k.zsh-theme

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
../../plugins/zsh-autosuggestions/zsh-autosuggestions.zsh

View File

@@ -0,0 +1 @@
../../plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

View File

@@ -0,0 +1,30 @@
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
## colors: 0-7 standard, 8-15 high-intensity
## red
ZSH_HIGHLIGHT_STYLES[bracket-error]='fg=009,bold'
ZSH_HIGHLIGHT_STYLES[unknown-token]='fg=009,bold'
## green
ZSH_HIGHLIGHT_STYLES[arg0]='fg=076'
ZSH_HIGHLIGHT_STYLES[suffix-alias]='fg=076,underline'
ZSH_HIGHLIGHT_STYLES[bracket-level-2]='fg=076,bold'
ZSH_HIGHLIGHT_STYLES[precommand]='fg=076,underline'
## blue
ZSH_HIGHLIGHT_STYLES[bracket-level-1]='fg=012,bold'
## yellow
ZSH_HIGHLIGHT_STYLES[double-quoted-argument]='fg=011'
ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]='fg=011'
ZSH_HIGHLIGHT_STYLES[bracket-level-4]='fg=011,bold'
ZSH_HIGHLIGHT_STYLES[single-quoted-argument]='fg=011'
ZSH_HIGHLIGHT_STYLES[reserved-word]='fg=011'
ZSH_HIGHLIGHT_STYLES[path_prefix]='fg=011,underline'
## cyan
ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]='fg=014'
ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]='fg=014'
ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]='fg=014'
ZSH_HIGHLIGHT_STYLES[bracket-level-5]='fg=014,bold'
ZSH_HIGHLIGHT_STYLES[rc-quote]='fg=014'
## black/dark grey
ZSH_HIGHLIGHT_STYLES[comment]='fg=008,bold'
## magenta
ZSH_HIGHLIGHT_STYLES[bracket-level-3]='fg=13,bold'

View File

@@ -0,0 +1 @@
../../plugins/fzf-tab-fork/fzf-tab.zsh

View File

@@ -0,0 +1 @@
../../plugins/fzf/shell/key-bindings.zsh

View File

@@ -0,0 +1 @@
../../plugins/stderred/usr/share/stderred/stderred.sh

View File

@@ -0,0 +1,4 @@
# Bold red
export STDERRED_ESC_CODE="$(tput bold && tput setaf 1)"
export STDERRED_BLACKLIST="^(git|curl|wget|swipl)$"

View File

@@ -0,0 +1,134 @@
## Author: druckdev
## Created: 2019-04-17
# Vim bindings
bindkey -v
# Text object selection
# Copied and slightly modified from:
# https://github.com/softmoth/zsh-vim-mode/blob/abef0c0c03506009b56bb94260f846163c4f287a/zsh-vim-mode.plugin.zsh#L214-#L228
autoload -U select-bracketed select-quoted
zle -N select-bracketed
zle -N select-quoted
for m in visual viopp; do
for c in {a,i}{\(,\),\[,\],\{,\},\<,\>,b,B}; do
bindkey -M "$m" "$c" select-bracketed
done
for c in {a,i}{\',\",\`}; do
bindkey -M "$m" "$c" select-quoted
done
done
# no delay when switching into NORMAL
export KEYTIMEOUT=1
function zle-line-init zle-keymap-select {
# Switch cursor style depending on mode
case $KEYMAP in
vicmd) echo -ne "\e[1 q";; # block
viins|main) echo -ne "\e[5 q";; # beam
esac
# Make sure that the terminal is in application mode when zle is active,
# since only then values from $terminfo are valid
! (( $+terminfo[smkx] )) || echoti smkx
}
zle -N zle-line-init
zle -N zle-keymap-select
function zle-line-finish {
# See above (echoti smkx)
! (( $+terminfo[rmkx] )) || echoti rmkx
}
zle -N zle-line-finish
bindkey '^H' run-help
bindkey '^E' edit-command-line
## Navigation
bindkey '^[[Z' reverse-menu-complete # shift-tab
bindkey '^Q' push-input # ctrl-Q
bindkey '\e[H' beginning-of-line # home
bindkey "$terminfo[khome]" beginning-of-line # home
bindkey '\e[F' end-of-line # end
bindkey "$terminfo[kend]" end-of-line # end
bindkey -v '^?' backward-delete-char # normal delete not vim-bac...
bindkey '^[[P' delete-char # delete
bindkey '^[[3~' delete-char # delete
bindkey '^[[1;5D' backward-word # ctrl-left
bindkey '^[[1;5C' forward-word # ctrl-right
bindkey '^H' backward-kill-word # ctrl-backspace
bindkey '^[[3;5~' kill-word # ctrl-delete
bindkey "$terminfo[kmous]" kill-word # ctrl-delete
# Modified version (end with a trailing slash) of:
# https://github.com/majutsushi/etc/blob/1d8a5aa28/zsh/zsh/func/rationalize-dots
function rationalize_dots {
# Rationalize dots at BOL or after a space or slash.
if [[ "$LBUFFER" =~ "(^|[ /])\.\./$" ]]; then
LBUFFER+=../
elif [[ "$LBUFFER" =~ "(^|[ /])\.$" ]]; then
LBUFFER+=./
else
LBUFFER+=.
return
fi
# Print currently typed path as absolute path with "collapsed"/reversed
# filename expansion.
zle -M "${(D)${(z)LBUFFER}[-1]:a}"
}
zle -N rationalize_dots
bindkey . rationalize_dots
function ls-on-enter {
# Execute `ls` when enter is pressed without a command entered.
[[ -n "$BUFFER" ]] || BUFFER=ls
zle accept-line
# See fzf-hist below
FZF_HIST_WENT_UP=
}
zle -N ls-on-enter
bindkey "^M" ls-on-enter
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(ls-on-enter)
# "Scroll" through history if buffer was empty but use it as query for fzf over
# command line history if not (similar to substring-search but with fzf)
function fzf-hist-up {
if [[ -z "$BUFFER" || "$FZF_HIST_WENT_UP" -eq 1 ]]; then
zle up-line-or-history
FZF_HIST_WENT_UP=1
else
# Will take BUFFER as query
fzf-history-widget
fi
}
function fzf-hist-down {
zle down-line-or-history
[[ -n "$BUFFER" ]] || FZF_HIST_WENT_UP=
}
zle -N fzf-hist-up
zle -N fzf-hist-down
## History
# Up
bindkey '^[[A' fzf-hist-up
bindkey "$terminfo[kcuu1]" fzf-hist-up
# Ctrl-Up
bindkey '^[[1;5A' fzf-history-widget
# Down
bindkey '^[[B' fzf-hist-down
bindkey "$terminfo[kcud1]" fzf-hist-down
# Ctrl-K
bindkey '^K' fzf-hist-up
# Ctrl-K in normal mode
bindkey -M vicmd '^K' fzf-history-widget
# Ctrl-J
bindkey '^J' fzf-hist-down
# Fuzzy finder bindings:
# ^T fzf-file-widget
# \ec (Alt-C) fzf-cd-widget
# ^R fzf-history-widget
comp-source "$ZSH_CONF/fzf/shell/key-bindings.zsh"

View File

@@ -0,0 +1,7 @@
HISTSIZE=1000000
SAVEHIST=1000000
if [[ ! -d "${XDG_DATA_HOME:-$HOME/.local/share}"/zsh ]]; then
mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}"/zsh
fi
HISTFILE="${XDG_DATA_HOME:-$HOME/.local/share}"/zsh/zsh_history