Add support for fish shell
[chere.git] / src / xhere
blob75697414d2cd939b1f17dee8aefec689c6fd809a
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.2
12 # Add support for dash
13 # Add support for mksh
14 #VERSION=0.7
15 # Run normally if /bin is not in path
16 # Thanks to Dave Griffin
17 # Don't complain if second arg not present. Assume we are in the correct
18 # directory. This allows compatibility with previous versions of chere.
19 #VERSION=0.6
20 # Fix a couple typos
21 # cd to second arg to handle invocation from RH explorer pane
22 # If the second arg is not a valid directory, guess a network path since
23 # we will always lose the \\ prefix
24 #VERSION=0.4
25 # First version, tied into chere version
27 # Would have the second arg as a directory to cd to, but the directory
28 # can't be quoted correctly for netork paths
30 # Fully specify paths to binaries, as /bin is not necessarily in the path
31 CYGPATH=/bin/cygpath
32 SED=/bin/sed
33 ID=/bin/id
35 if [ -z $1 ]; then
36 echo An argument is required, specifying the shell to invoke as a login shell
37 exit
38 elif [ $1 == -h ]; then
39 echo This script is not intended to be invoked from the command line. Try chere -h
40 exit
43 # Instead, just set a variable indicating to the login shells not to cd $HOME
44 export CHERE_INVOKING=true
46 # Goto the desired directory.
47 # This is necessary when the context menu is opened in the RH pane
48 if [ ! -z "$2" ]; then
49 CHERE_DIR=`$CYGPATH "$2"`
50 NETWORK_PATH=/$CHERE_DIR
51 if [ -d "$CHERE_DIR" ]; then
52 cd "$CHERE_DIR"
54 # If the full path doesn't exist, this is prob a network path
55 elif [ -d "$NETWORK_PATH" ]; then
56 cd "$NETWORK_PATH"
59 # If that doesn't exist then the current should be the desired directory
61 if [ $1 = /etc/passwd ]; then
62 user=`$ID -un`
63 scmd=`$SED -n "s?$user:.*:\(.*\)?\1?gp" /etc/passwd`;
64 set -- $scmd
67 # Replace this bash with a login shell
68 # but only if we recognise the shell
69 case $1 in
70 /bin/sh* | /bin/bash* | /bin/pdksh* | /bin/posh* | /bin/tcsh* | /bin/zsh* | /bin/dash* | /bin/mksh* | /bin/fish* )
71 echo Starting $1;
72 exec -l $1;;
73 * )
74 echo Do not recognise $1;;
75 esac