This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: latest cygwin: 'run' problem

On 2014-09-08, Gary Johnson wrote:
> On 2014-09-09, Andrey Repin wrote:
> > Greetings, Gary Johnson!
> > 
> > > I wrote a batch file and a shell script to implement a Run Bash Here
> > > feature from the Windows file manager "Send to" context menu, much
> > > like chere but without having to mess with the registry.  The
> > > hardest part was getting the quoting in the run command line right
> > > so that both cmd and bash were happy.  The files are included
> > > in-line below.
> > 
> > That's overengineered.
> Perhaps.  I know very little about Windows cmd shell programming, so
> I tried to pass the file name to bash early in the process and
> perform any logic there.
> > > ------------------------ run_bash_here.bat -------------------------
> > > --------------------------------------------------------------------
> > 
> > Replace it all with this "bash-here.cmd" placed in /bin :
> > 
> > @START "" /D "%~1" "%~dp0\mintty.exe"
> > 
> > > ------------------------- -------------------------
> > > --------------------------------------------------------------------
> > 
> > This all is just not needed.
> > Just create a shortcut in "Sent to" to your bash-here.cmd - job done, reap the
> > rewards.
> Thanks very much for the example.  It took me a while to figure out
> what that does.  I copied that line to bash-here.cmd and created a
> shortcut to it from my SendTo directory.  It almost works, but there
> are a few things my version does that yours does not.
> First, yours works only if you execute it while the target directory
> is selected in its parent directory.  Mine also works to run mintty
> in the current directory if you execute it while a file in that
> directory is selected.
> Second, my version runs a login shell which sets up the environment
> correctly, e.g., puts /usr/local/bin:/usr/bin: at the head of PATH.
> Just telling mintty to run a login shell isn't sufficient, however,
> because that also sets the current directory to your home directory,
> so you then need to cd to the target directory with the target path
> translated to Unix form.
> Those issues may be easy to fix, but as I said, I don't know my way
> around cmd very well.
> It might actually be better if the script always started bash in the
> parent directory of the selected file.  That would be more
> consistent and could be simpler to implement.  I'll try to find an
> explanation of cmd parameter expansion and see what I can figure
> out.

After much fiddling (programming by successive approximation), I
came up with this:

    @START "" "C:\cygwin\bin\mintty.exe" /bin/bash --login -c "cd $(cygpath -u $0); exec bash -i" "%~p1\"

Using an explicit path to mintty lets me put the script itself
someplace other than /bin.

Because %~p1 ends with a backslash, I had to add another backslash
before the closing quote to prevent the quote from being included in
the path.  (See and

I haven't tried it yet with a path that includes a space.  Tomorrow.


Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]