Source

metasyntax / Config / bash_profile

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# -*- sh -*-

# SSH_CONNECTION is set -> remote connection
# SSH_TTY is not set -> something like scp/rsync
if [[ ! -z $SSH_CONNECTION && -z $SSH_TTY ]]; then
    # Some of the settings below can mess up scp/rsync.
    return
elif [[ $TERM = 'dumb' ]]; then
    # Probably an Emacs TRAMP session.
    return
fi

## Make sure that we're using a Bash that's at version 4.0 or higher. Some parts
## of this startup script require version 4.0 -- specifically in the support of
## associative arrays. If we can't find a Bash at 4.0 or later, then at least
## print a warning, but some stuff later is probably going to fail.

bash_req_version='4.2.*'

case "$BASH_VERSION" in
    ${bash_req_version} )
        # Do nothing.
        ;;
    *   )
        echo "Current Bash is too old (version ${BASH_VERSION})."
        case "$(${HOME}/bin/bash --version | head -n 1)" in
            *\ version\ ${bash_req_version} )
                echo "Found a newer Bash that will work."
                exec $HOME/bin/bash
                ;;
            * ) echo "WARNING: Unable to find a Bash at ${bash_req_version} or higher!" ;;
        esac
        ;;
esac

export HISTCONTROL=ignoredups
export HISTCONTROL=ignoreboth
export HISTSIZE=10001
export LC_COLLATE=POSIX
export NNTPSERVER="news.motzarella.org"

declare -A repository

repository[metasyntax]=$HOME/Repos/metasyntax

declare -A text_attr
declare -A color
declare -A color_bg
declare -A color_fg

text_attr=([reset]=0 [bold]=1 [faint]=2 [italic]=3 [underline]=4)
color=([black]=0 [red]=1 [green]=2 [yellow]=3 [blue]=4 [magenta]=5 [cyan]=6 [white]=7)

for a in "${!text_attr[@]}" ; do
    text_attr[$a]="\\e[${text_attr[$a]}m"
done

for c in "${!color[@]}" ; do
    color_fg[$c]="\\e[$(( ${color[$c]} + 30 ))m"
    color_bg[$c]="\\e[$(( ${color[$c]} + 40 ))m"
done

# Supported values: perl, scheme, text, inline
vc_info_style='text'

# Leave the default Cygwin prompt to differentiate it.
# PS1="\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$"

draw_line() {
    i=0
    while [[ $i -lt $COLUMNS ]] ; do
        echo -n ' '
        i=$(( i + 1 ))
    done
    echo -n -e '\e[0G'
}

declare -A TCV_GIT_INFO
export TCV_GIT_INFO

find_git_dir() {
    cur_dir=$(pwd)
    status=1

    if [[ -d "${TCV_GIT_INFO[dir]}/.git" ]]; then
        len=${#TCV_GIT_INFO[dir]}
        if [[ ${cur_dir:0:$len} = ${TCV_GIT_INFO[dir]} ]]; then
            return 0
        fi
    fi

    while [[ ! -d "${cur_dir}/.git" && $cur_dir != '/' ]]; do
        cur_dir=$(dirname "$cur_dir")
    done

    if [[ -d "${cur_dir}/.git" ]]; then
        unset TCV_GIT_INFO[utime]
        TCV_GIT_INFO[dir]="$cur_dir"
        return 0
    fi

    return 1
}

export_git_information() {
    if ! find_git_dir ; then
        return 1
    fi

    declare -a stat_files

    stat_files+=("${TCV_GIT_INFO[dir]}/.git/HEAD")
    stat_files+=("${TCV_GIT_INFO[dir]}/.git/FETCH_HEAD")
    stat_files+=("${TCV_GIT_INFO[dir]}/.git/ORIG_HEAD")
    stat_files+=("${TCV_GIT_INFO[dir]}/.git/refs")

    # Check for any stashes that might exist.
    if [[ -e "${TCV_GIT_INFO[dir]}/.git/refs/stash" ]]; then
        stat_files+=("${TCV_GIT_INFO[dir]}/.git/refs/stash")
    fi

    # If we already know what branch we're on, look for that ref too.
    if [[ ! -z ${TCV_GIT_INFO[branch]} ]]; then
        stat_files+=("${TCV_GIT_INFO[dir]}/.git/refs/heads/${TCV_GIT_INFO[branch]}")
    fi

    git_change_time=$(stat -c '%Y' "${stat_files[@]}" 2>/dev/null | sort -r -n | head -n 1)

    if [[ -z ${TCV_GIT_INFO[utime]} || $git_change_time -gt ${TCV_GIT_INFO[utime]} ]]; then
        TCV_GIT_INFO[branch]=$(git branch --no-color | grep '^\*' | sed -e "s/^\\*[ \t\r\n]*//" -e "s/\n\$//")
        TCV_GIT_INFO[commit]=$(git log --no-merges --abbrev-commit --date=relative -1)
        TCV_GIT_INFO[stash]=$(git stash list | grep "[Oo]n ${TCV_GIT_INFO[branch]}" | wc -l)

        TCV_GIT_INFO[commit_hex]=$(echo "${TCV_GIT_INFO[commit]}" | grep '^commit' | sed -e "s/^commit[ \t\r\n]*//" -e "s/\n\$//")
        TCV_GIT_INFO[commit_date]=$(echo "${TCV_GIT_INFO[commit]}" | grep '^Date:' | sed -e "s/^Date:[ \t\r\n]*//" -e "s/\n\$//")

        TCV_GIT_INFO[utime]=$git_change_time
    fi
}

prompt_function() {
    if export_git_information ; then
        declare -A color_config

        dir=${TCV_GIT_INFO[dir]}

        branch=${TCV_GIT_INFO[branch]}
        commit=${TCV_GIT_INFO[commit]}
        stash=${TCV_GIT_INFO[stash]}

        commit_hex=${TCV_GIT_INFO[commit_hex]}
        commit_date=${TCV_GIT_INFO[commit_date]}

        if find_git_dir && [[ -r "${dir}/.vc-prompt" ]] ; then
            source "${dir}/.vc-prompt"
        else
            color_config[master]="${text_attr[bold]}${color_bg[cyan]}${color_fg[white]}"
            color_config[default]="${text_attr[bold]}${color_bg[blue]}${color_fg[white]}"
        fi

        if [[ -z ${color_config[$branch]} ]]; then
            branch_color="${color_config[default]}"
        else
            branch_color="${color_config[$branch]}"
        fi

        branch_fmt="${branch_color} ${branch} ${text_attr[reset]}"
        commit_fmt="${commit_hex} (${commit_date})"

        case $vc_info_style in
            'scheme' )
                echo -e "((branch . $branch_fmt) (commit . $commit_fmt) (stashes . $stash))"
                ;;
            'perl' )
                echo -e "{ branch => $branch_fmt, commit => $commit_fmt, stashes => $stash }"
                ;;
            'text' )
                echo
                echo -e -n "${color_bg[white]}${color_fg[black]}"
                draw_line
                echo -e -n "${color_bg[white]}${color_fg[black]}Branch: ${branch_fmt}"
                echo -e -n "${color_bg[white]}${color_fg[black]}  Commit: ${commit_fmt}"
                echo -e    "${color_bg[white]}${color_fg[black]}  Stashes: ${stash}${text_attr[reset]}"
                ;;
            'inline' )
                echo -e -n "$branch_fmt |"
                ;;
            * )
                ;;
        esac
    fi
}

if [[ $OSTYPE != 'cygwin' ]]; then
    export PS1=' \! [ \u @ \h ] : \w > '
    # When bash has to redraw the prompt (e.g. hit C-r then C-g) it ignores
    # PROMPT_COMMAND and only uses the prompt variable. That makes things get
    # messed up in the display... I don't know how to fix it yet.
    export PROMPT_COMMAND='prompt_function'
fi

export QT_XFT=true

if [ -d /opt ]; then
    # custom-compiled software with simple configuration
    # no other environment variables need to be set
    for dir in `find /opt -maxdepth 1 -type d ! \( -name opt -or -name _* \)`; do
        if [ -d "${dir}/bin" ]; then
            export PATH="${dir}/bin:${PATH}"
        fi
    done
fi

# Special variables for doing things later.
export TCV_ARCH=$(uname -m)
export TCV_SYSTEM=$(uname -s)
export TCV_SYSTEM_LC=$(echo "${TCV_SYSTEM}" | tr [:upper:] [:lower:])
export TCV_HOST=$(hostname | sed -e 's/^\([^.]*\).*$/\1/')

if which vim >& /dev/null ; then
    export TCV_VIMPATH=$(which vim)
fi

if which gosh >& /dev/null ; then
    load_path="${repository[metasyntax]}/Libraries/Scheme/Gauche"
    if [[ -e "$load_path" ]]; then
        export GAUCHE_LOAD_PATH="$load_path"
    fi
    unset load_path
fi

if which guile >& /dev/null ; then
    load_path="${repository[metasyntax]}/Libraries/Scheme/Guile"
    if [[ -e "$load_path" ]]; then
        export GUILE_LOAD_PATH="$load_path"
    fi
    unset load_path
fi

export TCV_PROFILE=YES

if [ -d "${HOME}/bin" ]; then export PATH="$HOME/bin:${PATH}"; fi
if [ -d "/usr/local/texlive/2010/bin/${TCV_ARCH}-${TCV_SYSTEM_LC}" ]; then
    export PATH="/usr/local/texlive/2010/bin/${TCV_ARCH}-${TCV_SYSTEM_LC}:${PATH}"
fi
if [ -d "${HOME}/Haskell/bin" ]; then export PATH="$HOME/Haskell/bin:${PATH}"; fi
if [ -d "${HOME}/Libraries/Tcl" ]; then export TCLLIBPATH="${HOME}/Libraries/Tcl"; fi
if [ -d "${HOME}/Libraries/LaTeX" ]; then export TEXINPUTS="${HOME}/Libraries/LaTeX:"; fi
if [ -d "/opt/sbcl" ]; then export SBCL_HOME="/opt/sbcl/lib/sbcl"; fi
if [ -d "/opt/gambit" ]; then export GAMBIT_IMPLEMENTATION_PATH="/opt/gambit"; fi
if [ -d "/opt/mercurial" ]; then export PYTHONPATH="/opt/mercurial/lib/python2.6/site-packages"; fi

ATSVERSION="0.2.3"
export ATSHOME="/opt/ats/lib/ats-anairiats-${ATSVERSION}"
export ATSHOMERELOC="ATS-${ATSVERSION}"

export ERL_LIBS="${repository[metasyntax]}/Libraries/Erlang"

export LUA_PATH=";"
export LUA_CPATH=";"

if [ -d "/opt/luarocks" ]; then
    export LUA_PATH="/opt/luarocks/share/lua/5.1/?.lua;${LUA_PATH}"
    export LUA_INIT="require 'luarocks.require'"
    if [ -d "/opt/luarocks/lib/luarocks/bin" ]; then
        export PATH="/opt/luarocks/lib/luarocks/bin:${PATH}"
    fi
fi

# Specifically for MacPorts on OS X.
if [ -d "/opt/local/var/luarocks" ]; then
    export LUA_PATH="/opt/local/share/lua/5.1/?.lua;${LUA_PATH}"
    export LUA_INIT="require 'luarocks.require'"
fi

export LUA_PATH="${HOME}/Programs/Libraries/Lua/?.lua;${LUA_PATH}"
export LUA_CPATH="${HOME}/Programs/Libraries/Lua/?.so;${LUA_CPATH}"

perlbrew_bashrc="${HOME}/perl5/perlbrew/etc/bashrc"
if [[ -r "$perlbrew_bashrc" ]]; then
    source "$perlbrew_bashrc"
fi

godi_enable() {
    if [[ -d "${HOME}/godi" ]]; then
        export PATH=${HOME}/godi/bin:${HOME}/godi/sbin:$PATH
        hash -r
    else
        echo 'GODI is not installed' 1>&2
    fi
}

godi_disable() {
    old_ifs=$IFS
    IFS=':'

    old_path=$PATH
    new_path=''

    for p in $old_path ; do
        if [[ ! $p =~ ${HOME}/godi ]]; then
            if [[ -z $new_path ]]; then
                new_path=$p
            else
                new_path=$new_path:$p
            fi
        fi
    done

    IFS=$old_ifs
    export PATH=$new_path
    hash -r
}

godi_enable &> /dev/null

case "${TCV_SYSTEM}" in
    "FreeBSD" )
        export GMSGFMT="/usr/local/bin/msgfmt"
        export PACKAGESITE="ftp://ftp3.freebsd.org/"
        ;;

    ############################################################################

    "NetBSD" )
        export PATH="/sbin:/usr/sbin:${PATH}"
        ;;

    ############################################################################

    "OpenBSD" )
        export TCV_INTERFACE=$(ifconfig -a | grep UP | grep -v -e "lo" -e "pflog" | sed -e 's/^\([^:]*\).*$/\1/')
        export TCV_DOMAIN=$(hostname | sed -e 's/^\([^.]*\)\.\(.*\)$/\2/')
        export ANONCVS="anoncvs@anoncvs3.usa.openbsd.org:/cvs"
        export PATH="/usr/games:/usr/local/sbin:${PATH}"

        if [ "${TCV_VIMPATH}" = "vim: Command not found." ]; then
            export EDITOR=vi
            export VISUAL=vi
        else
            export EDITOR=vim
            export VISUAL=vim
        fi

        if [ $(sysctl kern.version | grep -E -e '-(current|beta)' | wc -l) != "0" ]; then
            export PKG_PATH="ftp://ftp3.usa.openbsd.org/pub/OpenBSD/snapshots/packages/$(uname -m)/"
        else
            export PKG_PATH="ftp://ftp3.usa.openbsd.org/pub/OpenBSD/$(uname -r)/packages/$(uname -m)/"
        fi

        if [ -d /usr/local/jdk-1.7.0 ]; then
            export JAVA_HOME="/usr/local/jdk-1.7.0"
            export PATH="${JAVA_HOME}/bin:${JAVA_HOME}/jre/bin:${PATH}"
        fi
        ;;

    ############################################################################

    "Linux" )
        # FIXME: no definition of TCV_INTERFACE for Linux
        export TCV_DOMAIN=$(cat /etc/resolv.conf | grep -E '^search|domain' | sed -e 's/^search \|domain //' | uniq)

        if [ -z "${TCV_VIMPATH}" ]; then
            export EDITOR=vi
            export VISUAL=vi
        else
            export EDITOR=vim
            export VISUAL=vim
        fi

        if [ -d /usr/lib/jvm/java-6-sun ]; then
            export JAVA_HOME="/usr/lib/jvm/java-6-sun"
            if [ -d "${JAVA_HOME}/db" ]; then
                export DERBY_HOME="${JAVA_HOME}/db"
            fi
        fi
        ;;

    ############################################################################

    "Darwin" )
        export CVS_RSH=ssh
esac

# Different behaviour based on what machine we're on.

case "${TCV_DOMAIN}" in
    "metasyntax.net" )
        export MUTT_SPOOLFILE="imaps://mail.metasyntax.net/INBOX/"
        export CVSROOT="/var/cvs"
        ;;
    "trustbearer.com" )
        export MUTT_SPOOLFILE="imaps://www.trustbearer.com/INBOX/"
        export CVSROOT="taylor@metasyntax.net:/var/cvs"
        ;;
esac

## Work settings for IPFW.

if [[ $TCV_HOST = 'banner1' ]]; then
    export PATH=${HOME}/Local/bin:$PATH
    export ORACLE_BASE=/ora01/app/oracle
    export ORACLE_SID=PPRD
    source '/usr/local/bin/oraenv'
    export LD_LIBRARY_PATH="${HOME}/Local/lib:${LD_LIBRARY_PATH}"
fi

if [[ -r "${HOME}/.bashrc" ]]; then source "${HOME}/.bashrc" ; fi

# vim:ft=sh:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.