Bash PS1: Correctly enclose nonprintable sections
[msysgit.git] / etc / profile
blobc406ad298fc1b680a2e0688bc2d41c47efb7042a
1 # Copyright (C) 2001, 2002  Earnie Boyd  <earnie@users.sf.net>
2 # This file is part of the Minimal SYStem.
3 #   http://www.mingw.org/msys.shtml
5 #         File: profile
6 #  Description: Shell environment initialization script
7 # Last Revised: 2002.05.04
9 if [ -z "$MSYSTEM" ]; then
10   MSYSTEM=MINGW32
13 # My decision to add a . to the PATH and as the first item in the path list
14 # is to mimick the Win32 method of finding executables.
16 # I filter the PATH value setting in order to get ready for self hosting the
17 # MSYS runtime and wanting different paths searched first for files.
18 if [ $MSYSTEM == MINGW32 ]; then
19   export PATH=".:/usr/local/bin:/mingw/bin:/bin:$PATH"
20 else
21   export PATH=".:/usr/local/bin:/bin:/mingw/bin:$PATH"
24 # strip out cygwin paths from PATH
25 case "$PATH" in
26 */cygwin/*)
27         PATH="$(awk -vRS=: -vORS=: '!/cygwin/' <<< "$PATH")"
28         # awk always adds a trailing separator
29         export PATH="${PATH%:}"
30         ;;
31 esac
33 if [ -z "$USERNAME" ]; then
34   LOGNAME="`id -un`"
35 else
36   LOGNAME="$USERNAME"
39 # Set up USER's home directory
40 if [ -z "$HOME" -o ! -d "$HOME" ]; then
41   HOME="$HOMEDRIVE$HOMEPATH"
42   if [ -z "$HOME" -o ! -d "$HOME" ]; then
43     HOME="$USERPROFILE"
44   fi
47 if [ ! -d "$HOME" ]; then
48         printf "\n\033[31mERROR: HOME directory '$HOME' doesn't exist!\033[m\n\n"
49         echo "This is an error which might be related to msysGit issue 108."
50         echo "You might want to set the environment variable HOME explicitly."
51         printf "\nFalling back to \033[31m/ ($(cd / && pwd -W))\033[m.\n\n"
52         HOME=/
55 # normalize HOME to unix path
56 HOME="$(cd "$HOME" ; pwd)"
58 export PATH="$HOME/bin:$PATH"
60 export GNUPGHOME=~/.gnupg
62 if [ -z "$MAGIC" ]; then
63   magicfile=$(cd / && pwd -W)'/mingw/share/misc/magic.mgc'
64   test -f "$magicfile" && export MAGIC="$magicfile"
67 if [ "x$HISTFILE" == "x/.bash_history" ]; then
68   HISTFILE=$HOME/.bash_history
71 if [ -e ~/.inputrc ]; then
72     export INPUTRC=~/.inputrc
73 else
74     export INPUTRC=/etc/inputrc
77 case "$LS_COLORS" in
78 *rs*)
79         # Our ls may ot handle LS_COLORS inherited in a Wine process
80         unset LS_COLORS;;
81 esac
83 export HOME LOGNAME MSYSTEM HISTFILE
85 for i in /etc/profile.d/*.sh ; do
86   if [ -f $i ]; then
87     . $i
88   fi
89 done
91 export MAKE_MODE=unix
93 # Git specific stuff
94 test -e /bin/git.exe -o -e /git/git.exe || {
95         echo
96         echo -------------------------------------------------------
97         echo "Building and Installing Git"
98         echo -------------------------------------------------------
100         cd /git &&
101         make install
103         case $? in
104         0)
105                 MESSAGE="You are in the git working tree, and all is ready for you to hack."
106         ;;
107         *)
108                 MESSAGE="Your build failed...  Please fix it, and give feedback on the Git list."
109         esac
111         test -d /installer-tmp && rm -rf /installer-tmp
113         cat <<EOF
116 -------------------------
117 Hello, dear Git developer.
119 This is a minimal MSYS environment to work on Git.
121 $MESSAGE
126 # let's make sure that the post-checkout hook is installed
127 test -d /.git && test ! -x /.git/hooks/post-checkout &&
128 test -x /share/msysGit/post-checkout-hook &&
129 mkdir -p /.git/hooks &&
130 cp /share/msysGit/post-checkout-hook /.git/hooks/post-checkout
132 test -f /etc/motd && sed "s/\$MESSAGE/$MESSAGE/" < /etc/motd
133 test -x /share/msysGit/initialize.sh -a ! -d /.git &&
134 cat << EOF
136 It appears that you installed msysGit using the full installer.
137 To set up the Git repositories, please run /share/msysGit/initialize.sh
140 case ":$PATH:" in
141 *:/cmd:*|*:/bin:*) ;;
143         cat << EOF
145 In order to use Git from cmd.exe:
146 1. Add c:\msysgit\cmd to cmd's PATH
147 2. DON'T add c:\msysgit\bin or c:\msysgit\mingw\bin to cmd's PATH
148 Commands like 'git add' will work from cmd.exe now.
149 Commands like 'git-add' will NOT work. Add more wrappers as appropriate.
151 esac
154 . /git/contrib/completion/git-completion.bash
156 # non-printable characters must be enclosed inside \[ and \]
157 PS1='\[\033[0m\]'              # VT100 compat: reset all colors
158 PS1="$PS1"'$MSYSTEM:\w'        # e.g. MINGW32:/path/to/cwd
159 PS1="$PS1"'\[\007\]'           # Ascii character BEL
160 PS1="$PS1"'\n'                 # new line
161 PS1="$PS1"'\[\033[32m\]'       # change color
162 PS1="$PS1"'\u@\h '             # user@host<space>
163 PS1="$PS1"'\[\033[33m\]'       # change color
164 PS1="$PS1"'\w'                 # current working directory
165 if test -z "$WINELOADERNOEXEC"
166 then
167         PS1="$PS1"'$(__git_ps1)'   # bash function
169 PS1="$PS1"'\[\033[0m\]'        # change color
170 PS1="$PS1"'\n'                 # new line
171 PS1="$PS1"'$ '                 # prompt: always $
173 # set default options for 'less'
174 export LESS=-FRSX
175 export LESSCHARSET=utf-8
177 # set default protocol for 'plink'
178 export PLINK_PROTOCOL=ssh
180 # read user-specific settings, possibly overriding anything above
181 if [ -e ~/.bashrc ]; then
182     . ~/.bashrc
183 elif [ -e ~/.bash_profile ]; then
184     . ~/.bash_profile
185 elif [ -e /etc/bash_profile ]; then
186     . /etc/bash_profile