Skip to content

Instantly share code, notes, and snippets.

@zyth0s
Last active August 9, 2020 19:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zyth0s/d432f001294667c55f7c42599ac0b9d5 to your computer and use it in GitHub Desktop.
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).
# 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