Cygwin terminal window empty - windows

I've just installed cygwin (64bit) terminal on Windows 7 64. When I open cygwin terminal from Start menu, I can only see empty terminal window with blinking cursor. I can issue commands and see output, but prompt is missing (at least $ should be there, right?)
Any ideas how to fix it? It is fresh installation of cygwin on fresh Windows 7 64bit Enterprise.

Start with issuing the command
echo xyz
To find out if you are actually at a blank command prompt. If that responds with the output of xyz then check your prompt with
echo $PS1
And then set it
export PS1='\h \w> '
This should give you a prompt. If the first step itself does not give you a prompt you have other problems.
Another option is to start the bash shell from windows command prompt:
c:>c:\cygwin\bin\bash --login
Assuming you have installed cygwin in c:\cygwin

First,
I'm using window64 too, but it can work with cygwin32, please try with cygwin 32
If not, please try install cygwin again from another miror

Related

How to elegantly create a Windows shortcut that starts a WSL program under X

I'm struggling a little to launch xfce4-terminal from my WSL installation under VcXsrv from a button on the Windows taskbar. I don't want any DOS box/console/terminal other than the xfce4-terminal when I'm done. I have it working, but man is it ugly. Does anybody have a cleaner way of doing this?
Here is what I got working: I created a windows shortcut on the Desktop with this target (all in one line, broken with newlines for readability here):
C:\Windows\System32\wscript.exe
\\wsl$\Ubuntu-20.04\home\peter\bin\windows\startTerminal.vbs
startTerminal.vbs was inspired by from 10 Ways To Run Batch Files Silently And Hide The Console Window • Raymond.CC (one of the few solutions that didn't require installing a separate program for this!) and it contains:
CreateObject("Wscript.Shell").Run "C:\Windows\System32\wsl.exe -u peter --exec /home/peter/bin/windows/startTerminal.sh",0,True
and startTerminal.sh contains:
export DISPLAY=localhost:0.0
xfce4-terminal --command=/bin/zsh
Setting DISPLAY is apparently required, even though I set the DISPLAY environment in ~/.zshrc. wsl.exe apparently doesn't do that unless you run the login shell.
Once all of this is working, I can drag my shortcut to the taskbar and click on it there.
I count 3, three files cooperating to achieve this simple goal? Can I limit that to one or two without installing an external program?
Yes, I think you can do what I do in one shortcut file. I'll share what works for me then you'll have to fiddle for your program.
Try putting all your commands in the Target section of the Shortcut link file.
Step 1. Right click on desktop then New then Shortcut then name it (LaunchXFCE4)
Step 2. Right click LaunchXFCE4 select Properties
Step 3. Enter all your launch sequences in the Target section
Step 4. Right click LaunchXFCE4 select Pin to Taskbar
I'm launching Emacs 27.1 on WSL 2 with Ubuntu 20.10 on Windows 10 using this code which perhaps you can modify.
C:\Windows\System32\wsl.exe --distribution Ubuntu20 bash -c "export DISPLAY=$(ip route | awk '{print $3; exit}'):0 && export LIBGL_ALWAYS_INDIRECT=1 && export XCURSOR_SIZE=16 && setsid emacs"
The first export display is similar to your localhost:0.0 so replace it or try mine. Maybe your xfce4 replaces my emacs. Read this post about double ampersands. So possibly this
C:\Windows\System32\wsl.exe --distribution Ubuntu20 bash -c "export DISPLAY=localhost:0.0 && export LIBGL_ALWAYS_INDIRECT=1 && export XCURSOR_SIZE=16 && setsid xfce4-terminal --command=/bin/zsh"
Note, my VcXsrv starts when windows starts by putting a shortcut to config.xlaunch in my C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.
By the way, Microsoft will provide a GUI for WSL in a few months, according to their blog
GUI app support in WSL is becoming a reality! We are getting closer to
an initial preview and happy to announce a preview release for Windows
Insiders within the next couple of months.
I removed the need for a startTerminal.sh file by:
Editing startTerminal.vbs to contain:
CreateObject("Wscript.Shell").Run "C:\Windows\System32\wsl.exe -u peter bash -l -c xfce4-terminal",0,True
And then I created a ~/.bash_profile to set the $DISPLAY variable, which probably should've been done anyway:
$ cat .bash_profile
if [ -z "$DISPLAY" ]; then
export DISPLAY=:0
fi
So now there is the shortcut and a startTerminal.vbs that starts it up. It still isn't very elegant...
One of the few good additions to Windows was WSL-2, it's much more capable now.
It's part of late Win 10 and Win 11.
Here is how to elegently create a terminal window, replace the terminal with any X app you want.
Linux: "apt-get install xfce4-terminal" (or equivalent)
Windows: Create a new Shortcut (right click in any windows folder)
2.1) Shortcut to -> C:\Windows\System32\wslg.exe -u root -- /usr/bin/xfce4-terminal
If you have multiple distributions use it like: "-d Debian"
That's it. You can give it a better icon and name it.
It will launch the application as if it was a windows application.
After experimenting with #Saj 's answer which did not work for me I resulted in the below:
C:\Windows\System32\wsl.exe --distribution Ubuntu-20.04 bash -c "export DISPLAY=$((route.exe print | Select-String 0.0.0.0 | select -first 1) -Split "\s+" | select -Index 4):0.0 && export LIBGL_ALWAYS_INDIRECT=1 && setsid emacs"
Note that my problem was that it could not use bash commands inside the parenthesis (grep, awk)
Environment: WSL2 on Windows 10

How do I get colorized output on my windows git-bash terminal?

How do I get colorized highlighting on the output?
e.g
npm start
npm test
etc.
System:
Windows 10
Git version 2.16.1.windows.4
Node 5.6.0
Uninstall Git Bash for Windows 10 and run the installer again:
Click next until you'll prompt to choose to Configure the terminal emulator to use with Git Bash, here you select Use Windows default console window (instead of the default option which use MinTTY as terminal emulator)
Click next and finish the installation
Test if it works correctly:
Open Git Bash (cmd will open up), try to use ls you'll see all folder colored in blue
Try some ANSI escape code by running echo -e "\033[44m\033[37m Test \033[0m" you'll se the text Test with a blue background as seen in the screenshot below
Windows 10 Console support 24-bit color and ANSI escape sequences
The terminal was a MinTTY, which does not support colors it seems. Fixed it by re-installing and ticking of Windows Terminal.
For me, it was choosing Windows default console window instead of MinTTY that made color output not working.
My solution:
Uninstall git bash; during installing, choose MinTTY (the default option).
After installation, head over to C:\Program Files\Git\etc, open your git bash
vim ~/.bashrc (for some reason using an editor doesn't work; I guess it's a privilege issue)
Under # Add colors to 'ls' change it to
alias ls='ls --color=auto'
Then restart and it should work.
My version: git version 2.24.1.windows.2
Use winpty
Windows Git Bash has some documented quirks: Winpty and Git Bash
$ winpty npm start
winpty: error: cannot start 'npm': Not found in PATH
Again another windows / git bash quirk, it doesn't attempt to resolve executables ending in .cmd so it needs a nudge.
$ winpty npm.cmd start
The same applies for yarn with:
winpty yarn.cmd start
While we are here and you are having trouble getting gyp to locate your Python2 install location to compile native extensions then try this:
env PYTHON=/c/Python27/ winpty yarn.cmd install
Git Bash overrides your PYTHON environment variable for only the duration of this command. You get winpty to run the pseudo-tty session to allow animation rendering and coloring.
Assuming your python 2 install location is C:\Python27

PhpStorm terminal : Cygwin colors does not work

I have PhpStorm 2016.2 and I added Cygwin in the Shell path as follow : "C:\cygwin64\bin\env.exe" CHERE_INVOKING=1 /bin/bash.exe
It's working well, but the colors do not work.
For exemple I have ?[32m Name instead of having Name colored in green.
I tried several things like adding the plugin Grep Console to have the support of ANSI Color, but didn't work.
It's really hard to work with lines with multiple ANSI colors ?[39m ?[32m Scheme ?[39m ?[32m Host ?[39m ?[32m Path.
Do not hesitate to ask further information about the problem. Thank you.
P.S. I'm on Windows 10.
EDIT
when I do /usr/bin/which php in PHPStorm terminal I get /cygdrive/d/wamp2/bin/php/php5.6.16/php. I have php5.6.16 and php7.0.0 in my WAMP and I'm currently using php7.0.0.
EDIT 2 I added a $PATH for php7.0.0 so now I have /cygdrive/d/wamp2/bin/php/php7.0.0/php when I do /usr/bin/which php. But the main problem remains.
Adding second answer to provide an alternative solution to my original answer.
ANSICON Support
First download and install ANSICON
Extract the windows binary files
(x86 or x64 directory contents) into your $PATH (D:\wamp\bin\php\php7.0.0)
Optionally run ansicon -i from a Windows Command Prompt
to allow you to use ANSICON to add ansi color support to the Windows Command Prompt.
Next you need to wrap ANSICON for the PHPStorm terminal
"X:\path\to\ansicon.exe" -p "C:\cygwin64\bin\env.exe" CHERE_INVOKING=1 /bin/bash.exe
NOTE: Using -l or --login, as stated in the original answer, will add /usr/bin and /usr/local/bin to your $PATH and cause the
terminal to use the Cygwin PHP installation making ANSICON unneeded.
Next in your ~/.bashrc file you will need to add at the bottom of the file.
export ANSICON=true
You can easily append the line by running the following command from a Cygwin terminal.
echo export ANSICON=true >> ~/.bashrc
This will ensure Symfony will find the ANSICON environment variable with a different Windows Version.
Next restart PHPStorm and open the terminal to test it out.
You need to add the -l switch to your terminal path.
Before adding the switch:
The full path should be
"C:\cygwin64\bin\env.exe" CHERE_INVOKING=1 /bin/bash.exe -l
or
"C:\cygwin64\bin\env.exe" CHERE_INVOKING=1 /bin/bash.exe --login
Be sure to close the currently opened terminal window by clicking the red X in the upper left of the terminal dialog and reopen it.
Now running the command again it should look like:
See man bash within the Cygwin terminal for more information.
UPDATE
Based on your comment about your WAMP installation. You'll need to install PHP in Cygwin for it to run correctly, which will allow the use of the posix line of functions and emulate a Linux distribution for your PHP environment. Which is generally why Cygwin is used.
How are you intending to use Cygwin with PHP?
The issue is that Cygwin is using the Windows PHP executable and the Symfony Console Component StreamOutput is detecting it as a Windows instance of PHP and and not Cygwin/Linux in order to use posix_isatty.
Here is an example of the code Symfony Console uses to render color output to the terminal.
if ('\\' === DIRECTORY_SEPARATOR) {
static::$defaultColors = #(
0 >= version_compare('10.0.10586', PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD)
|| false !== getenv('ANSICON')
|| 'ON' === getenv('ConEmuANSI')
|| 'xterm' === getenv('TERM')
);
} elseif (function_exists('posix_isatty')) {
$h = stream_get_meta_data($this->outputStream) + array('wrapper_type' => null);
$h = 'Output' === $h['stream_type'] && 'PHP' === $h['wrapper_type'] ? fopen('php://stdout', 'wb') : $this->outputStream;
}

Vim on Cygwin and MinGW

I have tried to use Vim both on Cygwin and MinGW but many times the characters behave in an unpredictable manner (backspace is not deleting, cannot have a semicolumn, and so on...). I am wondering if this is related to those systems or if it could be a problem of my own system/settings (e.g I need to adjust some settings, define the character encoding, etc.). I am on windows 7 64bit
Thank you
The Cygwin CMD emulator has a known problem with Vim. Seems to be a redraw problem. Apparently fixing it would break execution of some exes that Cygwin depends on. Many users choose to use another terminal emulator. I find that paging down and back up fixes the redraw but sometimes I have to exit Vim and relaunch.
PuTTYcyg is a patched version of PuTTY that, in addition to telnet, rlogin, ssh, and serial connections, can also be used as a local Cygwin terminal instead of the Windows console or xterm. See README.txt on the PuTTYcyg site for more information.
To use rxvt:
#echo off
C:
chdir C:\cygwin\bin
set EDITOR=vi
set VISUAL=vi
set CYGWIN=codepage:oem tty binmode title
rxvt -sr -sl 10000 -fg white -bg black -fn fixedsys -fb fixedsys -tn cygwin -e bash --login -i
Mintty is a terminal emulator for Cygwin and MSYS. In Cygwin, it is installed as the default terminal by Cygwin's setup.exe. In MSYS, the mintty package can be installed with the command mingw-get install mintty. Alternatively, binaries for Cygwin 1.7, 1.5 and MSYS can be found on the Minitty downloads page.

adb shell auto-complete under Windows 7?

I tried on linux and ash from busybox does auto-complete command line... But under Windows 7 when I press Tab it doesn't work. Any idea to make Windows 7 smart? :) Thanks!
Looks like auto-complete is done, but nothing echoes back after when tab is pressed...
An example:
adb shell
ls m[press tab]
after tab is pressed, some space characters are shown, but characters that are generated by auto-complete doesn't echo back, then if I press enter, directory mnt is listed which means auto-complete works but echo system has some problem. Right?
ls m[space][space][space][press enter]
mnt
I run adb on Win7 sometimes, both under the cmd.exe and Cygwin, and I was frustrated by how adb shell handled autocompletion and character echo. I also use adb under OS X and Linux, and in both of those environments the autocompletion and character handling works as I expect. What the problem on Windows seems to be is that adb shell is not setting the terminal modes (stty/termio() for UNIX-type shells). I came up with the following workaround that seems to work well for Cygwin's bash shell. I don't know Windows well enough to know if there is a similar command to stty for cmd.exe:
$ stty -icanon -echo -echoe intr ^0 ; adb shell ; stty sane
Of course you can put this in a script.
I believe that the reason that recompiling adb under Cygwin fixes this issue (under Cygwin) is because the recompile causes adb to use the termio() calls to setup the local terminal modes so that they don't interfere with what you type to the Android shell.
Solved this problem by recompiling adb under cygwin. :)
You can use ADB enhanced Putty
It support auto complete and coloring
you can download it from
ADB Putty
read more at ADB enhanced Putty (replacement for "adb shell" command)
Auto-complete is controlled by the following Registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor
Set the value to 9 or 40.

Resources