This workaround uses ReplMaker.jl
to register a powershell>
mode in the REPL activated with }
. It handles the cd
command separately as in the proposed fix. It could be usefull until the proper fix lands.
using ReplMaker
function _pass_to_powershell(s)
# adapted from https://github.com/JuliaLang/julia/pull/31490
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(
_pass_to_powershell;
prompt_text = "powershell> ",
prompt_color = :cyan,
start_key = '}',
mode_name = "powershell_mode"
)
PowerShell comes with many aliases similar to bash, so the basic stuff works as expected.
julia> # type } to activate
powershell> Get-Alias
CommandType Name Version Source
----------- ---- ------- ------
Alias ? -> Where-Object
Alias % -> ForEach-Object
Alias ac -> Add-Content
Alias cat -> Get-Content
Alias cd -> Set-Location <--- this one is handled separately
Alias chdir -> Set-Location
Alias clc -> Clear-Content
Alias clear -> Clear-Host
Alias clhy -> Clear-History
Alias cli -> Clear-Item
Alias clp -> Clear-ItemProperty
Alias cls -> Clear-Host
Alias clv -> Clear-Variable
Alias cnsn -> Connect-PSSession
Alias compare -> Compare-Object
Alias conda -> Invoke-Conda 0.0 Conda
Alias copy -> Copy-Item
Alias cp -> Copy-Item
...
You can make it always available with the startup config file.