Use Notepad++ from Cygwin without having the shell wait for an exit code

19

4

I'm running Cygwin and would like to use Notepad++ as the main shell editor, kind of like what I have on my Mac, where I can type mate whatever to open up an instance of TextMate. In my ~/.bashrc file in Cygwin I have the following alias and environment variable set:

export EDITOR="/cygdrive/c/Program\ Files/Notepad++/notepad++.exe"
alias np="/cygdrive/c/Program\ Files/Notepad++/notepad++.exe"

It mostly works: when I type np whatever or when a Cygwin program calls for $EDITOR, Notepad++ opens.

However, the shell waits until Notepad++ is closed and won't allow any input until then. This may be specific to bash, but how can I open Notepad++ from Cygwin and tell the shell to not wait for an exit code to continue? Adding a & to the end of the alias command doesn't work correctly—it just opens an untitled file and warns filename: command not found instead of opening the file.

Thanks!

Andrew

Posted 2010-07-28T18:26:16.193

Reputation: 1 869

Answers

16

You could try a bash function to pass the arguments before the ampersand:

np ()
{
    /cygdrive/c/Program\ Files/Notepad++/notepad++.exe $* &
}

BUT the bigger issue may be the whole idea of not waiting until Notepad++ exits. Shell commands which use $EDITOR typically are designed to wait until the editor sends back an indication that the editing has completed. This usually means that the editor has exited (e.g. with vi or nano).

Emacs has a way to set your EDITOR to emacsclient and then when you're done editing, you hit a magical keystroke (C-x #) to indicate that editing is complete. If Notepad++ had something similar for cygwin users, I can see how this would work.

Another alternative is to use plain, boring, simple Notepad as your EDITOR and reserve Notepad++ for heavy use (I got the idea from this blog post)

Doug Harris

Posted 2010-07-28T18:26:16.193

Reputation: 23 578

Notepad also requires waiting for editing to be finished – codezombie – 2015-10-17T17:58:03.970

Awesome—that worked. I'm going to go with the vanilla Notepad as EDITOR and Notepad++ as np() – Andrew – 2010-07-28T19:41:42.243

8

I solved it with a simple symlink.

ln -s /cygdrive/c/Program\ Files\ \(x86\)/Notepad++/notepad++.exe ~/bin/npp

Of course ~/bin is in my $PATH.

Now to open a file I just type "npp filename.txt" from the cygwin prompt. I've haven't had to use the & at the end of the command.

This will also throw a tab into the currently running Notepad++ window rather than opening another one -- AND if the file is already open, it doesn't open it again.

Ethan Vaughn

Posted 2010-07-28T18:26:16.193

Reputation: 81

How do you add ~/bin to $PATH? – eric f – 2013-05-09T15:39:01.330

3

export EDITOR="/cygdrive/c/Program\ Files\ '(x86)'/Notepad++/notepad++.exe"

alias np="/cygdrive/c/Program\ Files\ '(x86)'/Notepad++/notepad++.exe"

also works for x86

mlanzero

Posted 2010-07-28T18:26:16.193

Reputation: 31

2

Just add a space and an ampersand (&) to the end of your command and the shell will immediately return to input mode while leaving notepad++ open.

on edit:

I'm not talking about adding it to your alias. Add it to the end of your command like this:

np whatever &

Robert S Ciaccio

Posted 2010-07-28T18:26:16.193

Reputation: 1 470

1Ooh. This looks good so far. Is there a way to put that in the .bash_profile so I don't need to type it all the time? – Andrew – 2010-07-28T18:36:11.300

I'm not a bash expert but I assume you could make your alias take a variable which is the argument, and also include the ampersand at the end. Someone smarter with bash could probably give you the exact syntax. I only knew how to answer your question because I used to do the exact same thing while working in a windows dev environment :) – Robert S Ciaccio – 2010-07-28T18:46:25.003

You can't make an alias take a variable in Bash. You have to use a function or a script. – Paused until further notice. – 2010-07-28T22:49:43.543

1

Aliases don't take interpolated arguments. Use a function instead.

function np() { /cygdrive/c/Program\ Files/Notepad++/notepad++.exe $1 & }

garyjohn

Posted 2010-07-28T18:26:16.193

Reputation: 29 085

1

#!/bin/sh
/cygdrive/c/Program\ Files/Notepad++/notepad++.exe $@ &

This script starts Notepad++ in the background, passing the command line arguments before the '&'

As Doug advised, having a default $EDITOR that does not block may cause problems.

Leftium

Posted 2010-07-28T18:26:16.193

Reputation: 8 163

0

There's a specific command in cygwin to accomplish this. Make sure you download run.exe, and make sure it's in your PATH (or your PATH contains the executable)

alias np="run.exe /cygdrive/c/Program\ Files/Notepad++/notepad++.exe"

Rich Homolka

Posted 2010-07-28T18:26:16.193

Reputation: 27 121