Clean up Makefile
[chere.git] / src / xhere
blob5c8308586a1add4a1ad6e5bc48886fe9d9f97a02
1 #!/bin/bash
2 # Have to use bash; can't get ash to "exec -l"
3 # Separate script from chere to avoid need for argument parsing
5 # first arg is shell
6 # second arg is the path
8 # Dave Kilroy
9 # Nov 2011
11 VERSION=1.4
12 # HISTORY PRIOR TO GIT
13 #VERSION=1.2
14 # Add support for dash
15 # Add support for mksh
16 #VERSION=0.7
17 # Run normally if /bin is not in path
18 # Thanks to Dave Griffin
19 # Don't complain if second arg not present. Assume we are in the correct
20 # directory. This allows compatibility with previous versions of chere.
21 #VERSION=0.6
22 # Fix a couple typos
23 # cd to second arg to handle invocation from RH explorer pane
24 # If the second arg is not a valid directory, guess a network path since
25 # we will always lose the \\ prefix
26 #VERSION=0.4
27 # First version, tied into chere version
29 # Would have the second arg as a directory to cd to, but the directory
30 # can't be quoted correctly for netork paths
32 # Fully specify paths to binaries, as /bin is not necessarily in the path
33 CYGPATH=/bin/cygpath
34 SED=/bin/sed
35 ID=/bin/id
36 GETENT=/bin/getent
38 if [ -z $1 ]; then
39 echo An argument is required, specifying the shell to invoke as a login shell
40 exit
41 elif [ $1 == -h ]; then
42 echo This script is not intended to be invoked from the command line. Try chere -h
43 exit
46 # Instead, just set a variable indicating to the login shells not to cd $HOME
47 export CHERE_INVOKING=true
49 # Goto the desired directory.
50 # This is necessary when the context menu is opened in the RH pane
51 if [ ! -z "$2" ]; then
52 CHERE_DIR=`$CYGPATH "$2"`
53 NETWORK_PATH=/$CHERE_DIR
54 if [ -d "$CHERE_DIR" ]; then
55 cd "$CHERE_DIR"
57 # If the full path doesn't exist, this is prob a network path
58 elif [ -d "$NETWORK_PATH" ]; then
59 cd "$NETWORK_PATH"
62 # If that doesn't exist then the current should be the desired directory
64 if [ $1 = /etc/passwd ]; then
65 user=`$ID -un`
66 scmd=`$GETENT passwd $user | $SED -n "s?.*:\(.*\)?\1?gp"`
67 set -- $scmd
70 # Replace this bash with a login shell
71 # but only if we recognise the shell
72 case $1 in
73 /bin/sh* | /bin/bash* | /bin/pdksh* | /bin/posh* | /bin/tcsh* | /bin/zsh* | /bin/dash* | /bin/mksh* | /bin/fish* )
74 echo Starting $1;
75 exec -l $1;;
76 * )
77 echo Do not recognise $1;;
78 esac