Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Powershell mode in Julia's REPL
# may go to startup file to make it always available
# https://github.com/MasonProtter/ReplMaker.jl#creating-a-repl-mode-at-startup-time
using ReplMaker
function powershell_command(s)
# adapted from https://github.com/JuliaLang/julia/blob/7a3fff1ea76b62b7681dbed5cc2dee43c64d9a51/base/client.jl#L45
args = String.(split(s))
if args[1] == "cd"
new_oldpwd = pwd()
if length(args) > 2
throw(ArgumentError("cd method only takes one argument"))
elseif length(args) == 2
dir = args[2]
if dir == "-"
if !haskey(ENV, "OLDPWD")
error("cd: OLDPWD not set")
end
cd(ENV["OLDPWD"])
else
cd(dir)
end
else
cd()
end
ENV["OLDPWD"] = new_oldpwd
println(pwd())
else
# command = Cmd(["powershell", s...]) # version 5
command = Cmd(["pwsh", "-Command", args...]) # version 7
command |> ignorestatus |> run
end
end
initrepl(
powershell_command;
prompt_text = "powershell> ",
prompt_color = :cyan,
start_key = ';', # this choice overwrites standard shell mode
mode_name = "powershell_mode"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment