From 4c0e1dfc324fa26ee6a03e14dcbac1419ff4b62a Mon Sep 17 00:00:00 2001 From: Salvydas Lukosius Date: Sat, 24 Feb 2024 04:40:14 +0000 Subject: [PATCH] chore: Refactor zsh function options setting for consistency Consolidated zsh function option settings for consistency and readability by removing redundant options and standardizing the declaration format. This streamlines maintenance and enhances code clarity. Fixes #96. Signed-off-by: Salvydas Lukosius --- functions/.zi-prepare-zoxide | 5 ++--- functions/.zsh-prepare-zoxide | 6 ++---- functions/@zsh-eval-cache | 12 +++++------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/functions/.zi-prepare-zoxide b/functions/.zi-prepare-zoxide index 1c3fee0..e8afef4 100644 --- a/functions/.zi-prepare-zoxide +++ b/functions/.zi-prepare-zoxide @@ -7,10 +7,9 @@ # Zsh Plugin Standard # https://wiki.zshell.dev/community/zsh_plugin_standard#standard-recommended-options builtin emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace} -builtin setopt extended_glob warn_create_global \ -typeset_silent no_short_loops rc_quotes no_auto_pushd +builtin setopt extended_glob typeset_silent no_short_loops rc_quotes no_auto_pushd -integer ret=0 +typeset -i ret=0 # The directory in which the database is stored. if [[ ! -d ${ZPFX}/share ]]; then diff --git a/functions/.zsh-prepare-zoxide b/functions/.zsh-prepare-zoxide index 574330f..89f7c6c 100644 --- a/functions/.zsh-prepare-zoxide +++ b/functions/.zsh-prepare-zoxide @@ -1,4 +1,3 @@ -#autoload # -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- # vim: ft=zsh sw=2 ts=2 et # @@ -9,10 +8,9 @@ # Zsh Plugin Standard # https://wiki.zshell.dev/community/zsh_plugin_standard#standard-recommended-options builtin emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace} -builtin setopt extended_glob warn_create_global typeset_silent \ -no_short_loops rc_quotes no_auto_pushd +builtin setopt extended_glob typeset_silent no_short_loops rc_quotes no_auto_pushd -integer ret=0 +typeset -i ret=0 # Check dependencies typeset -a dependencies diff --git a/functions/@zsh-eval-cache b/functions/@zsh-eval-cache index 73f6eae..8dda166 100644 --- a/functions/@zsh-eval-cache +++ b/functions/@zsh-eval-cache @@ -2,13 +2,11 @@ # vim: ft=zsh sw=2 ts=2 et builtin emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace} -builtin setopt extended_glob warn_create_global typeset_silent \ - no_short_loops rc_quotes no_auto_pushd local_options +builtin setopt extended_glob typeset_silent no_short_loops rc_quotes no_auto_pushd local_options typeset -gA ZEC typeset -i ret=0 typeset -a input_array=( "$@" ) -typeset -ga chpwd_functions __zoxide_z_prefix : ${ZEC[CACHE_DIR]:=${ZEC[CACHE_DIR]:-${Plugins[ZSH_ZOXIDE]}/._zoxide}} : ${ZEC[DISABLED]:=${ZEC[DISABLED]:-0}} @@ -16,7 +14,7 @@ typeset -ga chpwd_functions __zoxide_z_prefix : ${ZEC[MAX]:=${ZEC[MAX]:-1000}} ZEC[CACHE_DIR]=${~ZEC[CACHE_DIR]} -[[ -d $ZEC[CACHE_DIR] ]] || command mkdir -p $ZEC[CACHE_DIR] &> /dev/null +[[ -d ${ZEC[CACHE_DIR]} ]] || command mkdir -p ${ZEC[CACHE_DIR]} &> /dev/null if (( $+commands[md5] )); then ZEC[MD5_HASH]=$(md5 <<< $input_array) @@ -32,7 +30,7 @@ fi if (( ZEC[DISABLED] )); then (( ZEC[DEBUG] )) && builtin print -Pr "@zsh-eval-cache: disabled" eval "$( ${(@)input_array} )"; ret=$? -elif [[ -s $ZEC[CACHE] ]]; then +elif [[ -s ${ZEC[CACHE]} ]]; then [[ -f $ZEC[COUNT] ]] || { builtin print 1 > ${ZEC[COUNT]}; } 2> /dev/null typeset count=$(<${ZEC[COUNT]}) @@ -49,10 +47,10 @@ else (( ZEC[DEBUG] )) && builtin print -Pr "@zsh-eval-cache: miss" - ${(@)input_array} >! $ZEC[CACHE] && zcompile -U $ZEC[CACHE] && builtin source $ZEC[CACHE]; ret=$? + ${(@)input_array} >! ${ZEC[CACHE]} && zcompile -U ${ZEC[CACHE]} && builtin source ${ZEC[CACHE]}; ret=$? fi -(( count > ZEC[MAX] )) && command rm -rf $ZEC[CACHE_DIR] &> /dev/null +(( count > ZEC[MAX] )) && command rm -rf ${ZEC[CACHE_DIR]} &> /dev/null (( ret )) && builtin print -Pr "@zsh-eval-cache: failed to initialize zoxide" >&2