-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.bash_profile
executable file
·212 lines (172 loc) · 5.32 KB
/
.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
# Settings for all shells
#Environment variables
export EDITOR=vim
export VISUAL=$EDITOR
export PAGER=less
export CVS_RSH=ssh
export LESS="-RM"
export NODE_PATH=/usr/local/lib/node_modules
export PATH=$HOME/bin:$HOME/bin/bin:/usr/local/share/npm/bin:/usr/local/share/python:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# Find chruby share directory
for dir in {/usr/local,}/opt/chruby/share/chruby ; do
if [[ -d "$dir" ]] ; then
chruby_dir="$dir"
break
fi
done
# If chruby dir was found, set up chruby
if [ -d "$chruby_dir" ] ; then
. $chruby_dir/chruby.sh
# Set up chruby version from one of three places:
# 1. (preferred): file ~/.ruby-version
# 2. Last version installed in $HOME/.rubies
# 3. Last resort: hard-coded version
if [ -f ~/.ruby-version ] ; then
use_chruby_version=$(<~/.ruby-version)
unset chruby_defaulted
elif [ -d ~/.rubies ] ; then
use_chruby_version=$(ls -dt1 $HOME/.rubies/* | awk -F/ '{print $(NF)}' | sed 1q)
chruby_defaulted='latest version found'
fi
if [ -z "$use_chruby_version" ] ; then
use_chruby_version=1.9.3-p392
chruby_defaulted='one that seemed good'
fi
chruby "$use_chruby_version"
fi
# Settings for interactive shells
# return if not interactive
[[ $- != *i* ]] && return
# set a default terminal type for deficient systems or weird terminals
tput longname >/dev/null 2>&1 || export TERM=xterm
warn() {
tput setaf 1 >&2
printf '%s\n' "$*"
tput sgr0 >&2
}
## Set up $dotfiles directory
# returns true if the program is installed
installed() {
hash "$1" >/dev/null 2>&1
}
# OSX `readlink` doesn't support the `-f` option (-f = follow components to make full path)
# If `greadlink` is installed, use it
# Otherwise, use the dir and basename provided to construct a sufficient stand-in
relative_readlink() {
local dir="$1" base="$2"
if installed greadlink ; then
dirname "$(greadlink -f "$dir/$base")"
elif pushd "$dir" >/dev/null 2>&1 ; then
local link="$(readlink "$base")"
case "$link" in
/*) dirname "$link" ;;
*) pushd "$(dirname "$link")" >/dev/null 2>&1 ; pwd -P ; popd >/dev/null ;;
esac
popd >/dev/null
fi
}
if [[ -L "$HOME/.bash_profile" ]] ; then
dotfiles="$(relative_readlink "$HOME" .bash_profile)"
fi
if [[ -z "$dotfiles" ]] || [[ ! -d "$dotfiles" ]] ; then
#warn "~/.bash_profile should be a link to .bash_profile in the dotfiles repo"
dotfiles=$HOME/Code/dotfiles
fi
# Finish if we couldn't find our root directory
if [[ -z "$dotfiles" ]] || [[ ! -d "$dotfiles" ]] ; then
warn "Couldn't find root of dotfiles directory. Exiting .bash_profile early."
return
fi
export DOTFILES="$dotfiles"
if [ -n "$chruby_defaulted" ] ; then
warn "chruby version defaulted to $chruby_defaulted: $use_chruby_version"
fi
. $dotfiles/app-navigation.bash
#running_modern_bash && shopt -s autocd
# History settings
# ignoreboth=ignoredups:ignorespace
# ignoredups = ignore duplicate commands in history
# ignorespace = ignore commands that start with space
HISTCONTROL=ignoreboth
# Save (effectively) all commands ever
HISTSIZE=10000000
HISTFILESIZE=10000000
# only append the history at the end (shouldn't actually be needed - histappend)
shopt -s histappend
[ -d "$chruby_dir" ] && . $chruby_dir/auto.sh
# Bash
case "$(uname)" in
*Darwin*) ls_options=-lahG ;;
*) ls_options=-lah ;;
esac
function onport() {
(( $# )) || set -- 3000
lsof -Pni :$*
}
## only binds the given termcap entr(y|ies) to a widget if the terminal supports it
termcap_bind() {
local widget=$1 key termcap
shift
for termcap ; do
key="$(tput $termcap)"
[ -n "$key" ] && bind "\"$key\": $widget"
done
}
# Search history
termcap_bind history-search-backward cuu1 kcuu1
termcap_bind history-search-forward cud1 kcud1
# Simulate Zsh's preexec hook (see: http://superuser.com/a/175802/73015 )
# (This performs the histappend at a better time)
simulate_preexec() {
[ -n "$COMP_LINE" ] || # skip if doing completion
[ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] || # skip if generating prompt
history -a
}
trap simulate_preexec DEBUG
#command prompt customization
prompt() {
local last_status=$?
local WHITE="\[\033[1;37m\]"
local GREEN="\[\033[0;32m\]"
local CYAN="\[\033[0;36m\]"
local GRAY="\[\033[0;37m\]"
local BLUE="\[\033[0;34m\]"
local LIGHT_BLUE="\[\033[1;34m\]"
local YELLOW="\[\033[1;33m\]"
local RED="\[\033[1;31m\]"
local no_color='\[\033[0m\]'
local time="${YELLOW}\d \@$no_color"
local whoami="${GREEN}\u@\h$no_color"
local dir="${CYAN}\w$no_color"
local branch
if git rev-parse --git-dir >/dev/null 2>/dev/null ; then
branch=$(git branch | awk '/^\*/ { print $2 }')
branch="${branch:+$LIGHT_BLUE$branch }"
else
unset branch
fi
local driver
if test -n "$M_DRIVER" ; then
driver="$LIGHT_BLUE($M_DRIVER)"
else
driver="${RED}NO DRIVER"
fi
local last_fail
if test $last_status -ne 0 ; then
last_fail="=> ${YELLOW}Err: $last_status${no_color}\n"
else
unset last_fail
fi
PS1="\n$time $whoami $branch$dir\n$last_fail$no_color\$ "
}
PROMPT_COMMAND=prompt
# retain $PROMPT_DIRTRIM directory components when the prompt is too long
PROMPT_DIRTRIM=3
wedidit() {
open ~/dora-we-did-it.webm
}
# Load completion files from $dotfiles/completion/{function}.bash
for script in "$dotfiles/completion/"*.bash ; do
. "$script" > /dev/null 2>&1
done
source "$dotfiles/.aliases"