Cygwin quickie: opening files with cygstart.exe

2008-03-11 / 10:23 / dave

Cygwin’s cygstart.exe is amazing. It opens data files as though you clicked on them in Windows Explorer. Best of all this including folders: cygstart mydir opens up a view of the directory. I’ve got mine aliased (actually a symbolic link so I can use it from eshell) to op. I started off with it aliased to open but I used it enough that the 2 keystrokes were worth it.

$ ln -s /usr/bin/cygstart.exe ~/bin/op

Who needs xterm when you’ve got Cygwin and batch files?

2007-12-02 / 20:23 / dave

It’s cool that Cygwin includes an XWindows server, but, since I’m not running graphical programs remotely, I’ve never really seen the need to use it. But I really miss one thing: xterm.

I can get 80% of the way by using Launchy to start new cygwin shells. Unfortunately, the next 10% is important: environment. Xterm remembers where you are:

xterm example

The new window starts in the src directory, right where we were working before. While avoiding a cd is nice, it’s really an advantage when combined with bash-ssh. A new cygwin shell starts in non-ssh mode, requiring a fresh login.

We can get this next 10% with cyg, a 2 line batch file:

@echo off
start bash

All it does is call start on the bash executable (which is already in my path).

cyg example

So you can go switch to ssh mode, change your directory, and run cyg (1) and have those changes reflect in your new window (2). (I type cyg & out of habit–& runs a process in the background in *nix–but just cyg works fine). This matches my ADD work-flow: I can be in the middle of editing locally when I realize I need to clean up some temp files on the server. I launch a cyg, ssh to the server, do my deed and return without losing my place.

Using a batch file is also what produces the visual differences (3). At first I was annoyed, but it turns out pretty handy: I can easily tell my “main” window from my “omg I have to pop my stack right now” windows. Telling the windows apart is also important because there’s another limitation of cyg and bash-ssh. If the main window is closed, it takes ssh-agent with it, the cyg window needs an ssh password on each connect (though this is arguably better than xterm, which takes down all windows it launched. Oops.) (Also check out my awesome freehand text. Not bad considering I did it using a nipple.)

cyg after main window close ssh error example

Scratch my back

The last 10% I’d like is the ability to launch apps in a new window. Something like

$ cyg "man rsync"

And have that launch a new window and automatically run man rsync. I played around with % variables but couldn’t get anything working. I haven’t yet written a Python script to do it, and I’d like to keep it that way.