Showing posts with label cygwin. Show all posts
Showing posts with label cygwin. Show all posts

11.11.2009

Pimping Cygwin part I: Terminal Goodness

My inaugural experience with Linux as a desktop started with Gentoo in 2005. I used openbox as my windows manager. The extent of my GUX (graphical user experience) was right clicking the desktop to launch a terminal and off I went. The concept of putting a file or folder on the desktop wasn't there and I became quite fond of mv, mkdir and rm. Since then I've tried to use RHEL, Fedora, Solaris, and all the 'buntu's. Aside of the fact my games don't run and the drivers were always substandard, I was never happy with the experience of the interface. The only thing I ever miss about Linux is the shell. A big argument in the developer community on switching to Apple is the use of a real bash shell. I guess that's if you consider Terminal to be a real terminal. In the interest of not losing potential followers, I'll refrain from speaking on why I hate Apple. I'd entertain some comment discussion for anyone who questions my right to hate them but that's not the point of this blog. Instead, I'm here help you configure Cygwin for some Linux goodness on your Windows machine. I'm calling this part one because it would be a tremendously long post to detail everything great about Cygwin. Ultimately it's a terminal/shell I'm after so let's start off with how to get that working.

The first real problem with Cygwin is that by default it starts up in a DOS window. Come on Windows! Is a command line that supports line wrap copy/paste really that hard to provide? This can be a really bad first impression to the casual user who installs Cygwin. Thankfully, there's an rxvt implementation available for Cygwin, but making that useful isn't super straightforward either.

First, you have to remember to select it during the install process. Otherwise, it is not included. Then what you need to do is modify the cygwin.bat file (or create a new one) and have it launch RXVT and bash instead of whatever crap it does by default. That is a simple one liner batch file.
C:\Cygwin\bin\rxvt.exe -e /usr/bin/bash --login -i

The next thing to do is to make it pretty. This is what I have in my .Xdefaults file which should be in your cygwin ~(that's home you linux newbie):
Rxvt*geometry: 120x40
Rxvt*background: #000020
Rxvt*foreground: #ffffbf
Rxvt*scrollBar: True
Rxvt*scrollBar_right: True
Rxvt*font: Lucida Console-12
Rxvt*SaveLines: 2000
Rxvt*loginShell: True
! VIM-like colors
Rxvt*color0: #000000
Rxvt*color1: #FFFFFF
Rxvt*color2: #00A800
Rxvt*color3: #FFFF00
Rxvt*color4: #6090F8
Rxvt*color5: #A800A8
Rxvt*color6: #00A8A8
Rxvt*color7: #D8D8D8
Rxvt*color8: #000000
Rxvt*color9: #FFFFFF
Rxvt*color10: #00A800
Rxvt*color11: #FFFF00
Rxvt*color12: #6090F8
Rxvt*color13: #A800A8
Rxvt*color14: #00A8A8
Rxvt*color15: #D8D8D8

Last, but far from least, is fixing some keys and disabling that hideous beep. That's all part of the file also located at ~/.inputrc. Here is what I use.
"\e[3~": delete-char

# VT
"\e[1~": beginning-of-line
"\e[4~": end-of-line

# kvt
"\e[H": beginning-of-line
"\e[F": end-of-line

# rxvt and konsole (i.e. the KDE-app...)
"\e[7~": beginning-of-line
"\e[8~": end-of-line

# VT220
"\eOH": beginning-of-line
"\eOF": end-of-line

"\C-v": paste-from-clipboard

set meta-flag on
set convert-meta off
set input-meta on
set output-meta on
set bell-style visible

I'm not sure if you need all of those. I've copied this .inputrc file around for a couple years now. The good thing is that it's a standard .inputrc file and you can Google through many many years of how to configure it to your liking. Same goes for the .Xdefaults.

The last real thing to fix is the prompt. The default one is not very good. For any Linux user this should be simple but for those in need, try adding this to your .bashrc file, located conveniently at ~/.bashrc:
export PS1="\[\e[36;1m\]\u\[\e[32;1m\]:\w > \[\e[0m\]"

So there you have it. Bash goodness in Windows. Go ahead. Tail that logfile. Pipe it to grep. Use a for loop with find and sed to rename some files. Enjoy the beauty of symlinks (and laugh at junctions while you're at it, what a joke).

Please comment if something doesn't work so I can update the post. This is only what I can recall from memory after having done this so many times. I'm thinking about covering X for Part II of the series. SSH + X-forwarding works quite beautifully.

Now if only I could get Keynote and Textmate to run in Windows. I'd be in heaven! I need the polyglot OS.

10.12.2009

Cygwin + Interpreters(Jline) + Carriage return = solved!

I love cygwin. Not only is having every a bash shell and unix utility on windows awesome(grep, less, tail, awk, cut, pipe, sed, du, df, ls, ln, curl, sort, head, vi, X-Server, etc...) but using rxvt or xterm as a replacement to windows cmd window is awesome.

However when I use some command line interpreters such as a groovy shell, maven cli, spring roo, and others, my carriage return doesn't work. When I hit enter, the cursor goes to the next line but the command is not executed. This has been bothering me for months and yesterday I finally found the answer.

The core of the problem is with JLine, a command line API that many Java based interpreters use. Jline queries the environment to see what OS you are running and uses that for the expected end of line input. Because the OS is windows but the terminal is xterm, cygwin (rxvt at least) will not send the command Jline is expecting to signal end of line. Therefore, you can't actually execute anything in the interpreter.

So after searching for a solution over and over I finally stumbled upon this issue. Thank god for JIRA! It ultimately led me to this Jline defect.

So in order to save you a lot of trouble, all you have to do is add the following to your jvm args:
-Djline.terminal=jline.UnixTerminal


If you are doing this for maven CLI, then you need to add the -D argument to your MAVEN_OPTS because Maven will execute the process for you.

I didn't need to use the stty commands as recommended but I only fixed my maven-cli plugin (which is awesome btw). Maybe someone could explain what the stty commands are for and when or why you'd need them.

So hopefully this will save some cygwin users some time and frustration.