Skip to content

Commit 627e420

Browse files
authored
fix/issue/#37 (#38)
correctly assign parameters Signed-off-by: Sall <sall@w-ss.io>
1 parent 94fbe40 commit 627e420

File tree

4 files changed

+73
-36
lines changed

4 files changed

+73
-36
lines changed

.trunk/configs/.yamllint.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
rules:
2+
quoted-strings:
3+
required: only-when-needed
4+
extra-allowed: ["{|}"]
5+
empty-values:
6+
forbid-in-block-mappings: true
7+
forbid-in-flow-mappings: true
8+
key-duplicates: {}
9+
octal-values:
10+
forbid-implicit-octal: true

.trunk/trunk.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
version: 0.1
22
cli:
3-
version: 1.5.1
3+
version: 1.6.1
44
plugins:
55
sources:
66
- id: trunk
7-
ref: v0.0.12
7+
ref: v0.0.13
88
uri: https://github.com/trunk-io/plugins
99
lint:
10+
disabled:
11+
- yamllint
1012
enabled:
1113
- actionlint@1.6.23
1214
- git-diff-check
1315
- prettier@2.8.4
1416
- markdownlint@0.33.0
15-
- gitleaks@8.15.3
17+
- gitleaks@8.16.1
1618
runtimes:
1719
enabled:
18-
- go@1.18.3
20+
- python@3.10.8
21+
- go@1.19.5
1922
- node@18.12.1
2023
actions:
2124
enabled:

docs/README.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,30 @@
1515

1616
## The <samp>[`ajeetdsouza/zoxide`](https://github.com/ajeetdsouza/zoxide)</samp>
1717

18-
### Options
18+
### Environment variables
1919

20-
Export the following environment variables to change the default behavior:
20+
| Variable | Description | Default |
21+
| -------------------------- | ----------------------------------------- | --------------------------------------- |
22+
| <kbd>\_ZO_CMD_PREFIX</kbd> | Set variable to preferred prefix | Zi: <kbd>x</kbd>, other: <kbd>z</kbd> |
23+
| <kbd>\_ZO_DATA_DIR</kbd> | Directory in which the database is stored | Zi: <kbd>$ZPFX/share</kbd>, other: none |
2124

22-
| Variable | Description | Default |
23-
| ----------------------- | ------------------------------------------------------- | --------------- |
24-
| <kbd>ZEC_DISABLED</kbd> | Disable eval-caching | <kbd>0</kbd> |
25-
| <kbd>ZEC_DEBUG</kbd> | Enable debug mode for eval-caching | <kbd>0</kbd> |
26-
| <kbd>ZEC_MAX</kbd> | Maximum number to load from cache (until force refresh) | <kbd>1000</kbd> |
25+
All environment variables: [ajeetdsouza/zoxide#environment-variables](https://github.com/ajeetdsouza/zoxide#environment-variables)
26+
27+
#### Eval-cache options
28+
29+
Before setting the environment variables, you must declare the associative array:
30+
31+
```shell
32+
typeset -A ZEC
33+
```
34+
35+
Set the following environment variables to change the default behavior:
36+
37+
| Variable | Description | Default |
38+
| ------------------------ | ------------------------------------------------------- | --------------- |
39+
| <kbd>ZEC[DISABLED]</kbd> | Disable eval-caching | <kbd>0</kbd> |
40+
| <kbd>ZEC[DEBUG]</kbd> | Enable debug mode for eval-caching | <kbd>0</kbd> |
41+
| <kbd>ZEC[MAX]</kbd> | Maximum number to load from cache (until force refresh) | <kbd>1000</kbd> |
2742

2843
> Eval-cache files are stored in <kbd><samp>${Plugins[ZSH_ZOXIDE]}/.\_zoxide/\*</samp></kbd> directory.
2944

functions/@zsh-eval-cache

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,58 @@
22
# vim: ft=zsh sw=2 ts=2 et
33

44
builtin emulate -L zsh ${=${options[xtrace]:#off}:+-o xtrace}
5-
builtin setopt extended_glob warn_create_global typeset_silent no_short_loops rc_quotes no_auto_pushd
5+
builtin setopt extended_glob warn_create_global typeset_silent \
6+
no_short_loops rc_quotes no_auto_pushd local_options
67

7-
local -a input=( $@ ) chpwd_functions; integer count ret=0
8-
local md5_hash zoxide_cache zoxide_cache_dir __zoxide_z_prefix
9-
local counter_file max=${ZEC_MAX:-1000}
8+
typeset -gA ZEC
9+
typeset -i count=0 ret=0
10+
typeset -a input_array=( "$@" )
11+
typeset -ga chpwd_functions __zoxide_z_prefix
1012

11-
md5_hash="no_hash"
12-
zoxide_cache_dir="${Plugins[ZSH_ZOXIDE]}/._zoxide"
13+
: ${ZEC[CACHE_DIR]:=${ZEC[CACHE_DIR]:-${Plugins[ZSH_ZOXIDE]}/._zoxide}}
14+
: ${ZEC[MD5_HASH]:=${ZEC[MD5_HASH]:-no_hash}}
15+
: ${ZEC[DISABLED]:=${ZEC[DISABLED]:-0}}
16+
: ${ZEC[DEBUG]:=${ZEC[DEBUG]:-0}}
17+
: ${ZEC[MAX]:=${ZEC[MAX]:-1000}}
1318

14-
[[ -d $zoxide_cache_dir ]] || command mkdir -p $zoxide_cache_dir &> /dev/null
19+
ZEC[CACHE_DIR]=${~ZEC[CACHE_DIR]}
20+
21+
: ${ZEC[CACHE]:=${ZEC[CACHE]:-${ZEC[CACHE_DIR]}/${ZEC[MD5_HASH]}.zsh}}
22+
: ${ZEC[COUNT]:=${ZEC[COUNT]:-${ZEC[CACHE_DIR]}/${ZEC[MD5_HASH]}.txt}}
23+
24+
[[ -d $ZEC[CACHE_DIR] ]] || command mkdir -p $ZEC[CACHE_DIR] &> /dev/null
1525

1626
if (( $+commands[md5] )); then
17-
md5_hash=$(md5 <<< $input)
27+
ZEC[MD5_HASH]=$(md5 <<< $input_array)
1828
elif (( $+commands[md5sum] )); then
19-
md5_hash=$(md5sum <<< $input | awk '{ print $1 }')
29+
ZEC[MD5_HASH]=$(md5sum <<< $input_array | awk '{ print $1 }')
2030
else
2131
print "@zsh-eval-cache: md5 program not found"; return 1
2232
fi
2333

24-
zoxide_cache="${zoxide_cache_dir}/${md5_hash}.zsh"
25-
counter_file="${zoxide_cache_dir}/${md5_hash}.txt"
26-
27-
if (( ZEC_DISABLED )); then
28-
(( ZEC_DEBUG )) && builtin print -Pr "@zsh-eval-cache: disabled"
29-
eval "$( $input )"; ret=$?
30-
elif [[ -s $zoxide_cache ]]; then
31-
[[ -f $counter_file ]] || builtin print 1 > $counter_file 2> /dev/null
34+
if (( ZEC[DISABLED] )); then
35+
(( ZEC[DEBUG] )) && builtin print -Pr "@zsh-eval-cache: disabled"
36+
eval "$( ${(@)input_array} )"; ret=$?
37+
elif [[ -s $ZEC[CACHE] ]]; then
38+
[[ -f $ZEC[COUNT] ]] || builtin print 1 > $ZEC[COUNT] 2> /dev/null
3239

33-
count=$(<$counter_file) && (( count++ ))
34-
builtin print $count > $counter_file 2> /dev/null
40+
count=$(<$ZEC[COUNT]) && (( count++ ))
41+
builtin print $count > $ZEC[COUNT] 2> /dev/null
3542

36-
(( ZEC_DEBUG )) && builtin print -Pr "@zsh-eval-cache: hit $count"
43+
(( ZEC[DEBUG] )) && builtin print -Pr "@zsh-eval-cache: hit $count"
3744

38-
builtin source $zoxide_cache; ret=$?
45+
builtin source $ZEC[CACHE]; ret=$?
3946
else
40-
[[ -f $counter_file ]] || builtin print 1 > $counter_file 2> /dev/null
47+
[[ -f $ZEC[COUNT] ]] || builtin print 1 > $ZEC[COUNT] 2> /dev/null
4148

42-
(( ZEC_DEBUG )) && builtin print -Pr "@zsh-eval-cache: miss"
49+
(( ZEC[DEBUG] )) && builtin print -Pr "@zsh-eval-cache: miss"
4350

44-
$input > $zoxide_cache && zcompile -U $zoxide_cache && builtin source $zoxide_cache; ret=$?
51+
${(@)input_array} >! $ZEC[CACHE] && zcompile -U $ZEC[CACHE] && builtin source $ZEC[CACHE]; ret=$?
4552
fi
4653

47-
(( count > max )) && command rm -rf ${zoxide_cache_dir} &> /dev/null
54+
(( count > ZEC[MAX] )) && command rm -rf $ZEC[CACHE_DIR] &> /dev/null
55+
56+
(( ret )) && builtin print -Pr "@zsh-eval-cache: failed to initialize zoxide" >&2
4857

4958
(( ret )) && builtin print -Pr "@zsh-eval-cache: failed to initialize zoxide" >&2
5059

0 commit comments

Comments
 (0)