This is the mail archive of the
cygwin-apps@cygwin.com
mailing list for the Cygwin project.
[ITP] chere
- From: Dave <d_inabox at yahoo dot com>
- To: cygwin-apps at cygwin dot com
- Date: Mon, 4 Oct 2004 10:12:07 -0700 (PDT)
- Subject: [ITP] chere
Recent traffic in the main mailing list indicated a package to manage Cygwin
Prompt Here functionality would be appreciated.
I propose contributing (and maintaining) a shell script to do this. See the
attached script for my initial version. It works as advertised on my W2K box,
installing and uninstalling a Bash/Rxvt context menu.
It needs some work, and input from term/shell maintainers on appropriate startup
incantations. I'd welcome any comments and feedback.
Is this going in the right direction? Has someone got a more appropriate
solution in the wings (I'm aware of Gerrits and a few other implementations)? Am
I wasting my time?
Dave.
Hints:
./chere -h
to get some help.
./chere -p -t rxvt -s bash
to print the commands to install Bash/Rxvt on stdout
./chere -t rxvt -s bash
to install Bash/Rxvt context menu
./chere -u -t rxvt
to uninstall Bash/Rxvt context menu
__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail
#!/bin/bash
#
# This shell script (un)installs Cygwin Prompt Here functionality.
# Requires: regtool
#
# TODO
# ----
# 1. Transform to ash syntax, so bash isn't required
# Problem with ash builtin getopts? I have an old ash...
# 2. Fix quoting
# 3. Can we pick the shell from /etc/passwd at runtime?
#
# Dave Kilroy
# Oct 2004
#
VERSION=0.1
# Initial implementation.
# Bash required.
# Possible quoting problems.
# Windows uninstall only posible if script present
# Xterm command not known
# Only Bash startup command verified
# Need to use eval to force correct quote evaluation
REGTOOL="eval regtool"
REGTOOL_=regtool
KNOWN_TERMS="cmd rxvt xterm"
KNOWN_SHELLS="ash bash cmd pdksh tcsh zsh"
ACTION=i
DO_WIN_UINST=t
FORCE=f
####################### Parse command line #######################
while getopts aciunmpfht:s: ARG ; do
case $ARG in
( a ) USERS=a;;
( c ) USERS=c;;
( i ) ACTION=i;;
( u ) ACTION=u;;
( n ) DO_WIN_UINST=t;;
( m ) DO_WIN_UINST=f;;
( p ) REGTOOL="echo regtool";;
( t ) this_term=$OPTARG;;
( s ) this_shell=$OPTARG;;
( f ) FORCE=t;;
( h ) cat <<-EOF
$0 version $VERSION
Usage:
$0 [-aciunmfph] -t <term> -s <shell>
Adds the stated terminal/shell combination to the folder context menu.
This allows you to right click a folder in Windows Explorer and open a
Cygwin shell in that folder.
You will require appropriate access rights for this to work. i.e. you
probably need to have Administrator rights.
Options:
a - All Users (Default)
c - Current User [Not Implemented. Is it possible?]
i - Install (Default)
u - Uninstall
n - Be Nice and provide Control Panel uninstall option (Default)
m - Minimal, no Control Panel uninstall
f - Force write
p - Print regtool commands to stdout rather than running them
h - Help
Supported terminals:
$KNOWN_TERMS
Supported shells:
$KNOWN_SHELLS
Example:
$0 -t rxvt -s tcsh
EOF
exit;;
esac
done
# Check windows version and cygwin install directory
VER=`uname -s`
CYG_DIR=`cygpath -m /`
#################### Define terminals ########################
# For each terminal, indicate how to start it in TERM_CMD,
# with the last option set for the following text to be the initial
# command to start the shell.
if [ $ACTION = i ]; then
case $this_term in
( cmd )
if [ VER = "CYGWIN_NT*" ]; then
TERM_CMD="cmd /k";
else
TERM_CMD="command /k";
fi;;
( rxvt )
TERM_CMD="$CYG_DIR/bin/rxvt.exe -e";;
( xterm )
TERM_CMD="$CYG_DIR/bin/xterm.exe";;
( * )
echo $0 Error: Unknown terminal $this_term
echo Supported terminals:
echo $KNOWN_TERMS
exit;;
esac
fi
#################### Define shells #############################
# For each shell, indicate the command that should be used to
# start it in the directory %1, and keep it open.
#
case $this_shell in
( bash )
SHELL_CMD="$CYG_DIR/bin/bash --login -c \\\"cd '%1'; exec bash\\\""
ACCEL="&Bash Here"
CPH_DESC="Cygwin Bash Prompt Here";;
( ash )
SHELL_CMD="$CYG_DIR/bin/sh -c \\\"cd '%1'; exec sh\\\"";
ACCEL="&Ash Here"
CPH_DESC="Cygwin Ash Prompt Here";;
( pdksh )
SHELL_CMD="$CYG_DIR/bin/pdksh -c \\\"cd '%1'; exec pdksh\\\""
ACCEL="&Pdksh Here"
CPH_DESC="Cygwin Pdksh Prompt Here";;
( tcsh )
SHELL_CMD="$CYG_DIR/bin/tcsh -c \\\"cd '%1'; exec tcsh\\\""
ACCEL="&Tcsh Here"
CPH_DESC="Cygwin Tcsh Prompt Here";;
( zsh )
SHELL_CMD="$CYG_DIR/bin/zsh -c \\\"cd '%1'; exec zsh\\\""
ACCEL="&Zsh Here"
CPH_DESC="Cygwin Zsh Prompt Here";;
( cmd )
# Note this doesn't work well if the folder is not on C:
# You also need to switch directories
SHELL_CMD="cd '%1'"
ACCEL="&Command Prompt Here"
CPH_DESC="Command Prompt Here (cygwin)";;
( * )
echo $0 Error: Unknown shell $this_shell
echo Supported shells:
echo $KNOWN_SHELLS
exit;;
esac
# Identify the registry keys for each OS
# Same for all?
DIR_KEY=/HKCR/Directory/Shell
DRIVE_KEY=/HKCR/Drive/Shell
UINST_KEY=/HKLM/Software/Microsoft/Windows/CurrentVersion/Uninstall
if [ $ACTION = i ]; then
####### Install ###########
if [ $FORCE = t ] || ! $REGTOOL_ check $DRIVE_KEY/cygwin_$this_term 2> /dev/null ; then
# Add Registry Key for Drives
$REGTOOL add $DRIVE_KEY/cygwin_$this_term
$REGTOOL -s set $DRIVE_KEY/cygwin_$this_term/ \"$ACCEL\"
$REGTOOL add $DRIVE_KEY/cygwin_$this_term/command
$REGTOOL -s set $DRIVE_KEY/cygwin_$this_term/command/ \"$TERM_CMD $SHELL_CMD\"
fi
if [ $FORCE = t ] || ! $REGTOOL_ check $DIR_KEY/cygwin_$this_term 2> /dev/null; then
# Add Registry Key for Directories/Folders
$REGTOOL add $DIR_KEY/cygwin_$this_term
$REGTOOL -s set $DIR_KEY/cygwin_$this_term/ \"$ACCEL\"
$REGTOOL add $DIR_KEY/cygwin_$this_term/command
$REGTOOL -s set $DIR_KEY/cygwin_$this_term/command/ \"$TERM_CMD $SHELL_CMD\"
fi
if [ $DO_WIN_UINST = t ]; then
# Add uninstall registry entry
if [ $FORCE = t ] || ! $REGTOOL_ check $UINST_KEY/cygwin_$this_term 2> /dev/null ; then
# Actually, should create an .inf so windows can get rid of the menu entries
# even after the cygwin directory is wiped :(
$REGTOOL add $UINST_KEY/cygwin_$this_term
$REGTOOL -s set $UINST_KEY/cygwin_$this_term/DisplayName \"$CPH_DESC\"
$REGTOOL -s set $UINST_KEY/cygwin_$this_term/UnInstallString \"$CYG_DIR/bin/bash -c \\\"$CYG_DIR/bin/chere -u -s $this_shell\\\"\"
fi
fi
elif [ $ACTION = u ]; then
###### UnInstall ##########
# Assumed that regtool will remove subkeys recursively
$REGTOOL remove $DRIVE_KEY/cygwin_$this_term/command
$REGTOOL remove $DRIVE_KEY/cygwin_$this_term
$REGTOOL remove $DIR_KEY/cygwin_$this_term/command
$REGTOOL remove $DIR_KEY/cygwin_$this_term
$REGTOOL remove $UINST_KEY/cygwin_$this_term
fi