# 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:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rockdeldiablo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rockdeldiablo/32/19833_2.png) [@Rockdeldiablo](https://discourse.julialang.org/u/Rockdeldiablo)\
**Post date:** [December 2, 2020, 5:54pm UTC](https://discourse.julialang.org/t/shell-mode-causes-issues-on-windows/51134/1 "2020-12-02T17:54:37Z")

</div>

Hi everybody, i just installed julia and i am still dealing with various settings,packages and errors.  
i have recently learned about julia shell mode and I was trying some standard commands with cygwin and cmd. everything works up to the point where i want to quit the shell mode. The backspace shortcut doesn’t work and the only command that i can use to quit is exit which brings me to a corrupted julia terminal  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/f/4f36e3748edebe73f37e3be8c524b0f267092482.png)

how can i solve this issue? thank you

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [December 2, 2020, 6:01pm UTC](https://discourse.julialang.org/t/shell-mode-causes-issues-on-windows/51134/2 "2020-12-02T18:01:48Z")

</div>

This thread may be of some use: [Getting Julia REPL working in Windows git/bash](https://discourse.julialang.org/t/getting-julia-repl-working-in-windows-git-bash/50715)

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [December 2, 2020, 6:17pm UTC](https://discourse.julialang.org/t/shell-mode-causes-issues-on-windows/51134/3 "2020-12-02T18:17:26Z")

</div>

The workaround is to use the following script command on the REPL shell mode:

```julia
shell> cmd /C c:\\cygwin64\\bin\\bash -i -l

oheil@PC ~
$

```

I can only speculate: Julia is spawning commands directly using exec(), without any underlying terminal, not like e.g. running a remote command using ssh on linux/unix where the command is run with a shell (/bin/sh) as the execution part. This difference (missing terminal) is perhaps the cause for this weird behaviour above.

The workaround uses windows cmd to run the cygwin bash. Options -i -l are there to have have bash as a interactive login shell (e.g. to have typical commands like ls in your path).

---

<div class="post-metadata">

**Author:** ![Rockdeldiablo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rockdeldiablo/32/19833_2.png) [@Rockdeldiablo](https://discourse.julialang.org/u/Rockdeldiablo)\
**Post date:** [December 16, 2020, 7:32am UTC](https://discourse.julialang.org/t/shell-mode-causes-issues-on-windows/51134/5 "2020-12-16T07:32:26Z")

</div>

Hi,i have been using this trick for a while and it actually works well, but i was wondering if there is a way to implement a shortcut instead of writing the whole command. Can i set an alias in julia shell mode?

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [December 16, 2020, 12:19pm UTC](https://discourse.julialang.org/t/shell-mode-causes-issues-on-windows/51134/6 "2020-12-16T12:19:19Z")

</div>

A file, e.g. cygwinbash.bat, somewhere in a folder which is in the PATH with

```julia
c:\\cygwin64\\bin\\bash -i -l

```

works well, except that the Julia window title is changed permanently to the bash prompt, which is in my case a ~.

Explicitly using `cmd` isn’t necessary here, because a .bat file is running in a cmd shell.

The change of the window title can be avoided by setting environment variable `PS1` (and/or `PS2`,… not tested) to something without the escape sequences

```julia
\e]0;

```

or

```julia
\033]0;

```

For my cygwin `PS1` is set in

```julia
c:\cygwin64\etc\bash.bashrc

```

and editing it there (removing above esc sequenced from the beginning of the PS1 string) solved this (minor) issue, too. Doing this, will prevent change of window title for all (interactive) cygwin bash windows. There are options to use a specific resource file or none at startup, but I stopped investigating further. These details are easily found in the man page of `bash` or on the web.

---

<div class="post-metadata">

**Author:** ![devel-chm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devel-chm/32/3572_2.png) [@devel-chm](https://discourse.julialang.org/u/devel-chm)\
**Post date:** [June 11, 2021, 4:56pm UTC](https://discourse.julialang.org/t/shell-mode-causes-issues-on-windows/51134/7 "2021-06-11T16:56:29Z")

</div>

This appears to be fixed in Julia 1.6.1

---

<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).
