Skip to content

Commit

Permalink
Do not export dir variables anymore (opt-in variable) 📦
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrieanKhisbe committed Oct 15, 2020
1 parent dcebf77 commit cfe4abe
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
9 changes: 7 additions & 2 deletions diractions.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
39 changes: 35 additions & 4 deletions test/diraction_integration_shpec.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cfe4abe

Please sign in to comment.