Skip to content

Commit

Permalink
Introduce read only mode for dir variables 📕
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrieanKhisbe committed Oct 15, 2020
1 parent cfe4abe commit 577484c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion diractions.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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\""
Expand Down
21 changes: 21 additions & 0 deletions test/diraction_integration_shpec.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 577484c

Please sign in to comment.