RSS

Schlagwort-Archive: cygwin

Cygwin Bash aus ausgewähltem Explorer Verzeichnis starten

Cygwin Bash aus ausgewähltem Explorer Verzeichnis starten

Original: http://snippets.dzone.com/posts/show/10227

Want to launch a bash shell in any directory using the Windows Explorer context menu? This is how I did it, tweaking the basic method described here. This should work even for paths that have spaces or for UNC paths.

1. Edit Registry
– Start regedit.exe.
– Add these key/values:
HKEY_CLASSES_ROOTDirectoryshellBashHere=bash here
HKEY_CLASSES_ROOTDirectoryshellBashHerecommand=

cmd.exe /c C:cygwincygwin.bat "%1"

Note the quotation marks around „%1“.
Please adjust the path to cygwin.bat if necessary.

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 complete path of the opened
folder and is available in the bash shell (echo $BASHHERE).

3. Edit profile

Make $BASHHERE the current directory by adding the following line to
/etc/profile or ~/.profile. (I’d replace your line cd „${HOME}“ with the following):

  if [ "$BASHHERE" != "" ]; then
    cd "$(cygpath -u "$(echo $BASHHERE | tr -d "42")")"
  else
    cd "${HOME}"
  fi

The „tr -d“ deletes enclosing quotes, which cygpath can’t deal with for some reason when embedded in $BASHHERE. Maybe there’s a simpler way, but this way worked for me.

(For UNC paths, cmd.exe complains when you launch cygwin.bat, but it dutifully passes on the argument.)

 
3 Kommentare

Verfasst von - Dezember 15, 2011 in Linux, Windows

 

Schlagwörter: ,

 
Erstelle eine Website wie diese mit WordPress.com
Jetzt starten