Skip to content

Instantly share code, notes, and snippets.

@IlyaOrson
Created October 20, 2021 18:29
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 IlyaOrson/2019f47e9f91ba11e18950a9be3ccd06 to your computer and use it in GitHub Desktop.
Save IlyaOrson/2019f47e9f91ba11e18950a9be3ccd06 to your computer and use it in GitHub Desktop.
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