Skip to content

Commit

Permalink
chore: Refactor zsh function options setting for consistency
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ss-o committed Feb 24, 2024
1 parent fdeb4cf commit 4c0e1df
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
5 changes: 2 additions & 3 deletions functions/.zi-prepare-zoxide
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions functions/.zsh-prepare-zoxide
Original file line number Diff line number Diff line change
@@ -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
#
Expand All @@ -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
Expand Down
12 changes: 5 additions & 7 deletions functions/@zsh-eval-cache
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
# 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}}
: ${ZEC[DEBUG]:=${ZEC[DEBUG]:-0}}
: ${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)
Expand All @@ -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]})
Expand All @@ -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

Expand Down

0 comments on commit 4c0e1df

Please sign in to comment.