From 0caae9082a3bbb14b05938a7d0f292c2e4d161f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sun, 5 Apr 2020 21:34:53 +0200 Subject: [PATCH] lib: speed up slow parts of the lib files; other small fixes --- lib/completion.zsh | 2 +- lib/functions.zsh | 2 +- lib/misc.zsh | 20 ++++++++++---------- lib/spectrum.zsh | 26 ++++++++++++-------------- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/lib/completion.zsh b/lib/completion.zsh index c932bc925..8b87557a2 100644 --- a/lib/completion.zsh +++ b/lib/completion.zsh @@ -73,4 +73,4 @@ if [[ $COMPLETION_WAITING_DOTS = true ]]; then fi # automatically load bash completion functions -autoload -Uz bashcompinit && bashcompinit +autoload -U +X bashcompinit && bashcompinit diff --git a/lib/functions.zsh b/lib/functions.zsh index f934ab968..678e29ce7 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -89,7 +89,7 @@ function default() { # 0 if the env variable exists, 3 if it was set # function env_default() { - (( ${${(@f):-$(typeset +xg)}[(I)$1]} )) && return 0 + [[ ${parameters[$1]} = *-export* ]] && return 0 export "$1=$2" && return 3 } diff --git a/lib/misc.zsh b/lib/misc.zsh index 61571afc9..a5d3af998 100644 --- a/lib/misc.zsh +++ b/lib/misc.zsh @@ -3,15 +3,15 @@ autoload -Uz is-at-least # *-magic is known buggy in some versions; disable if so if [[ $DISABLE_MAGIC_FUNCTIONS != true ]]; then for d in $fpath; do - if [[ -e "$d/url-quote-magic" ]]; then - if is-at-least 5.1; then - autoload -Uz bracketed-paste-magic - zle -N bracketed-paste bracketed-paste-magic - fi - autoload -Uz url-quote-magic - zle -N self-insert url-quote-magic - break - fi + if [[ -e "$d/url-quote-magic" ]]; then + if is-at-least 5.1; then + autoload -Uz bracketed-paste-magic + zle -N bracketed-paste bracketed-paste-magic + fi + autoload -Uz url-quote-magic + zle -N self-insert url-quote-magic + break + fi done fi @@ -25,7 +25,7 @@ env_default 'LESS' '-R' alias _='sudo ' ## more intelligent acking for ubuntu users -if which ack-grep &> /dev/null; then +if (( $+commands[ack-grep] )); then alias afind='ack-grep -il' else alias afind='ack -il' diff --git a/lib/spectrum.zsh b/lib/spectrum.zsh index 312ab2248..d5c22a8c5 100644 --- a/lib/spectrum.zsh +++ b/lib/spectrum.zsh @@ -1,4 +1,3 @@ -#! /bin/zsh # A script to make using 256 colors in zsh less painful. # P.C. Shyamshankar # Copied from https://github.com/sykora/etc/blob/master/zsh/functions/spectrum/ @@ -6,32 +5,31 @@ typeset -AHg FX FG BG FX=( - reset "%{%}" - bold "%{%}" no-bold "%{%}" - italic "%{%}" no-italic "%{%}" - underline "%{%}" no-underline "%{%}" - blink "%{%}" no-blink "%{%}" - reverse "%{%}" no-reverse "%{%}" + reset "%{%}" + bold "%{%}" no-bold "%{%}" + italic "%{%}" no-italic "%{%}" + underline "%{%}" no-underline "%{%}" + blink "%{%}" no-blink "%{%}" + reverse "%{%}" no-reverse "%{%}" ) for color in {000..255}; do - FG[$color]="%{[38;5;${color}m%}" - BG[$color]="%{[48;5;${color}m%}" + FG[$color]="%{[38;5;${color}m%}" + BG[$color]="%{[48;5;${color}m%}" done - -ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris} - # Show all 256 colors with color number function spectrum_ls() { + local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris} for code in {000..255}; do - print -P -- "$code: %{$FG[$code]%}$ZSH_SPECTRUM_TEXT%{$reset_color%}" + print -P -- "$code: $FG[$code]$ZSH_SPECTRUM_TEXT%{$reset_color%}" done } # Show all 256 colors where the background is set to specific color function spectrum_bls() { + local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris} for code in {000..255}; do - print -P -- "$code: %{$BG[$code]%}$ZSH_SPECTRUM_TEXT%{$reset_color%}" + print -P -- "$code: $BG[$code]$ZSH_SPECTRUM_TEXT%{$reset_color%}" done }