Last active
March 1, 2023 21:07
-
-
Save pbouffard/d788bc8c5bd8e06388825105dcd9ad8a to your computer and use it in GitHub Desktop.
My latest startup.jl
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
# # Kwong book | |
function subtypetree(roottype::Type, level = 1, indent = 4) | |
level == 1 && println(roottype) | |
for s in subtypes(roottype) | |
println(join(fill(" ", level * indent)) * string(s)) | |
subtypetree(s, level + 1, indent) | |
end | |
end | |
# using Eyeball # doesn't work within atreplinit()? | |
@info "Running startup.jl at $(@__FILE__)..." | |
import REPL | |
import Pkg | |
import Logging | |
_in_vscode() = Logging.current_logger() isa VSCodeServer.VSCodeLogger | |
function _fixbrackets() | |
@async begin | |
n = 0 | |
while n < 10 && !isdefined(Base, :active_repl) | |
sleep(1) | |
n += 1 | |
end | |
if !isdefined(Base, :active_repl) | |
@warn "Couldn't do OhMyREPL fix" | |
else | |
OhMyREPL.Prompt.insert_keybindings() | |
end | |
end | |
end | |
# | |
function _addrevise() | |
Pkg.add("Revise") | |
end | |
atreplinit() do repl | |
# Add current environment to normal REPL prompt | |
# must do this before importing OhMyREPL or it will clobber OhMyREPL | |
repl.interface = REPL.setup_interface(repl) | |
repl.interface.modes[1].prompt = () -> Pkg.REPLMode.promptf()[1:end-6] * " julia> " | |
function _maybeimport(pkgsym) | |
pkgstr = String(pkgsym) | |
try | |
@eval using $pkgsym | |
@info "Imported $pkgstr" | |
catch | |
@info "Didn't import $pkgstr, not available in this environment?" | |
end | |
end | |
_maybeimport.([ | |
:Revise, | |
:OhMyREPL, | |
]) | |
# this actually doesn't work.. | |
# https://discourse.julialang.org/t/check-if-running-in-vs-code-inside-startup-jl/95346 | |
# if _in_vscode() | |
# @info "Running in VS Code integrated terminal" | |
# else | |
# _maybeimport(:TerminalExtensions) | |
# end | |
# if _canimport("TerminalExtensions"); @eval using TerminalExtensions; end | |
# ( | |
# try | |
# @info "using TerminalExtensions..." | |
# @eval using TerminalExtensions | |
# catch e | |
# @warn "Error importing TerminalExtensions" exception=(e, catch_backtrace()) | |
# end | |
# ) | |
# Base.require(:TerminalExtensions) | |
# try | |
# @eval using Eyeball | |
# catch e | |
# @warn "Error initializing Eyeball" exception=(e, catch_backtrace()) | |
# end | |
# try | |
# @info "using Revise..." | |
# @eval using Revise | |
# catch e | |
# @warn "Error initializing Revise" exception=(e, catch_backtrace()) | |
# end | |
# input_prompt() = "hello" | |
# try | |
# @info "using OhMyREPL..." | |
# @eval using OhMyREPL | |
# @eval colorscheme!("GitHubLight") | |
# catch e | |
# @warn "error while importing OhMyREPL" e | |
# end | |
# try | |
# @eval using InteractiveCodeSearch | |
# catch e | |
# @warn "error while importing InteractiveCodeSearch" e | |
# end | |
@info "Sysimage in use is $(unsafe_string(Base.JLOptions().image_file))" | |
@info "Run _fixbrackets() manually to fix https://github.com/KristofferC/OhMyREPL.jl/issues/166" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment