Skip to content

Instantly share code, notes, and snippets.

@femtomc
Last active May 13, 2020 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save femtomc/1e20c230846df6175d652d11e7cc847d to your computer and use it in GitHub Desktop.
Save femtomc/1e20c230846df6175d652d11e7cc847d to your computer and use it in GitHub Desktop.
A command line tool for watching Julia src and executing arbitrary files.
#!/usr/bin/env julia
# Check if Revise is installed.
using Pkg
try
Pkg.status("Revise")
catch e
error("\n\033[0;31mRevise not installed to your global environment. Please install Revise.\033[0m\n\033[0;32mUse 'using Pkg; Pkg.add(\"Revise\")' at REPL.\033[0m\n")
end
using Revise
# Activate env.
Pkg.activate(".")
# Works on *nix systems.
cmd = `find -name '*.jl'`
# Filenames get passed in as CL args.
include_filenames = Base.ARGS
# Uses Revise to watch for all updates to Julia files in repo.
entr(split(read(cmd, String), "\n")[1:end-1]) do
if include_filenames[1] == "test"
try
Pkg.test()
catch e
println("\n\033[0;31mCaught error in test.\033[0m\n")
println(e)
end
else
map(include_filenames) do path
try
include(path)
catch e
println("\n\033[0;31mCaught error in $(path).\033[0m\n")
for (exc, bt) in Base.catch_stack()
showerror(stdout, exc, bt)
println()
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment