diff --git a/diractions.plugin.zsh b/diractions.plugin.zsh index 58f9771..f3e8cd5 100644 --- a/diractions.plugin.zsh +++ b/diractions.plugin.zsh @@ -63,6 +63,7 @@ declare -gA _DIRACTION_HELP -set-default DIRACTION_DEF_FILE "$HOME/.diractions" # §maybe rename to config file -set-default DIRACTION_BROWSER # §todo: update -set-default DIRACTION_AUTO_CONFIG true +-set-default DIRACTION_EXPORT_VARIABLES false # -- if [[ -z $DIRACTION_DISPATCH_WHITELIST ]]; then @@ -154,8 +155,12 @@ function diraction-create() { # create variable if not already bound if [ -z "${(P)var}" ] ; then # ¤note: déréférencement de variable: ${(P)var} - export $var="$(eval echo "$dir")" - # §see: keep export? + local value="$(eval echo "$dir")" + if [[ "$DIRACTION_EXPORT_VARIABLES" =~ ^(true|yes|y)$ ]] ; then + export $var="$value" + else + eval "$var=${(q)value}" + fi # §maybe: readonly probably better?? (maybe not: could not unset then) fi # create an alias: call to the _diraction-dispach function with directory as argument diff --git a/test/diraction_integration_shpec.zsh b/test/diraction_integration_shpec.zsh index d014313..1249b10 100755 --- a/test/diraction_integration_shpec.zsh +++ b/test/diraction_integration_shpec.zsh @@ -13,16 +13,47 @@ describe "Integration Diraction" source $plugin diraction-batch-create << "DIR" - tmp /tmp + dir-tmp /tmp DIR - tmp - pwd - tmp + echo \$_dir_tmp + dir-tmp - pwd + dir-tmp pwd + + zsh << SUB_SHELL + echo dir-tmp:\\\$_dir_tmp: +SUB_SHELL +BASIC_SCRIPT +)" + _status=$? + assert equal $_status 0 + + assert equal "$output" "/tmp\n/tmp\n/tmp\ndir-tmp::" + end + + it "basic script with exports" + output="$(zsh 2>&1 << BASIC_SCRIPT + set -e + DIRACTION_AUTO_CONFIG=false + DIRACTION_EXPORT_VARIABLES=true + source $plugin + + diraction-batch-create << "DIR" + dir-tmp /tmp +DIR + echo \$_dir_tmp + dir-tmp - pwd + dir-tmp + pwd + + zsh << SUB_SHELL + echo dir-tmp:\\\$_dir_tmp: +SUB_SHELL BASIC_SCRIPT )" _status=$? assert equal $_status 0 - assert equal $output "/tmp\n/tmp" + assert equal "$output" "/tmp\n/tmp\n/tmp\ndir-tmp:/tmp:" end end