This is the mail archive of the cygwin@sources.redhat.com 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]

Re: Bash + Shell hack = ?


If y'all don't mind I'd like to suggest a slightly cleaner way of doing this.

Starting from the windows explorer end. Windows automatically passes the fully
qualified path to the object as arg 1, so just create an item that points to
cygwin.bat however you wish, mine is called "bash this" and the command to run
is simply "d:\cygwin\cygwin.bat". Windows will automatically call it with the
full path, so if you choose this on c:\yada it would run "d:\cygwin\cygwin.bat
c:\yada".

Now to that we've got it into cygwin.bat we need to propagate it further, using
an environment variable is easiest... here's my cygwin.bat:

@set STARTIN=%1
@d:\cygwin\bin\bash --login -i

the only line there that is important to this is the one setting
the STARTIN envvar, as this is how we pass it on to bash... in order
to act on it I've replaced this line in /etc/profile:

cd $HOME

with this logic:

if [ ! -z "$STARTIN" ]; then
   if [ -d "$STARTIN" ]; then
     cd "$STARTIN"
   else
     echo "$STARTIN is not a valid path."
     cd $HOME
   fi
   unset STARTIN
else
   cd $HOME
fi


which also requires these lines to be changed, as . and ~ may no
longer be the same directory at this point in the script:

test -f ./.profile && . ./.profile
test -f ./.bashrc && . ./.bashrc

becomes:

test -f ~/.profile && . ~/.profile
test -f ~/.bashrc && . ~/.bashrc

This gives you a couple other advantages: such as you can create an icon
to open a bash prompt to any given location (I like one in my start bar
that automatically puts me in the root of my products build tree.) and
you can open a new bash window from any dos prompt with 'start cygwin .'

Note that if you want to be able to handle spaces in paths then you can
replace STARTIN's assignment with this:

set STARTIN=%1 %2 %3 %4 %5 %6 %7 %8 %9

which will allow you to have up to 8 spaces in the total path; the downside
to this is that the initial prompt will look a bit odd (trailing spaces)
until you cd the first time.

p.s. any relation to Kirby?


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


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