Last active
August 9, 2020 19:30
-
-
Save zyth0s/d432f001294667c55f7c42599ac0b9d5 to your computer and use it in GitHub Desktop.
Run Julia scripts from the interpreter with a macro (like an IPython magic command).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run Julia files from the REPL with the following syntax: | |
# > @run "../file.jl" <-- String (any rel/abs path) [si autocompletion] | |
# > @run file.jl <-- Expr (no ./ or ../ etc) [no autocompletion] | |
# > @run file <-- Symbol (no ./ or ../ etc) [no autocompletion] | |
macro run(filename) | |
if filename isa String | |
include(filename) | |
elseif filename isa Expr | |
include(join([string(filename.args[1]), | |
string(filename.args[2].value)], | |
".")) | |
elseif filename isa Symbol | |
include(string(filename) * ".jl") | |
else | |
error("The filepath must be a string.") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment