delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/06/22/13:05:09

X-Spam-Check-By: sourceware.org
Date: Fri, 22 Jun 2007 10:04:46 -0700
From: Gary Johnson <garyjohn AT spk DOT agilent DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: using chere
Message-ID: <20070622170446.GA15817@suncomp1.spk.agilent.com>
Mail-Followup-To: cygwin AT cygwin DOT com
References: <f5c30k$v3t$1 AT sea DOT gmane DOT org> <514926 DOT 2846 DOT qm AT web25006 DOT mail DOT ukl DOT yahoo DOT com> <f5e0qn$ten$1 AT sea DOT gmane DOT org> <467AB10F DOT 8070307 AT gmail DOT com>
MIME-Version: 1.0
In-Reply-To: <467AB10F.8070307@gmail.com>
User-Agent: Mutt/1.5.16 (2007-06-09)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019