-
Notifications
You must be signed in to change notification settings - Fork 1
/
dotbash_profile
212 lines (179 loc) · 4.66 KB
/
dotbash_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
#!/bin/bash
#
# Alexs .bash_profile
# Loaded by bash when any non-login shell started
#
# Normal environment variable tweaks should be hidden away in
# the .bashrc (assuming they don't mess with ssh/tramp stuff)
#
set +x
#
# Source global definitions
#
#echo "Starting ajb's .bashrc $*"
#set -x
#For debuging when we are interactive or non-interactive (tty)
#
#ENVLOG=~/tmp/env`date +%s`.log
#env > $ENVLOG
#echo "ARGS=$*" >> $ENVLOG
#PID=$$
#echo "PID=$PID" >> $ENVLOG
#cat /proc/$PID/cmdline >> $ENVLOG
#echo "pstree" >> $ENVLOG
#pstree -p >> $ENVLOG
if [ -f /etc/bashrc ]; then
source /etc/bashrc
fi
if [ -f /etc/bash.bashrc ]; then
source /etc/bash.bashrc
fi
#
# Calculate the root directory of this script
#
THIS_SCRIPT="${BASH_SOURCE[0]}"
while [ -h "$THIS_SCRIPT" ]; do
DIR="$( cd -P "$( dirname "$THIS_SCRIPT" )" && pwd )"
THIS_SCRIPT="$(readlink "$THIS_SCRIPT")"
[[ $THIS_SCRIPT != /* ]] && THIS_SCRIPT="$DIR/$THIS_SCRIPT"
done
DOTFILES_DIR=$( cd -P "$( dirname "$THIS_SCRIPT" )" && pwd)
if [ -f $DOTFILES_DIR/dotbashrc ]; then
source $DOTFILES_DIR/dotbashrc
fi
#############
# Aliases
#############
# Search through a list of alternative binaries, returning the first match
function find_alternatives ()
{
for arg in "$@"
do
# --skip-alias only works with GNU which
# file=`which --skip-alias $arg 2> /dev/null`
file=`which $arg 2> /dev/null`
if [ -x "$file" ]; then
echo "$file"
return
fi
done
echo "/alternative/not/found"
}
# Search though a list of directories, returning first match
function find_directories ()
{
for d in "$@"
do
if [ -d "$d" ]; then
echo "$d"
return
fi
done
echo "/alternative/not/found"
}
# Search though a list of files, returning first match
function find_alt_file ()
{
for f in "$@"
do
if [ -f "$f" ]; then
echo "$f"
return
fi
done
echo "/alternative/not/found"
}
#
# Lets see if we have a decent "grep"
#
GREP=$(find_alternatives "ag" "ack-grep" "ggrep" "grep" "/bin/grep")
alias grep="$GREP"
#
# Look for a decent diff
#
DIFF=$(find_alternatives "gdiff" "diff")
alias diff="$DIFF"
# Find a decent browser
BROWSER=$(find_alternatives "chromium-browser" "google-chrome" "chrome" "firefox-4.0" "firefox" "mozilla")
######################
# Environent Variables
######################
# One editor
export EDITOR=emacs
# set CFLAGS for debugging - autoconf usually picks it up.
#export CFLAGS=-g3
# CVS exports
export CVS_RSH=ssh
export CVSEDITOR=ec
# GNU systems usually use less by default for
# man pages, however not all unix-a-likes do
export PAGER=less
#
# surfraw, command line browser control
# http://surfraw.alioth.debian.org/
#
SURFRAW=$(find_alternatives "surfraw")
if [[ -f $SURFRAW ]]; then
alias wiki="$SURFRAW wikipedia "
alias google="$SURFRAW google "
alias imdb="$SURFRAW imdb "
alias code="$SURFRAW codesearch"
alias jspcode="$SURFRAW codesearch lang:jsp"
alias javacode="$SURFRAW codesearch lang:java"
alias pycode="$SURFRAW codesearch lang:python"
fi
########################
# Miscelaneous Stuff
########################
# I want core-dumps dammit
ulimit -S -c unlimited
# Helper function to load extra bits of profile that
# are optional depending on the environment.
LOADED_MODULES=""
function load_extra_module()
{
module=$1
shift
find_exes=$(find_alternatives $*)
module_path=${DOTFILES_DIR}/dotbash_${module}
if [[ -f $find_exes && -f $module_path ]]; then
source $module_path
LOADED_MODULES="$LOADED_MODULES $module"
fi
}
# If invoked as /bin/sh let's assume a minimal environment
if [ "$SHELL" == "/bin/sh" ]; then
echo "Executing $SHELL under minmal environment"
elif [ "${INSIDE_EMACS/*tramp*/tramp}" == "tramp" ] ; then
echo "Executing $SHELL inside tramp"
PS1="[\u@\h \w]$ "
elif [ "$TERM" == "dumb" ] ; then
echo "Executing $SHELL inside dumb (maybe tramp)"
PS1="[\u@\h \w]$ "
else
# Always loaded
load_extra_module ps1 true
load_extra_module path true
load_extra_module find true
load_extra_module hist true
# Depends on tools
load_extra_module tmux tmux
load_extra_module emacs emacs
load_extra_module git git
load_extra_module apt apt-get
load_extra_module keys ssh-agent gpg-agent keychain
load_extra_module valgrind valgrind
load_extra_module ccache ccache
# Gentoo is special...
if [[ `whoami` != "root" ]]; then
load_extra_module gentoo emerge
else
unset CFLAGS
fi
load_extra_module `hostname` true
load_extra_module local true
echo "Loaded$LOADED_MODULES"
clean_path
fi
# Alias for reloading
alias .profile=". ~/.bash_profile"