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
pkgs = ["Revise", "OhMyREPL"]
for pkg in pkgs
if Base.find_package(pkg) === nothing
# Update all packages, but do so in a worker process
pkg_worker = Distributed.addprocs(1)[end]
redirect_stdout() # silence everything, only on this worker
# now remove this worker and say we are done
printstyled("\n Pkg.update() complete \n"; color=:light_black)
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?
ENV["EDITOR"] = "atom"
const PLOTS_DEFAULTS = Dict(:theme => :wong)
@eval using Revise
# Turn on Revise's automatic-evaluation behavior
@eval using Rebugger
# Activate Rebugger's key bindings
@warn "Could not load startup packages."
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.
Yes, that’s possible by adding this to your startup.jl file
open(joinpath(homedir(),".julia","config","dir"),"r") do f
atexit(() -> begin
open(joinpath(homedir(),".julia","config","dir"),"w") do f
Does anyone know a decent way to work in a call to load precompiled modules (from package compiler) in the startup file? I.e. Start Julia within Julia with the precompiled modules from an image, but only doing this once.
I’d been a Julia user for less than a week before the REPL default format for floats drove me insane. So I put this Google search result in my startup.jl and became less insane. I had no idea what these four lines were really doing for several months after that, but they solved my problem.
Here is my updated one.
I gave up on updating all packages
# Disable updating registry on `add` (still runs on `up`), as it is slow
using Pkg: Pkg
Pkg.UPDATED_REGISTRY_THIS_SESSION = true
# use more colors for displaying Pkg conflicts
if isdefined(Pkg.Resolve, :CONFLICT_COLORS)
append!(Pkg.Resolve.CONFLICT_COLORS, [21:51; 55:119; 124:142; 160:184; 196:220])
# Setup Revise.jl
atreplinit() do repl
@eval using Revise
println("Error starting Revise $err")
Other than starting Revise and setting the editor I have a macro for partial application:
count = 0
for arg in expr.args
count += count_(arg)
convert(Int64,expr == :_)::Int64
for i in eachindex(expr.args)
if (sym == :_) & (!isempty(slist))
sym = popfirst!(slist)
fname = gensym()
symnames = [gensym() for i in 1:My_partial.count_(expr)]
args = copy(symnames)
(quote $fname($(args...)) = $expr end)
and the obligatory (for me) definitions to stack array of arrays to a matrix:
I set the environment variable for my editor in ~/.bashrc, and I generally launch Julia from bash, so I don’t use startup.jl to set environment variables like this.
But I think the name code is absolutely absurd, and it’s not on my PATH. I use the symlink vscode, and so my startup.jl contains:
# `vscode` is my symlink to the Visual Studio Code executable.
# Tell Julia how to open files with `vscode`, modified from: `InteractiveUtils/src/editless.jl`
using InteractiveUtils # `using` instead of `import` due to https://github.com/JuliaLang/julia/issues/40192
InteractiveUtils.define_editor(["vscode"]) do cmd, path, line
`$cmd -g $path:$line`
Along the same lines of making things prettier, I keep a pretty_rational function in my startup to change the default printing of Rational numbers when I want to. I’m not brave enough to make it my default setting, though.
@eval Base.show(io::IO, x::Rational) =
x.den==1 ? print(io, x.num) : print(io, "$(x.num)/$(x.den)")