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

@@ -1,134 +0,0 @@
## 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

@@ -1,47 +0,0 @@
#compdef conf
## Author: druckdev
## Created: 2020-04-19
local _MAX_DEPTH=2
local w1="${words[$#words - 1]}"
local w2="${words[$#words - 2]}"
local w3="${words[$#words - 3]}"
if [ -z $w2 ]; then # first word to complete
# move into config directory
pushd -q "${XDG_CONFIG_HOME:-$HOME/.config}/"
# list all directories
local paths="$(find -L *(-/) -maxdepth $_MAX_DEPTH -type d 2>/dev/null | xargs)"
# move back from config directory
popd -q
# move into HOME
pushd -q "$HOME"
# list all directories starting with a dot (but remove that dot)
paths+="$(find -L .*~.cache(-/) -maxdepth $_MAX_DEPTH -type d 2>/dev/null | sed 's/^\.//' | xargs)"
# move back from HOME
popd -q
# use list for completion
_multi_parts / '('"$paths"')'
elif [ -z $w3 ]; then # second word to complete
# move into chosen config directory
if [ -d "${XDG_CONFIG_HOME:-$HOME/.config}/$w1" ]; then
pushd -q "${XDG_CONFIG_HOME:-$HOME/.config}/$w1"
elif [ -d "$HOME/.$w1" ]; then
pushd -q "$HOME/.$w1"
fi
# check if there are any files here
# eval "local $(echo $functions[conf] | grep CONF_PATTERNS= | sed -E 's/\$(\{?)1(\}?)/\$\1w1\2/g; s/^[ \t]*//')"
local exist=( *(-.) ) 2>/dev/null
# complete (symlinks pointing to) files
[ -z "$exist" ] || _values "config:" *(-.)
# move back
popd -q
fi

View File

@@ -1,342 +0,0 @@
## 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

@@ -1,134 +0,0 @@
## 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

@@ -1,148 +0,0 @@
--- p10k.zsh-theme 2020-08-25 04:58:57.523296332 +0200
+++ p10k.zsh-theme 2020-08-25 04:56:22.351599739 +0200
@@ -45,6 +45,9 @@
# last prompt line gets hidden if it would overlap with left prompt.
typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(
# =========================[ Line #1 ]=========================
+ # time # current time
+ # =========================[ Line #2 ]=========================
+ newline
status # exit code of the last command
command_execution_time # duration of the last command
background_jobs # presence of background jobs
@@ -87,7 +90,7 @@
vim_shell # vim shell indicator (:sh)
midnight_commander # midnight commander shell (https://midnight-commander.org/)
nix_shell # nix shell (https://nixos.org/nixos/nix-pills/developing-with-nix-shell.html)
- # vpn_ip # virtual private network indicator
+ vpn_ip # virtual private network indicator
# load # CPU load
# disk_usage # disk usage
# ram # free RAM
@@ -95,9 +98,6 @@
todo # todo items (https://github.com/todotxt/todo.txt-cli)
timewarrior # timewarrior tracking status (https://timewarrior.net/)
taskwarrior # taskwarrior task count (https://taskwarrior.org/)
- time # current time
- # =========================[ Line #2 ]=========================
- newline
# ip # ip address and bandwidth usage for a specified network interface
# public_ip # public IP address
# proxy # system-wide http/https/ftp proxy
@@ -188,9 +188,9 @@
# Red prompt symbol if the last command failed.
typeset -g POWERLEVEL9K_PROMPT_CHAR_ERROR_{VIINS,VICMD,VIVIS,VIOWR}_FOREGROUND=196
# Default prompt symbol.
- typeset -g POWERLEVEL9K_PROMPT_CHAR_{OK,ERROR}_VIINS_CONTENT_EXPANSION=''
+ typeset -g POWERLEVEL9K_PROMPT_CHAR_{OK,ERROR}_VIINS_CONTENT_EXPANSION='>'
# Prompt symbol in command vi mode.
- typeset -g POWERLEVEL9K_PROMPT_CHAR_{OK,ERROR}_VICMD_CONTENT_EXPANSION=''
+ typeset -g POWERLEVEL9K_PROMPT_CHAR_{OK,ERROR}_VICMD_CONTENT_EXPANSION='<'
# Prompt symbol in visual vi mode.
typeset -g POWERLEVEL9K_PROMPT_CHAR_{OK,ERROR}_VIVIS_CONTENT_EXPANSION='V'
# Prompt symbol in overwrite vi mode.
@@ -325,7 +325,7 @@
#####################################[ vcs: git status ]######################################
# Branch icon. Set this parameter to '\uF126 ' for the popular Powerline branch icon.
- typeset -g POWERLEVEL9K_VCS_BRANCH_ICON=
+ typeset -g POWERLEVEL9K_VCS_BRANCH_ICON='| '
# Untracked files icon. It's really a question mark, your font isn't broken.
# Change the value of this parameter to show a different icon.
@@ -371,7 +371,7 @@
res+="${clean}${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}"
where=${(V)VCS_STATUS_LOCAL_BRANCH}
elif [[ -n $VCS_STATUS_TAG ]]; then
- res+="${meta}#"
+ res+="${meta}${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}#"
where=${(V)VCS_STATUS_TAG}
fi
@@ -481,32 +481,32 @@
# like this: 1|0.
typeset -g POWERLEVEL9K_STATUS_OK_PIPE=true
typeset -g POWERLEVEL9K_STATUS_OK_PIPE_FOREGROUND=70
- typeset -g POWERLEVEL9K_STATUS_OK_PIPE_VISUAL_IDENTIFIER_EXPANSION='✔'
+ typeset -g POWERLEVEL9K_STATUS_OK_PIPE_VISUAL_IDENTIFIER_EXPANSION=
# Status when it's just an error code (e.g., '1'). No need to show it if prompt_char is enabled as
# it will signify error by turning red.
- typeset -g POWERLEVEL9K_STATUS_ERROR=false
+ typeset -g POWERLEVEL9K_STATUS_ERROR=true
typeset -g POWERLEVEL9K_STATUS_ERROR_FOREGROUND=160
- typeset -g POWERLEVEL9K_STATUS_ERROR_VISUAL_IDENTIFIER_EXPANSION='✘'
+ typeset -g POWERLEVEL9K_STATUS_ERROR_VISUAL_IDENTIFIER_EXPANSION=
# Status when the last command was terminated by a signal.
typeset -g POWERLEVEL9K_STATUS_ERROR_SIGNAL=true
typeset -g POWERLEVEL9K_STATUS_ERROR_SIGNAL_FOREGROUND=160
# Use terse signal names: "INT" instead of "SIGINT(2)".
- typeset -g POWERLEVEL9K_STATUS_VERBOSE_SIGNAME=false
- typeset -g POWERLEVEL9K_STATUS_ERROR_SIGNAL_VISUAL_IDENTIFIER_EXPANSION='✘'
+ typeset -g POWERLEVEL9K_STATUS_VERBOSE_SIGNAME=true
+ typeset -g POWERLEVEL9K_STATUS_ERROR_SIGNAL_VISUAL_IDENTIFIER_EXPANSION=
# Status when some part of a pipe command fails and the overall exit status is also non-zero.
# It may look like this: 1|0.
typeset -g POWERLEVEL9K_STATUS_ERROR_PIPE=true
typeset -g POWERLEVEL9K_STATUS_ERROR_PIPE_FOREGROUND=160
- typeset -g POWERLEVEL9K_STATUS_ERROR_PIPE_VISUAL_IDENTIFIER_EXPANSION='✘'
+ typeset -g POWERLEVEL9K_STATUS_ERROR_PIPE_VISUAL_IDENTIFIER_EXPANSION=
###################[ command_execution_time: duration of the last command ]###################
# Show duration of the last command if takes longer than this many seconds.
- typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=3
+ typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1
# Show this many fractional digits. Zero means round to seconds.
- typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0
+ typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=2
# Execution time color.
typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND=101
# Duration format: 1d 2h 3m 4s.
@@ -522,7 +522,7 @@
# Background jobs color.
typeset -g POWERLEVEL9K_BACKGROUND_JOBS_FOREGROUND=70
# Custom icon.
- # typeset -g POWERLEVEL9K_BACKGROUND_JOBS_VISUAL_IDENTIFIER_EXPANSION='⭐'
+ typeset -g POWERLEVEL9K_BACKGROUND_JOBS_VISUAL_IDENTIFIER_EXPANSION='☰'
#######################[ direnv: direnv status (https://direnv.net/) ]########################
# Direnv color.
@@ -1382,16 +1382,16 @@
typeset -g POWERLEVEL9K_VPN_IP_FOREGROUND=81
# When on VPN, show just an icon without the IP address.
# Tip: To display the private IP address when on VPN, remove the next line.
- typeset -g POWERLEVEL9K_VPN_IP_CONTENT_EXPANSION=
+ # typeset -g POWERLEVEL9K_VPN_IP_CONTENT_EXPANSION=
# Regular expression for the VPN network interface. Run `ifconfig` or `ip -4 a show` while on VPN
# to see the name of the interface.
- typeset -g POWERLEVEL9K_VPN_IP_INTERFACE='(wg|(.*tun))[0-9]*'
+ typeset -g POWERLEVEL9K_VPN_IP_INTERFACE='(wg|(.*tun)|vpn)[0-9]*'
# If set to true, show one segment per matching network interface. If set to false, show only
# one segment corresponding to the first matching network interface.
# Tip: If you set it to true, you'll probably want to unset POWERLEVEL9K_VPN_IP_CONTENT_EXPANSION.
- typeset -g POWERLEVEL9K_VPN_IP_SHOW_ALL=false
+ typeset -g POWERLEVEL9K_VPN_IP_SHOW_ALL=true
# Custom icon.
- # typeset -g POWERLEVEL9K_VPN_IP_VISUAL_IDENTIFIER_EXPANSION='⭐'
+ typeset -g POWERLEVEL9K_VPN_IP_VISUAL_IDENTIFIER_EXPANSION=
###########[ ip: ip address and bandwidth usage for a specified network interface ]###########
# IP color.
@@ -1464,13 +1464,13 @@
####################################[ time: current time ]####################################
# Current time color.
- typeset -g POWERLEVEL9K_TIME_FOREGROUND=66
+ typeset -g POWERLEVEL9K_TIME_FOREGROUND=39
# Format for the current time: 09:51:02. See `man 3 strftime`.
typeset -g POWERLEVEL9K_TIME_FORMAT='%D{%H:%M:%S}'
# If set to true, time will update when you hit enter. This way prompts for the past
# commands will contain the start times of their commands as opposed to the default
# behavior where they contain the end times of their preceding commands.
- typeset -g POWERLEVEL9K_TIME_UPDATE_ON_COMMAND=false
+ typeset -g POWERLEVEL9K_TIME_UPDATE_ON_COMMAND=true
# Custom icon.
typeset -g POWERLEVEL9K_TIME_VISUAL_IDENTIFIER_EXPANSION=
# Custom prefix.

File diff suppressed because it is too large Load Diff

View File

@@ -1,93 +0,0 @@
# Copyright 2019 Roman Perepelitsa
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Measures how long it takes for your zsh prompt to render. Roughly speaking,
# if you press and hold [ENTER], how many prompts will be printed per second?
#
# $1 -- Benchmark for this many seconds. Default is 5.
# $2 -- Sleep for this many seconds before benchmarking to fill the keyboard input buffer.
# This mitigates the problem caused by slow key repeat rate (see below). Default is 10.
#
# After calling this function in an interactive shell you need to press and hold [ENTER] until
# you see benchmark results. It'll take 15 seconds with default arguments. The output also includes
# your prompt with all non-ascii characters escaped. This is to enable you to easily share the
# results with others (e.g., if you want to complain to your zsh theme provider about high prompt
# latency). Not only will they see how fast (or how slow!) your prompt renders but also what it
# actually looks like.
#
# Make sure your repeat key rate is high enough that your shell is unable to keep up. While not
# benchmarking, press and hold [ENTER]. If you see empty lines between prompts or if prompts keep
# being printed after you release [ENTER], your repeat key rate is sufficient. If it's not,
# you can artificially boost it by buffering keyboard input buffer. Your effective key repeat
# rate is multiplied by 1 + $2 / $1. With default settings this is 1 + 10 / 5 == 3.
function zsh-prompt-benchmark() {
typeset -gHF3 _BENCHMARK_PROMPT_DURATION=${1:-5}
typeset -gHi _BENCHMARK_PROMPT_WARMUP_DURATION=${2:-10}
typeset -gHi _BENCHMARK_PROMPT_SAMPLE_IDX=0
typeset -gHF3 _BENCHMARK_PROMPT_START_TIME=0
>&2 echo "Enabling prompt benchmarking for ${_BENCHMARK_PROMPT_DURATION}s" \
"after buffering keyboard input for ${_BENCHMARK_PROMPT_WARMUP_DURATION}s."
>&2 echo "Press and hold [ENTER] until you see benchmark results."
add-zsh-hook precmd _zsh_prompt_benchmark_precmd
typeset -gHf _zsh_prompt_benchmark_precmd() {
local -F now=$EPOCHREALTIME
((++_BENCHMARK_PROMPT_SAMPLE_IDX))
if ((now < _BENCHMARK_PROMPT_START_TIME + _BENCHMARK_PROMPT_DURATION)); then
return
fi
if (( _BENCHMARK_PROMPT_START_TIME )); then
local -i N=$((_BENCHMARK_PROMPT_SAMPLE_IDX - 1))
local -F3 T=$((now - _BENCHMARK_PROMPT_START_TIME))
local -F2 P=$((1000 * T / N))
local LP=$(eval LC_ALL=C printf '%q' \"$PROMPT\")
local RP=$(eval LC_ALL=C printf '%q' \"$RPROMPT\")
>&2 echo -E "************************************************************"
>&2 echo -E " Prompt Benchmark Results "
>&2 echo -E "************************************************************"
>&2 echo -E "Warmup duration ${_BENCHMARK_PROMPT_WARMUP_DURATION}s"
>&2 echo -E "Benchmarked prompts $N"
>&2 echo -E "Total time ${T}s"
>&2 echo -E "Time per prompt ${P}ms"
>&2 echo -E "************************************************************"
>&2 echo -E ""
>&2 echo -E "PROMPT=$LP"
>&2 echo -E ""
>&2 echo -E "RPROMPT=$RP"
>&2 echo -E ""
>&2 echo -E "Tip: To print one of the reported prompts, execute the"
>&2 echo -E "following command with \${P} replaced by the prompt string."
>&2 echo -E ""
>&2 echo -E " print -lP BEGIN \${P} '' END"
>&2 echo -E ""
>&2 echo -E "For example, here's how you can print the same left prompt"
>&2 echo -E "(PROMPT) that was benchmarked:"
>&2 echo -E ""
>&2 echo -E " print -lP BEGIN $LP END"
>&2 echo -E "************************************************************"
>&2 echo -E ""
>&2 echo -E "Press 'q' to continue..."
unset -m "_BENCHMARK_PROMPT_*"
unset -f _zsh_prompt_benchmark_precmd
add-zsh-hook -D precmd _zsh_prompt_benchmark_precmd
local _ && IFS='' read -rsd q _
else
sleep $_BENCHMARK_PROMPT_WARMUP_DURATION
typeset -gHF _BENCHMARK_PROMPT_START_TIME=$EPOCHREALTIME
fi
}
}
zmodload zsh/datetime
autoload -Uz add-zsh-hook

View File

@@ -1,30 +0,0 @@
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'