About

Typically, the way to run Linux on Windows as a subsystem is to either use Cygwin or MSYS/2 and then install the desired packages. With Cygwin, the terminal provided is MinTTY yet MinTTY is not as complete as a proper XTerm terminal, such that one interesting task would be to set up Cygwin in order to be able to launch an XTerm terminal directly from Windows.

Setting up XWin

Using the Cygwin package manager, the startxwin and xterm packages must be installed that pulls xinit and all the other packages required to run the X11 window server on Windows. The variant that will be run is XWin, a windowing server that allows X11 programs to be launched on the Windows desktop and blend-in along all the other Windows applications.

With the packages installed, the next part is to create some Windows batch files to launch XWin and then a set of batch files to launch various other X11 programs such as XTerm. These scripts are not a far stretch from the provided Cygwin.bat file with regards to the Windows DOS operations, but they get more complex when various options are added to the command line.

XWin

The batch file for XWin is the following:

@echo off
setlocal enableextensions
set TERM=
C:\cygwin64\bin\bash.exe --login /usr/bin/startxwin

to which a shortcut is created and placed in the usual Windows "Start Up" folder such that it will be executed once Windows starts.

xterm

Here is the batch script for xterm:

@echo off
setlocal enableextensions
set TERM=
C:\cygwin64\bin\xterm.exe -ls -xrm "xterm*VT100.Translations: #override \n\ ~Meta <Btn3Down>:    insert-selection(CLIPBOARD)" -display :0

that will launch the XTerm terminal and also additionally handle pasting the clipboard into the terminal using the third mouse button.

Copy & Paste Issues

Due to the various layers of virtualization, copy & paste functionality might not be straightforward, in particular between Windows-native applications and X11. However, some fixes can be applied to address the issues.

First, note the parameter that has been passed to XTerm within the XTerm batch file:

xterm*VT100.Translations: #override \n\ 
    ~Meta <Btn3Down>:    insert-selection(CLIPBOARD)

This override makes it such that the contents of the clipboard can be pasted into the XTerm window by simply clicking the middle mouse button. Conversely, copying is performed just by selecting text within the XTerm window.

Mouse button 3 is used here because it just so happens that due to a trackpad, mouse button 2 is not sensed at all. To check up on the mouse buttons, the X11 utility xev can be used.

xev can be launched from XTerm and it will display, by default, a black caret to which you the mouse can be pointed at and then keys or mouse buttons can be pressed in order to see what xev picks up. Typically, the keycode is the one to watch for, or the mouse button number, because those identifiers can be used with other software such as XTerm to remap keys.

For example, assuming that xev confirms a right-click (mouse button 2), the XTerm configuration can be adjusted to:

xterm*VT100.Translations: #override \n\ 
    ~Meta <Btn2Down>:    insert-selection(CLIPBOARD)

such that right-click (mouse button 2) can be used instead of mouse button 3 to paste the contents of the clipboard inside the terminal.

Creating Shortcuts

The XWin batch file shortcut is placed inside the Windows "Start Up" folder in order to start X11 on boot, whilst the utilities can be spread out within the Windows menu such that they can be launched quickly.

One problem that will become immediately apparent, is that whether XWin or any other utility is launched, a command prompt will show up on the desktop first, which is ugly such that a solution has to be found to eliminate the prompt.

One solution is to use a free utility such as silentbatch that is able to run a Windows batch file without popping up a command window. silentbatch.exe can be copied to the Cygwin /usr/local/bin/ directly and then the shortcut to the batch file that start XWin is modified in order to launch the file though silentbatch.exe instead of directly.

In other words, the "Target" textbox, from the "Shortcut" of the shortcut is changed to reflect a path to the Cygwin XWin batch file:

C:\cygwin64\usr\local\bin\silentbatch.exe C:\cygwin64\Cygwin-X.bat

Then, placing the shortcut in the "Start Up" Windows folder makes it such that XWin will be launched on Windows boot silently without displaying a command prompt.

The same procedure using silentbatch.exe and shortcut modification is then used to update the "XTerm" shortcut such that launching XTerm will not pop up a Windows command prompt window first.


windows/getting_a_proper_unix_terminal_running.txt ยท Last modified: 2024/04/15 10:39 by office

Wizardry and Steamworks

© 2025 Wizardry and Steamworks

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.