# Shell mode causes issues on windows

**URL:** <https://discourse.julialang.org/t/shell-mode-causes-issues-on-windows/51134>\
**Category:** New to Julia\
**Tags:** shell\
**Created:** [December 2, 2020, 5:54pm UTC](https://discourse.julialang.org/t/shell-mode-causes-issues-on-windows/51134 "2020-12-02T17:54:37Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![IlyaOrson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ilyaorson/32/1681_2.png) [@IlyaOrson](https://discourse.julialang.org/u/IlyaOrson)\
**Post date:** [October 19, 2021, 5:27pm UTC](https://discourse.julialang.org/t/shell-mode-causes-issues-on-windows/51134/8 "2021-10-19T17:27:01Z")

</div>

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](https://github.com/JuliaLang/julia/pull/31490). It could be usefull until the proper fix lands.

```julia
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.

```nohighlight
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](https://github.com/MasonProtter/ReplMaker.jl#creating-a-repl-mode-at-startup-time).

---

_[View the full topic](https://discourse.julialang.org/t/shell-mode-causes-issues-on-windows/51134)._
