diff --git a/diractions.plugin.zsh b/diractions.plugin.zsh index f3e8cd5..162b7bf 100644 --- a/diractions.plugin.zsh +++ b/diractions.plugin.zsh @@ -64,6 +64,7 @@ declare -gA _DIRACTION_HELP -set-default DIRACTION_BROWSER # §todo: update -set-default DIRACTION_AUTO_CONFIG true -set-default DIRACTION_EXPORT_VARIABLES false +-set-default DIRACTION_READONLY_VARIABLES false # §todo: experiment, and maybe make it default (or maybe not: could not unset then) # -- if [[ -z $DIRACTION_DISPATCH_WHITELIST ]]; then @@ -161,7 +162,9 @@ function diraction-create() { else eval "$var=${(q)value}" fi - # §maybe: readonly probably better?? (maybe not: could not unset then) + if [[ "$DIRACTION_READONLY_VARIABLES" =~ ^(true|yes|y)$ ]] ; then + readonly $var + fi fi # create an alias: call to the _diraction-dispach function with directory as argument alias "$alias"="_diraction-dispatch \"$dir\"" diff --git a/test/diraction_integration_shpec.zsh b/test/diraction_integration_shpec.zsh index 1249b10..4b954e4 100755 --- a/test/diraction_integration_shpec.zsh +++ b/test/diraction_integration_shpec.zsh @@ -56,4 +56,25 @@ BASIC_SCRIPT assert equal "$output" "/tmp\n/tmp\n/tmp\ndir-tmp:/tmp:" end + + it "basic script with readonly" + output="$(zsh 2>&1 << BASIC_SCRIPT + set -e + DIRACTION_AUTO_CONFIG=false + DIRACTION_READONLY_VARIABLES=true + source $plugin + + diraction-batch-create << "DIR" + ro-dir-tmp /tmp +DIR + echo \$_ro_dir_tmp + readonly _ro_dir_tmp + _ro_dir_tmp="sorry you can't" +BASIC_SCRIPT +)" + _status=$? + assert equal $_status 1 + + assert equal "$output" "/tmp\nzsh: read-only variable: _ro_dir_tmp" + end end