Created
October 20, 2021 18:29
-
-
Save IlyaOrson/2019f47e9f91ba11e18950a9be3ccd06 to your computer and use it in GitHub Desktop.
Powershell mode in Julia's REPL
This file contains hidden or 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
# 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