Aliases should not be dropped at the end of the scope
Currently, aliases are dropped at the end of the scope, and cannot be effectively defined in a for
-loop or in an if
statement.
This is also true even if another script is sourced within the loop/if statement.
Ideally, aliases should act as export
variables, and continue to be defined even after the end of the scope.
Importance
Suppose in the initrc
file the user wants to iterate over all .ion
scripts in another folder and source them all.
This would capture all export
variables, but will not save any aliases. Not only this behavior is inconvinient, it is also unclear.
Simple example
for _ in 0..1
export TEST_VAR = "Var is defined"
alias test_alias = echo "Alias is defined"
end
echo $TEST_VAR
test_alias
Would produce the following output (both ion script.ion
and source script.ion
):
Var is defined
ion: pipeline execution error: command not found: test_alias
Another example
Suppose with have two scripts: inner.ion
export TEST_VAR = "Var is defined"
alias test_alias = echo "Alias is defined"
and main.ion
if true
source inner.ion
echo "Test inside `if`"
echo $TEST_VAR
test_alias
end
echo -e "\nTest outside `if`"
echo $TEST_VAR
test_alias
Will produce the following output (both ion main.ion
and source main.ion
):
Test inside `if`
Var is defined
Alias is defined
Test outside `if`
Var is defined
ion: pipeline execution error: command not found: test_alias
Comparison with other shells
for _ in 0; do
export TEST_VAR="Var is defined"
alias test_alias="echo Alias is defined"
done
echo $TEST_VAR
test_alias
will have the following behaviour in other shells:
- Successful in
sh
, - Successful in
bash
, but only if ran assource
, - Successful in
zsh
.