1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Source this script inside a bash or sh session to setup:
21 # If `install` is given as an argument, then the script sourcing is automatically inserted in the `.profile`.
23 # Final function that sets up the shell environment.
25 #echo "Install in $1:"
28 echo "$PATH" |
grep -q
"$str" ||
export PATH
="$str:$PATH"
30 echo "$MANPATH" |
grep -q
"$str" ||
export MANPATH
="$str:$MANPATH"
32 if [ -n
"$BASH" -a
-n
"$PS1" ]; then
33 .
"$1/misc/bash_completion/nit"
38 # Fast setup when invoked from .profile (see `install` at the end)
40 # Because [d]ash does not support argument to source (`.`),
41 # we pass the root dir as a local environment variable.
42 if [ -n
"$NIT_DIR" ]; then
44 return 2> /dev
/null
# `return` fails if invoked as is; i.e. not trough source (`.`)
48 # Guess the nit root directory and return it in `dirname`.
51 [ -f
"$dirname/src/nitc.nit" ] && return 0
54 [ -f
"$dirname/src/nitc.nit" ] && return 0
56 if [ -n
"$BASH_SOURCE" ]; then
57 dirname=`dirname "$BASH_SOURCE"`/..
58 [ -f
"$dirname/src/nitc.nit" ] && return 0
61 dirname=`dirname "$0"`/..
62 [ -f
"$dirname/src/nitc.nit" ] && return 0
64 echo "Cannot find the Nit root directory. Run the script from the Nit root directory."
68 # Main method of the script.
70 # A function is used so that `return` have a sane effect
76 if [ "$1" = "install" ]; then
81 # Get the root directory
84 # Get it from the argument
86 if [ ! -f
"$dirname/src/nitc.nit" ]; then
87 if [ -d
"$dirname/" ]; then
88 echo "$dirname: not a Nit root directory"
90 echo "$dirname: not a directory"
97 __nit_env_guess ||
return 1
99 *) echo "usage: source nit_env.sh [install] [path/to/nitdir]"
104 # Get a canonical path
106 cd $dirname > /dev
/null
111 if [ -n
"$BASH" -a
"$0" = "$BASH_SOURCE" ]; then
112 echo "nit_env.sh should be sourced not executed as is. E.g. run with 'source ./nit_env.sh'"
115 # Setup the environment
118 # Register in the .profile if required
119 if [ -n
"$install" ]; then
120 local ne
="$fulldir/misc/nit_env.sh"
121 local str
="test -r \"$ne\" && NIT_DIR=\"$fulldir\" . \"$ne\""
122 if [ -f
"$HOME/.profile" ]; then
123 echo "$str" >> "$HOME/.profile"
124 echo "successfuly registered nit in .profile"
125 elif [ -f
"$HOME/.bashrc" ]; then
126 echo "$str" >> "$HOME/.bashrc"
127 echo "successfuly registered nit in .bashrc"
128 elif [ -f
"$HOME/.bash_profile" ]; then
129 echo "$str" >> "$HOME/.bash_profile"
130 echo "succesfuly registerd nit .bash_profile"
131 elif [ -f
"$HOME/.zshrc" ]; then
132 echo "$str" >> "$HOME/.zshrc"
133 echo "successfuly registered nit in .zshrc"
135 echo "$str" > "$HOME/.profile"
136 echo "couldn't find .bashrc, .bash_profile, .profile. Created .profile and registered nit in it"