What is in your startup.jl?


#1

I now have a fair bit in my startup.jl
I am wondering if anyone else also has cool things.


What mine does:

  • Load Revise and OhMyRepl.
    - installing them if they are not already installed
  • Update all packages
    - It does this in a silenced worker processes, so as not to waste time
    - it is supposed to remove that worker afterwards but I am not sure that it does
    - My packages are now evergreen, like a webbrowser.

I used to do stuff with setting stacktrace colors to not uses bold, because bold was not differentiable from white on my old terminal emulator,
but it is on my new setup so I don’t have it anymore


# Setup OhMyREPL and Revise
import Pkg
let
    pkgs = ["Revise", "OhMyREPL"]
    for pkg in pkgs
    if Base.find_package(pkg) === nothing
        Pkg.add(pkg)
    end
    end
end

using Revise
using OhMyREPL


# Update all packages, but do so in a worker process
import Distributed
let
    pkg_worker = Distributed.addprocs(1)[end]
    Distributed.remotecall(pkg_worker) do
        redirect_stdout() # silence everything, only on this worker
        Pkg.update()

        # now remove this worker and say we are done
        remotecall(1) do
            eval(quote
                Distributed.rmprocs($(pkg_worker))
                printstyled("\n Pkg.update() complete \n"; color=:light_black)
            end)
        end
    end
end

#2

Here is mine

ENV["JULIA_NUM_THREADS"] = 8
ENV["EDITOR"] = "vim"
ENV["PYTHON"] = "python"
#using Reduce
#@force using Reduce.Algebra
#using OhMyREPL
#using Revise
using BenchmarkTools, SyntaxTree

cdpkg(pkg) = cd(dirname(Base.find_package(string(pkg))))

macro cdpkg(pkg)
    cdpkg(pkg)
    return nothing
end

usually I have some of my startup packages commented and disabled, such as OhMyREPL and Revise, since I want the REPL to startup as fast as possible, I enable and uncomment them only sometimes.

The macro and cdpkg function are used to cd to a package without having to import it.


#3

That’s very nice @oxinabox. I definitely would not want all dependencies of projects I’m working on to update every time I start Julia. It’s great for the main project (labelled (1.0) but no project I’m developing seriously.

I thought you had to do some more eval magic for Revise and Rebugger to really do their thing?
Mine is

ENV["EDITOR"] = "atom"
const PLOTS_DEFAULTS = Dict(:theme => :wong)

 try
     @eval using Revise
     # Turn on Revise's automatic-evaluation behavior
     Revise.async_steal_repl_backend()

     @eval using Rebugger
     # Activate Rebugger's key bindings
     atreplinit(Rebugger.repl_init)

     using OhMyREPL
     colorscheme!("Monokai24bit")

 catch err
     @warn "Could not load startup packages."
 end

 showall(x) = show(stdout, "text/plain", x)

The showall function is particularly nice when you things like keys(somedict) to get a list of the keys to use etc.
The :wong theme is nicer than Plots’s default IMHO.


#4

Thanks for sharing these tips !
BTW is it possible to configure startup.jl to make an automatic cd() to the last used directory ?


#5

Yes, that’s possible by adding this to your startup.jl file

try
    open(joinpath(homedir(),".julia","config","dir"),"r") do f
        cd(read(f,String))
    end
catch
end
atexit(() -> begin
    try
        open(joinpath(homedir(),".julia","config","dir"),"w") do f
            write(f,pwd())
        end
    catch
    end
end)

#6

Thank you very much… It’s added !