42

The terminal for Windows Subsystem for Linux (WSL) is fairly minimal. I have not used the terminal on Windows very much - I generally use Ubuntu or OSX - but I am surprised that the default terminal is so bare.

Is it possible to either:

  1. Connect a Windows terminal program to WSL or

  2. Launch the Ubuntu terminal program from WSL as an X window?

Kevin Bowen
  • 19,615
  • 55
  • 79
  • 83
  • As far as I know, Ubuntu is using the Windows terminal, which is why it's so lackluster (e.g., it can't even display bold fonts). But MS is working on making it better with Windows Terminal v1.0: https://github.com/microsoft/terminal/milestone/6 – SO_fix_the_vote_sorting_bug Apr 04 '20 at 11:00
  • Absolutely use Microsoft's improved Windows Terminal https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701?activetab=pivot:overviewtab – dlamblin Aug 04 '21 at 07:09

12 Answers12

28

I personally do the latter: use VcXsrv as my X server in multiple windows mode, then launch the xfce4-terminal (because gnome-terminal had visual issues that I didn't care to try to learn how to fix), and suddenly I have a competent terminal with font and color support.

I found I needed to add these to my bashrc...

export DISPLAY="localhost:0"
export TERM=xterm-256color

Do the fix from this reddit for dbus:

sudo sed -i 's$<listen>.*</listen>$<listen>tcp:host=localhost,port=0</listen>$' /etc/dbus-1/session.conf

I also installed compiz and I use the cbwin project to run windows programs from my xfce4-terminal shell.

I am very happy with this setup and use NeoVim + lots of native linux plugins even though my "for-work" machine must be Windows. :)

It is also possible to start an SSH server in Bash-on-Linux-on-Windows and then connect to it, say from MinTTY like from Cygwin.

PS: to make launching xfce4-terminal painless and without the extra bash cmd window, I wrote a program that does nothing but start the bash process with arguments to start xfce4-terminal without a console window. I did this in C# - basically use arguments "UseShellExecute" false and "CreateNoWindow" true. I then pinned that to my taskbar and it's almost seemless.

EDIT: The answer with VBScript is brilliant. Here's that same script, but a JScript version...

WScript.CreateObject("WScript.Shell").run('bash.exe -l -c "DISPLAY=:0.0 xfce4-terminal"', 0, false);
aikeru
  • 696
  • 1
    Selected answer because its comprehensive and it helped me find http://stackoverflow.com/a/39188790; I realized updating MobaXterm to >9.0 got me a decent terminal for WSL. – David LeBauer Sep 26 '16 at 04:31
  • If anyone is curious, here's the link to the reddit post from which the "fix from reddit" for dbus was lifted. – tel Jan 02 '18 at 22:00
  • @tel thanks! I actually did not know where that came from and have added the link... – aikeru Jan 04 '18 at 05:07
  • If the "visual issue you don't care to fix" is you can't see part of the prompt of directory or filenames the reason is they are dark blue. They aren't visible on the purple gnome-terminal background. The trick is to remap the color dark blue to turquoise and then it works fine. – WinEunuuchs2Unix Jun 14 '18 at 02:45
23

It took a little while to figure out all the implied steps in the other answers, so here's a step by step summary:

  1. On Windows, install VcXsrv or XMing.
  2. In Bash for Windows, install the terminal: sudo apt-get install xfce4-terminal.
  3. Add export DISPLAY=:0 to your .bashrc. (Adding it to .profile or .bash_profile didn't work for me). This will allow you to start xfce4-terminal properly from bash, but is orthogonal to the command below.
  4. Run the following in a shortcut or in the Run prompt (as @OhJeez suggested in the comments):

    powershell -windowstyle hidden -Command "iex \"bash ~ -c 'DISPLAY=:0 xfce4-terminal'\" "
    

Other notes:

  • The ~ starts bash in your home directory, you can remove it to start in whatever directory the .vbs file is in, instead. So it's convenient to put it in C:\Users\foo, for example.
  • Note that XMing has to be running for the script to work; in order to start it automatically with Windows you can follow the instructions in this article.
  • Emacs 24 (included with Ubuntu 14.04) doesn't seem to work with XMing; I had to install a newer version as suggested in this post.
Andrew Mao
  • 1,721
  • 1
  • 18
  • 19
  • 1
    Thanks for your help. When i run the script, nothing seems to happen (Xming server is running). However, if I open bash and run xfce4-terminal it works fine. Furthermore, if I run bash -l -c xfce4-terminal from windows cmd, I get a warning Gtk-WARNING **: cannot open display: and nothing happens. I'm quite confused as I figured these commands should behave identically, any guesses? – rperryng Jul 10 '17 at 16:04
  • @rperryng yeah - I'm also trying to get a one-liner to open xfce without the ugly bash command prompt in between, but no luck yet. – Andrew Mao Jul 17 '17 at 20:21
  • 1
    Best solution for starting xfce4-terminal using shortcut. There is a flicker, but no window remains behind: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -windowstyle hidden -Command "iex \"bash.exe ~ -c 'DISPLAY=:0 xfce4-terminal'\" "

    Another version which will start Xming if it's not running: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -windowstyle hidden -Command "iex '& \"C:\Program Files (x86)\Xming\Xming.exe\" -multiwindow'; iex \"bash.exe ~ -c 'DISPLAY=:0 xfce4-terminal'\" "

    – OhJeez Jul 25 '17 at 21:45
  • @OhJeez nice, thanks for working out the intricacies of that command. – Andrew Mao Jul 28 '17 at 18:44
  • Workaround for high-resolution displays. If you have a 4k display, you will have blurry fonts in your terminal.

    To fix this you will need:

    1. Use "VcXsrv Windows X Server" instead of Xing https://sourceforge.net/projects/vcxsrv/

    2. Run the xserver in compatibility mode. To do this you will need: click on VcXsrv shortcut with the right mouse button. Choose "Properties". On the "Compatibility" tab set checkbox against "Override high DPI scaling behavior..." and choose "Application" in the next dropdown.

    3. Run xfce4-terminal and change font setting. Change font to a larger one.

    – koorchik Sep 30 '17 at 17:33
  • @OhJeez I'd like write a reg file to start xfce4-terminal from context menu , but without success. Could you please give me a favor ? link : https://stackoverflow.com/questions/55788271/how-can-i-add-right-click-context-menu-for-shell-in-wslwindows-subsystem-linux – Mithril Apr 22 '19 at 02:12
  • @Mithril I don't use WSL or Xming anymore. – OhJeez Apr 23 '19 at 07:18
14

Today, you are suggested to use "Windows terminal" which is open sourced by Microsoft.

The official build can be obtained from Windows Store in mid June this year.

But you can also experience it using below preview version. https://github.com/yanglr/WindowsDevTools/blob/master/awosomeTerminal/WindowsTerminal_SelfSigned_x86_x64_arm64.7z

After installed, the running results are below:

pic1

pic2

pic3

pic4

12

I created (and use) an open source terminal for Windows Subsystem for Linux (WSL) called wsl-terminal, it is based on mintty and wslbridge.

screenshot

Gore Liu
  • 119
  • 1
  • 2
  • Be careful with self promotion - it can look like spam. https://askubuntu.com/help/promotion –  Sep 20 '17 at 01:54
  • 8
    Self promotion is ok if you acknowledge it – David LeBauer Sep 20 '17 at 02:16
  • And you haven't acknowledged it. – muru Sep 20 '17 at 02:31
  • 7
    And please, add some details about why wsl-terminal will provide a better terminal experience. – Cynplytholowazy Sep 20 '17 at 04:09
  • 2
    Thank you for sharing this. Your stuff already works better than the built-in terminal - at least it can deal with line wrapping on the command line a bit better. A CTRL-A to quickly go to the beginning of the command still fails though. I'm happy with people self promoting stuff like this. People should calm down. – EdH Dec 23 '17 at 15:41
  • 1
    Why don't you ask the 1000+ people who starred it on github @Cynplytholowazy ? – EdH Dec 29 '17 at 22:13
  • this is great. all i wanted was an easy-to-install non-crappy terminal client that can do copy and paste properly (gasp!) and this solution was much easier than the others. – Nathan Beach Mar 06 '19 at 15:47
  • @muru, did "goreliu.github.io" really not give it away? I mean, c'mon... – SO_fix_the_vote_sorting_bug Apr 04 '20 at 20:59
  • The link doesn't seem to go to the right place. But this looks like the same project: https://github.com/mskyaxl/wsl-terminal – SO_fix_the_vote_sorting_bug Apr 04 '20 at 21:17
  • @jdk it's not the reader's job to examine easily changed usernames and links to determine that - it's the poster's job to state it out explicitly. If OP is too lazy to do that, they shouldn't be posting. It's as simple as that. – muru Apr 05 '20 at 01:03
6

On a fresh Ubuntu install, I've just installed XMing (in Windows) then (in Ubuntu) xfce4-terminal, and after I export DISPLAY=:0, it worked.

To get rid of Windows's default console, this VBS script does the job:

WScript.CreateObject("WScript.Shell").run "bash -l -c xfce4-terminal", 0, True

(With $DISPLAY set in your .profile.)

edit: And to make the script pin'able, create a shortcut with target wscript "C:\path\to\thescript.vbs".

n.caillou
  • 159
  • The VBS seems to work, however the terminal window is open and closed right after. How can I keep it running? – TCB13 Apr 15 '17 at 22:04
4

On Windows:

  • Click on the upper left corner of the bash window.
  • In the menu that opens select 'Properties'
  • Set options that you want like font etc.(there is even an Ubuntu mono font!)
  • After setting properties they will be applied for current window. To set them as default click the upper left of the window and click defaults.
  • You can press Alt+Enter to toggle full screen mode.

I hope this helps.

mohi
  • 41
  • 2
  • I'd like to point out it has the same appearance / usage as Ubuntu's (Gnome's) terminal except it adds mouse support. ie You can click the column headings in htop – WinEunuuchs2Unix Oct 07 '17 at 23:42
4

ConEmu works great! Just install it and start a new {bash} console. I added cd ~ to my .bashrc to have it default to starting in my home directory.

Good explanation: https://conemu.github.io/en/BashOnWindows.html

ravery
  • 6,874
Bill Hoag
  • 141
2

Since the latest updates to Windows 10 (and WSL) everything seems to be working using "native" windows bash console. (And I am not talking about the (in)famous 1809 Windows update). This works even on Enterprise version at least for 1803 17134.345 build).

See the article at https://www.hanselman.com/blog/SettingUpAShinyDevelopmentEnvironmentWithinLinuxOnWindows10.aspx

A little caveat - to really use the bash console in Windows one should launch tmux - and everything will work as showed by Scott in his blog.

Adrian
  • 21
  • This is hilarious! "exec tmux" indeed solves all the Windows native "bash.exe" terminal issues (weird cut off lines after resizing). – Yves Dorfsman Oct 23 '18 at 22:22
2

Extraterm is more than just a terminal emulator. It provides a toolbox for working with your terminal and command line applications.

  • Features
  • Supports Linux and macOS, on Windows WSL, CMD, PowerShell and Cygwin
  • xterm compatible
  • Multiple tabs and panes, split and tiled any way you like
  • Show images in the terminal
  • Unicode support
  • Color emoji
  • Keyboard friendly “Command Palette”
  • Configurable key bindings
  • Keyboard based selections
  • Shell integration; can isolate and ‘frame’ command output. (bash, zsh and fish supported)
  • Easy uploads and downloads using the shell integration
  • Command output is editable in place. Multi-cursor editing
  • Previous command output can be used as input for new commands
  • Supports iTerm2 and TextMate themes
  • Text zoom
nelaaro
  • 10,028
  • I am now using this terminal, as it has the features I really want. an easy way to switch between cmd, powershell, bash, fish etc. – nelaaro Jan 29 '19 at 08:46
1

Extending answers of aikeru and n.caillou as neither of their VBScript/JScript solutions worked right away for me.

Call WScript.CreateObject("WScript.Shell").Run("bash.exe -l -c 'DISPLAY=:0.0 xfce4-terminal --working-directory $HOME'", 0, True).

The script needs to be prepended by Call when using parenthesis in the run command, see here. Also the ticks needed to be the other way round. Moreover, an additional argument to xfce4-terminal will start the terminal in the user's home folder. Sorry if this was actually working JScript code, I have no idea about these scripting languages.

Saving this as a file vbscript.vbs and executing from a cmd prompt by

wscript vbscript.vbs

then opens a xfce4-terminal window (given XMing or alike is running) after 2 seconds delay. Turning this into a shortcut as suggested by n.caillou's works indeed and clicking the shortcut will automatically spawn a new xfce terminal window with some delay.

David Foerster
  • 36,264
  • 56
  • 94
  • 147
1

https://hyper.is/

  • It is based on electron which makes it easy to develop and extend using javascript.
  • It does not use the default windows console in any way.
  • It allows you to choose your backend shell bash, cmd, PowerShell.

    the shell to run when spawning a new session (i.e. /usr/local/bin/fish)
    if left empty, your system's login shell will be used by default
    
    Windows
    - Make sure to use a full path if the binary name doesn't work
    - Remove `--login` in shellArgs
    
    Bash on Windows
    - Example: `C:\\Windows\\System32\\bash.exe`
    
    PowerShell on Windows
    - Example: `C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`
    shell: 'C:\\Windows\\System32\\bash.exe',enter code here
    

Very nice themes and plugins

plugins: [
    //"hyper-dracula"
    //"hyper-solarized-dark"
    "hyper-material-theme"
],

Using this guide I was able to get my WLS, bash working very nicely.

nelaaro
  • 10,028
1

A terminal for a more modern age https://eugeny.github.io/terminus/

Terminus is a terminal heavily inspired by Hyper. It is, however, designed for people who need to get things done.

  • Runs on Windows, macOS and Linux
  • Theming and color schemes
  • Fully configurable shortcuts
  • Full Unicode support including double-width characters
  • Doesn't choke on fast-flowing outputs
  • Proper shell-like experience on Windows including tab completion (via Clink)
  • PowerShell (+Core), WSL (Bash on Windows), Git-Bash, Cygwin, Cmder and CMD support
  • Remembers your tabs
  • Integrated SSH client and connection manager
nelaaro
  • 10,028