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: using chere


On 2007-06-21, Dave wrote:
> Paul Mallas wrote:
> > Since we are on the topic - is there a way to do something similar
> > inside an open windows folder rather than from the folder icon?  I would
> > find that much more convenient.
> 
> This came up two years ago. Follow the thread from about here:
> 
> <http://www.cygwin.com/ml/cygwin/2005-06/msg00599.html>
> 
> I haven't spent any further time on it, but will welcome any
> contributions :)

I've been playing with this for a while and am pretty happy with my 
solution.  I just haven't gotten around to posting it anywhere.  
What I've done is to create a normal shortcut in my SendTo folder 
that points to

   "C:\Documents and Settings\garyjohn\run_bash_here.bat"

"C:\Documents and Settings\garyjohn" happens to be my HOME and where 
I started playing with the bat file.  A better location would be 
C:\cygwin\usr\local\lib.

------------------------ run_bash_here.bat -------------------------
@echo off

REM Batch file to run a bash shell in the directory given by the batchfile
REM argument, %1.
REM
REM Gary Johnson
REM 2006-10-17

REM Save the current value of CYGWIN and add the 'noglob' option to allow us
REM to pass the %1 argument to a bash command  unchanged.
REM
set cygwin_save=%CYGWIN%
set CYGWIN=%CYGWIN% noglob

REM Use this form to run in a Command Prompt window.
REM
REM C:\cygwin\bin\bash --login -c "run_bash_here "'%1'

REM Use this form to run in an rxvt window.
REM
C:\cygwin\bin\rxvt.exe -e C:/cygwin/bin/bash --login -c "run_bash_here "'%1'" "'%cygwin_save%'
--------------------------------------------------------------------

The 'run_bash_here' command needs to run in the environment of the 
login shell, so I implemented it as a function in my ~/.bashrc:

------------------------- run_bash_here() --------------------------
# Run a Cygwin bash interactive shell in a directory according to the
# argument.  If the argument is a directory, run the shell there.  If the
# argument is a file, run the shell in the parent directory.  The argument is
# the full path in Windows format.
#
run_bash_here() {

    # Restore original value of CYGPATH.
    #
    CYGWIN="$2"

    # Convert first argument to a Cygwin path.
    #
    path=$(cygpath -u "$1")

    # If the path is not a directory, remove the last component.
    #
    if [ -d "$path" ]
    then
	dir="$path"
    else
	dir="${path%/*}"
    fi

    cd "$dir"
    exec bash -i
}
--------------------------------------------------------------------

I like it because it allows me to run a bash shell in the current 
directory, not just a sub-directory, and because I don't have to do 
any explicit manipulation of the registry.  I just wish there was an 
easier way for others to install it than:

   1.  Drop this batch file here.
   2.  Edit your ~/.bashrc to include this function.
   3.  Run the new SendTo shortcut wizard.

especially step 2.  Maybe I could just drop a file containing that 
function definition into /etc/profile.d.

Regards,
Gary

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


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