public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Bash Here - Start Cygwin from a folders context menu
@ 2002-05-28  1:41 Martin Gramatke
  2002-05-28  2:59 ` Michael Hoffman
  0 siblings, 1 reply; 15+ messages in thread
From: Martin Gramatke @ 2002-05-28  1:41 UTC (permalink / raw)
  To: cygwin

Hi,

maybe you know "Command Prompt Here"?! It is a convinient tool from
the Powertoys collection to start a Dos shell from the context menu of
any folder (right click on it). The current directory is automatically
set to this folder.

I tried to install something similiar for Cygwin: "Bash Here" should
start a cygwin bash shell from a folders context menu.

The three installation steps, as described at the end of this posting,
works but it is not perfect.

Because some MSDOS routines are involved, the currend directory is
shortened: "c:/Progra~1" instead of "c:/Program Files". This is
cosmetic and has no functional drawback, but looks ugly.  Also, the
window looks like a dos window and does not have that nice cygwin icon
in upper left edge (at least on my Win98SE installation).

Another thing, I am not sure if it always works, is the supposition of
mounted drives: c:, d: etc. On my installation it works great, e.g.
putting a CD into the drive and suddenly e: is available like magic. I
am not sure, if this is the case for all cygwin installations. You
might have to mount all the drives you want to use with BashHere
manually.

Here are the steps to Install BashHere (sorry, no skript):

1. Edit Registry

Start regedit.exe.

For Win98 add the following key:

HKEY_CLASSES_ROOT\Directory\shell\BashHere="Bash Here"
HKEY_CLASSES_ROOT\Directory\shell\BashHere\command="C:\\WINDOWS\\COMMAND.COM
/E:4096 /c C:\\cygwin\\cygwin.bat %1"

For WinXP add these:

HKEY_CLASSES_ROOT\Directory\shell\BashHere="Bash Here"
HKEY_CLASSES_ROOT\Directory\shell\BashHere\command="C:\\WINDOWS\\System32\\COMMAND.COM
/E:4096 /c C:\\cygwin\\cygwin.bat %1"

Please adjust the path to cygwin.bat if necessary.

Finish regedit.

Now right click on a folder, to open its context menu. You will see
the entry "Bash Here". When you use it, it will start the shell, but
still with your home directory as current ($PWD).

2. Edit cygwin.bat in c:/cygwin

This batch starts the bash shell with the last command line "bash...".
Insert "set BASHHERE=%1" the line before.

This Environment variable now contains the comlete path of the opened
folder and is availabile in the bash shell (echo $BASHHERE).

3. Edit profile 

Make $BASHHERE the current directory by adding the following line to
/etc/profile or ~/.profile:

if [ "$BASHHERE" != "" ]; then
    cd $( echo $BASHHERE | tr "\134" /)
fi

The "tr" replaces \ against /.

That's all, have fun.

Any suggestions or improvements are appreciated! 

regards Martin 

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: Bash Here - Start Cygwin from a folders context menu
@ 2002-05-28 10:57 Thomas Schweikle
  2002-05-29 11:20 ` Peter A. Castro
  0 siblings, 1 reply; 15+ messages in thread
From: Thomas Schweikle @ 2002-05-28 10:57 UTC (permalink / raw)
  To: Gerrit P. Haase; +Cc: cygwin

Hi!



Bitte antworten an "Gerrit P. Haase" <gerrit@familiehaase.de>
Gesendet von:   cygwin-owner@cygwin.com
An:     David Starks-Browning <starksb@ebi.ac.uk>
Kopie:  cygwin@cygwin.com 
Thema:  Re: Bash Here - Start Cygwin from a folders context menu

>> I'd like it to work before I reference it in the FAQ.

Fine!

> Well, it was some fiddeling.
> It worked well but now as I tried
> to reinstall, it doesn't work on
> mounted drives anymore:-(

I've done it some time ago. Here's what I did:

first I took a close look on how others where dooing it. Then created a 
file:
--- start of "bash-here.reg" ---
REGEDIT4

[HKEY_CLASSES_ROOT\Drive\shell\bashHere]
@="Shell: bash prompt here"

[HKEY_CLASSES_ROOT\Drive\shell\bashHere\command]
@="C:\\Programme\\Cygwin\\cygwin.bat \"%1\""


[HKEY_CLASSES_ROOT\Directory\shell\bashHere]
@="Shell: bash prompt here"

[HKEY_CLASSES_ROOT\Directory\shell\bashHere\command]
@="C:\\Programme\\Cygwin\\cygwin.bat \"%1\""
--- end of "bash-here.reg" ---


Next "cygwin.bat" was modified:
--- start of "cygwin.bat" ---
@echo off

C:
chdir \Programme\cygwin\bin
echo cd %1 | sed -e "s#\(.\):\(.*\)#/cygdrive/\1\2#" -e "s#\\\\#/#g" > 
%HOMEDRIVE%\.bashcd

bash --login -i
--- end of "cygwin.bat" ---


And last a change to "/etc/profile":
--- start of "/etc/profile" ---
PATH="/usr/local/bin:/usr/bin:/bin:$PATH"

USER="`id -un`"

# Set up USER's home directory
if [ -z "$HOME" ]; then
  HOME="/home/$USER"
fi

if [ ! -d "$HOME" ]; then
  mkdir -p "$HOME"
fi

export HOME USER

for i in /etc/profile.d/*.sh ; do
  if [ -f $i ]; then
    . $i
  fi
done

export MAKE_MODE=unix
export PS1='\[\033]0;\w\007
\033[32m\]\u@\h \[\033[33m\w\033[0m\]
$ '

cd "$HOME"

test -f ./.bashrc && . ./.bashrc
test -f ./.bashcd && . ./.bashcd && rm -f $HOME/.bashcd
--- end of "/etc/profile" ---


Since I am using tcsh too, I've done it for tcsh too:
--- start of "tcsh-here.reg" ---
REGEDIT4

[HKEY_CLASSES_ROOT\Drive\shell\cshHere]
@="Shell: tcsh prompt here"

[HKEY_CLASSES_ROOT\Drive\shell\cshHere\command]
@="C:\\Programme\\cygwin\\bat\\tcsh.bat \"%1\""


[HKEY_CLASSES_ROOT\Directory\shell\cshHere]
@="Shell: tcsh prompt here"

[HKEY_CLASSES_ROOT\Directory\shell\cshHere\command]
@="C:\\Programme\\cygwin\\bat\\tcsh.bat \"%1\""
--- end of "tcsh-here.reg" ---


--- start of "tcsh.bat" ---
@echo off

C:
chdir \Programme\cygwin\bin
echo cd %1 | sed -e "s#\(.\):\(.*\)#/cygdrive/\1\2#" -e "s#\\\\#/#g" > 
%HOMEDRIVE%\.bashcd

tcsh -l
--- end of "tcsh.bat" ---

--- start of "/etc/csh.login" ---
#
# Example /etc/csh.login for Cygwin
#
unsetenv TEMP
unsetenv TMP

set path=( /usr/local/bin /usr/bin /bin $path )

if ( ! ${?USER} ) then
  set user="`id -un`"
endif
if ( ! ${?HOME} ) then
  set home=/home/$USER
endif
if ( ! -d "$HOME" ) then
  mkdir -p "$HOME"
endif

if ( ! ${?TERM} || "$TERM" == "unknown"  || "$tty" == "conin" ) then
  set TERM=linux
endif

setenv MAKE_MODE unix

umask 022

cd ~
if ( -f ".bashcd" ) then
  source ./.bashcd
  rm -f "$HOME/.bashcd"
endif
--- end of "/etc/csh.login" ---


For W2K cmd.exe it is less complicated. You only need registry settings 
since it is not neccessary to replace '\' with '/' and substitute 'c:' 
with '/cygdrive/c' and there is an option telling cmd.exe to execute a 
commandline given command, then go to interactive mode:
--- start of "cmd-here.reg" ---
REGEDIT4

[HKEY_CLASSES_ROOT\Drive\shell\DosHere]
@="Shell: CMD &prompt here"

[HKEY_CLASSES_ROOT\Drive\shell\DosHere\Command]
@="C:\\WINNT\\System32\\cmd.exe /k cd \"%1\""

[HKEY_CLASSES_ROOT\Directory\shell\DosHere]
@="Shell: CMD &prompt here"

[HKEY_CLASSES_ROOT\Directory\shell\DosHere\Command]
@="C:\\WINNT\\System32\\cmd.exe /k cd \"%1\""
--- end of "cmd-here.reg" ---


Neccessary changes for zsh I leave upto the reader ;-)

-- 
Thomas


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 15+ messages in thread
* RE: Bash Here - Start Cygwin from a folders context menu
@ 2002-05-30 17:54 Kilroy, David
  2002-05-30 19:20 ` Gerrit P. Haase
  0 siblings, 1 reply; 15+ messages in thread
From: Kilroy, David @ 2002-05-30 17:54 UTC (permalink / raw)
  To: 'cygwin@cygwin.com'

[-- Attachment #1: Type: text/plain, Size: 1665 bytes --]


From the recent discussion, I thought it a little silly that all the
different incantations only worked for a particular shell/window combo.
After a read of some older mailing list stuff discussing different ways of
doing things I came up with a few modifications to the files Gerrit posted
[diffs attached]

It allows you to do any of:
./install bash
./install rxvt
./install [batch]

And goes off and sets up your registry (and start up files in the case of
batch) to do things in your preferred method.

It is relatively easy to add command line incantations for other shells so
that they can be provided for as well.

Also:
1) Tries to leverage any existing cygwin.bat to create cygwin_indir.bat, if
thats what you want.
2) Stops repeated additions to ~/.bashrc for repeated installs
3) handles missing ~/.bashrc
4) Uses bare bones rxvt startup line so the users .Xdefaults are used

Gerrit, would you be interested in adding these changes (or similar) to the
file you're already hosting? The FAQ can then deal with "but I want Cygwin
Prompt Here to start ?sh, not bash" [assuming appropriate incantations are
added].


Dave.

Old thread reference:
http://sources.redhat.com/ml/cygwin/2002-04/msg00647.html


> From: Gerrit P. Haase [mailto:freeweb@nyckelpiga.de]
> Subject: Re: Bash Here - Start Cygwin from a folders context menu
> 
> Fetch the original from Glen Coakley:
> http://www.users.qwest.net/~weissj/Cygwin/CygwinAddons.html
> 
> AND please fetch the diff here:
> http://koeln.convey.de/cywgin/CygwinPromptHere/
> 
> Or fetch the ready patched package at my site.
>
http://koeln.convey.de/cywgin/CygwinPromptHere/CygwinPromptHere-20020528.tar
.gz


[-- Attachment #2: cphinf.diff --]
[-- Type: application/octet-stream, Size: 606 bytes --]

--- CygwinPromptHere.inf.tpl.orig	2002-05-28 10:02:06.000000000 -0400
+++ CygwinPromptHere.inf.tpl	2002-05-30 12:54:40.000000000 -0400
@@ -63,5 +63,7 @@
 CygwinPromptHereName="Cygwin Prompt Here PowerToy"
 CygwinPromptHereAccel="Cy&gwin Prompt Here PowerToy"
 UDHERE="Software\Microsoft\Windows\CurrentVersion\Uninstall\CygwinPromptHere"
+BATCH_SHELL_CMD="cygwin_indir.bat ""%1"""
+CMD_BASH_SHELL_CMD="bin\bash.exe --login -c ""cd '%1'; exec bash"""
+RXVT_BASH_SHELL_CMD="bin\rxvt.exe -e /bin/bash.exe --login -c ""cd '%1'; exec bash"""
 CYGWIN_ROOT=
-CYGWIN_SHELL_CMD="cygwin_indir.bat ""%1"""

[-- Attachment #3: install.diff --]
[-- Type: application/octet-stream, Size: 5860 bytes --]

--- install.orig	2002-05-28 10:02:06.000000000 -0400
+++ install	2002-05-30 13:45:17.000000000 -0400
@@ -11,13 +11,27 @@
 
 This 'install' will adapt to the version of Windows that you are using and
 locate your cygwin root directory. It will modify the registry entries for
-Drives and Directories under HKEY_CLASSES_ROOT, add a cygwin_indir.bat file in
+Drives and Directories under HKEY_CLASSES_ROOT. 
+
+The following are valid options:
+    bash - start bash from the default command shell
+    rxvt - start bash under rxvt
+    batch - run a batch file based on the current /cygwin.bat (default)
+
+Under batch, I will add a cygwin_indir.bat file in
 your cygwin root directory and append a few lines to your .bashrc. 
 
 The changes to your .bashrc will only be executed if you are running under
-cygwin (I share my .bashrc with my Unix box.) 
+cygwin (I share my .bashrc with my Unix box.) Also these changes will not 
+be run under other user profiles.
+
+The advantage of using the options bash or rxvt is that no temporary files are
+used, and the extra command invocation in memory is spared. The rxvt command
+used is a bare bones 'rxvt -e bash', so your preferences should go into
+~/.Xdefaults
 
 EOF
+# Add an odd apostrophe to stop the 'comment' leaking when viewing in xemacs'
 
 #################### Are you sure you want to do this? ####################
 PROMPT="Would you like to continue? [y/n]"
@@ -35,14 +49,36 @@
 fi
 echo ""
 
-CYGWIN_ROOT_DOS=`regtool get 'HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/\native'`
-CYGWIN_ROOT_CYGWIN=`cygpath -u $CYGWIN_ROOT_DOS`
-CYGWIN_ROOT_DOS=`cygpath -w $CYGWIN_ROOT_DOS`
+CYGWIN_ROOT_CYGWIN=/
+CYGWIN_ROOT_DOS=`cygpath -w $CYGWIN_ROOT_CYGWIN`
 
-#################### Make necessary additions to .bashrc ####################
+case $1 in
+batch)
+    DESIRED_SHELL=%BATCH_SHELL_CMD%
+;;
+cmd-bash | bash)
+    DESIRED_SHELL=%CMD_BASH_SHELL_CMD%
+;;
+rxvt-bash | rxvt)
+    DESIRED_SHELL=%RXVT_BASH_SHELL_CMD%
+;;
+# Add you preferred windowing/shell combo here
+# and then add appropriate start up line to .inf.tpl
+*)
+    DESIRED_SHELL=%BATCH_SHELL_CMD%
+;;
+esac
+
+# Only modify/create ./bashrc and cygwin_indir.bat if running from a batch file
+# otherwise things are handled in the registry and this isn't required
+if [ "$DESIRED_SHELL" = "%BATCH_SHELL_CMD%" ]
+then
 
-if [ `grep -c BPH_TEMP_FILE $HOME/.bashrc` = 0 ]; then
-  cat <<EOF >> $HOME/.bashrc
+#################### Make necessary additions to .bashrc ####################
+# create it if necesary
+  touch $HOME/.bashrc
+  if [ `grep -c /tmp/bphdir.tmp $HOME/.bashrc` = 0 ]; then
+    cat <<EOF >> $HOME/.bashrc
 
 # Additions for "Cygwin Prompt Here" functionality
 if [ -r /tmp/bphdir.tmp ]; then
@@ -52,38 +88,36 @@
 # End of: Additions for "Cygwin Prompt Here" functionality
 
 EOF
-fi
-
-#################### Create and install the .inf file ####################
-# sed/shell quoting -- Ugh!
-CYGWIN_ROOT_DOS_ESCAPED=`echo "$CYGWIN_ROOT_DOS" | sed -e 's;\\\\;\\\\\\\\;g'`
-sed -e "s;\(CYGWIN_ROOT=\);\\1\"$CYGWIN_ROOT_DOS_ESCAPED\";g" \
-	< CygwinPromptHere.inf.tpl > CygwinPromptHere.inf
-
-CYG_COMSPEC=`cygpath -u $COMSPEC`
-INSTALL_CMD=`regtool get 'HKEY_CLASSES_ROOT\inffile\shell\Install\command\' \
-	    | sed -e 's; %1;;g'`
-DOS_PWD=`cygpath -w -a "$PWD"`
-
-# Windows (2000) looks for the exact filename specified in the .inf file.
-$CYG_COMSPEC /c start $INSTALL_CMD $DOS_PWD\\CygwinPromptHere.inf
+  fi
 
 #################### Create cygwin_indir.bat ####################
 
 # old CYGWIN_DRIVE=`echo $CYGWIN_ROOT_DOS | cut -d'\\' -f1`
-CYGWIN_DRIVE=`echo $CYGWIN_ROOT_DOS | cut -d: -f1`:
-CYGWIN_DIR=`echo $CYGWIN_ROOT_DOS | cut -d: -f2`
+  CYGWIN_DRIVE=`echo $CYGWIN_ROOT_DOS | cut -d: -f1`:
+  CYGWIN_DIR=`echo $CYGWIN_ROOT_DOS | cut -d: -f2`
 
 # Backup old file
-if [ -r /cygwin_indir.bat ]
-then
+  if [ -r /cygwin_indir.bat ]
+  then
     TODAY=`date +'%Y%m%d'`
     cp /cygwin_indir.bat /cygwin_indir.${TODAY}.bat
     echo "A copy of the existing file '/cygwin_indir.bat' has been saved as:"
     echo "/cygwin_indir.${TODAY}.bat."
-fi
+  fi
 
-cat <<EOF > /cygwin_indir.bat
+# if the standard cygwin.bat exists, pass it through sed to get cygwin_indir.bat
+# so we retain the users options/preferences. Try and cygpath after cding to /bin
+# else create it
+  if [ -x /cygwin.bat ]
+  then
+    cat <<EOF > batch.sed
+/\(\(cd\|chdir\).*bin\)[[:space:]]*$/I a\\
+cygpath -u %1> ..\\\\tmp\\\\bphdir.tmp
+EOF
+    sed -f batch.sed /cygwin.bat > /cygwin_indir.bat
+    rm batch.sed
+  else
+    cat <<EOF > /cygwin_indir.bat
 @echo off
 title Cygwin Bash Shell
 
@@ -91,12 +125,28 @@
 cd $CYGWIN_DIR\bin
 cygpath -u %1> $CYGWIN_ROOT_DOS\tmp\bphdir.tmp
 
-rxvt -sr -sl 2500 -fg lightblue -geometry 90x30 -bg midnightblue -sb -tn rxvt  -fn "Lucida Console-14" -e /usr/bin/bash --login -i
+bash --login -i
 
 exit
 EOF
+  fi
+  chmod a+x /cygwin_indir.bat
+fi
+
+#################### Create and install the .inf file ####################
+# sed/shell quoting -- Ugh!
+CYGWIN_ROOT_DOS_ESCAPED=`echo "$CYGWIN_ROOT_DOS" | sed -e 's;\\\\;\\\\\\\\;g'`
+sed -e "s;\(CYGWIN_ROOT=\);\\1\"$CYGWIN_ROOT_DOS_ESCAPED\";g" -e "s;%CYGWIN_SHELL_CMD%;$DESIRED_SHELL;g" \
+	< CygwinPromptHere.inf.tpl > CygwinPromptHere.inf
+
+CYG_COMSPEC=`cygpath -u $COMSPEC`
+INSTALL_CMD=`regtool get 'HKEY_CLASSES_ROOT\inffile\shell\Install\command\' \
+	    | sed -e 's; %1;;g'`
+DOS_PWD=`cygpath -w -a "$PWD"`
+
+# Windows (2000) looks for the exact filename specified in the .inf file.
+$CYG_COMSPEC /c start $INSTALL_CMD $DOS_PWD\\CygwinPromptHere.inf
 
-chmod a+x /cygwin_indir.bat
 
 #################### Installation Complete ####################
 


[-- Attachment #4: Type: text/plain, Size: 214 bytes --]

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: Bash Here - Start Cygwin from a folders context menu
@ 2002-10-03  4:41 glen.coakley
  0 siblings, 0 replies; 15+ messages in thread
From: glen.coakley @ 2002-10-03  4:41 UTC (permalink / raw)
  To: cygwin

>> Also:
>> 1) Tries to leverage any existing cygwin.bat to create cygwin_indir.bat,
if
>> thats what you want.
>> 2) Stops repeated additions to ~/.bashrc for repeated installs
>> 3) handles missing ~/.bashrc
>> 4) Uses bare bones rxvt startup line so the users .Xdefaults are used
>>
>> Gerrit, would you be interested in adding these changes (or similar) to
the
>> file you're already hosting? The FAQ can then deal with "but I want
Cygwin
>> Prompt Here to start ?sh, not bash" [assuming appropriate incantations
are
>> added].
>
>Yes, sure.  It was a little mess with cleaning up .bashrc all the time;)
>I'll look to get it up to the server this weekend.
>
>Someone who is using tcsh and zsh needs to assist me in testing since
>I'm not using these two (yet).
>
>If I get it right now it is still not possible to get two extensions at
>the same time?  So if I want to have a 'bash Prompt Here' (cmd shell) and
>a 'rxvt Prompt Here' I'll need two different startup files?

I added these updates to my own archive including allowing any number of the
'extensions' to be installed at once and uninstalled separately. A .inf file
is built on-the-fly for each extension.

I also fixed the uninstall so that it doesn't leave the extra registry keys
around. This seems to be a bug from the original DOS Prompt Here power toy.

The file is available at www.glencoakley.org. Enter the site and find the
Cygwin link. I don't recommend linking directly to it because my site host
has changed twice since this I created this and I am trying to set up a
system to host it myself. But, I own the domain and don't plan on changing
that.

You will find that the old link below still works but has NOT been updated.
This is because I don't have an account with that ISP anymore but they
haven't bothered to purge the files yet.

>>> Fetch the original from Glen Coakley:
>>> http://www.users.qwest.net/~weissj/Cygwin/CygwinAddons.html

I am not on the list so please send/copy any replies to me directly.

Glen

--------------------------------------
Glen Coakley, Senior Software Engineer
WebSite: www.GlenCoakley.org


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2002-10-03 11:41 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-28  1:41 Bash Here - Start Cygwin from a folders context menu Martin Gramatke
2002-05-28  2:59 ` Michael Hoffman
2002-05-28  4:32   ` Martin Gramatke
2002-05-28  8:30   ` Gerrit P. Haase
2002-05-28  9:14     ` David Starks-Browning
2002-05-28  9:30       ` Gerrit P. Haase
2002-05-28 10:52         ` Gerrit P. Haase
2002-05-28 10:20   ` David T-G
2002-05-28 13:30     ` Michael A Chase
2002-05-28 13:37       ` David T-G
2002-05-28 10:57 Thomas Schweikle
2002-05-29 11:20 ` Peter A. Castro
2002-05-30 17:54 Kilroy, David
2002-05-30 19:20 ` Gerrit P. Haase
2002-10-03  4:41 glen.coakley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).