Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 273 lines (238 sloc) 4.934 kb
f36c699 Derek Wyatt Initial commit
authored
1
2 set -o vi
3 set -o ignoreeof
4
5 export PATH=.:/usr/local/bin:~/bin:$PATH
6 if uname | grep -q Darwin; then
7 export EDITOR="/usr/local/bin/mvim -f"
8 else
9 export EDITOR=vim
10 fi
11
12 export JAVA_HOME=/usr/local/jdk
13
14 # don't put duplicate lines in the history. See bash(1) for more options
15 # ... or force ignoredups and ignorespace
16 export HISTCONTROL=ignoredups:ignorespace
17
18 # append to the history file, don't overwrite it
19 shopt -s histappend
20
21 # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
22 export HISTSIZE=1000
23 export HISTFILESIZE=2000
24
25 # check the window size after each command and, if necessary,
26 # update the values of LINES and COLUMNS.
27 shopt -s checkwinsize
28
29 # make less more friendly for non-text input files, see lesspipe(1)
30 [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
31
32 eval "$(dircolors -b ~/.dircolors)"
33 alias ls='ls --color=auto -F'
34 alias grep='grep --color=auto'
35 alias fgrep='fgrep --color=auto'
36 alias egrep='egrep --color=auto'
37
38 function g
39 {
40 if uname | grep -q Darwin; then
41 mvim --remote-silent $@
42 else
43 gvim --remote-silent $@
44 fi
45 }
46
47 export DIRSTACK_MAX=15
48 DS=()
49
50 function eecho
51 {
52 echo $@ 1>&2
53 }
54
55 function shiftStackUp
56 {
57 typeset num=$1
58 typeset -i c=$((num+1))
59
60 while (( $c < ${#DS[*]} ))
61 do
62 DS[$((c-1))]="${DS[$c]}"
63 ((c=c+1))
64 done
65 unset DS[$((${#DS[*]}-1))]
66 }
67
68 function shiftStackDown
69 {
70 typeset num=$1
71 typeset -i c=${#DS[*]}
72
73 while (( $c > $num ))
74 do
75 DS[$c]="${DS[$((c-1))]}"
76 ((c=c-1))
77 done
78 }
79
80 function popStack
81 {
82 if [[ ${#DS[*]} == 0 ]]; then
83 eecho "Cannot pop stack. No elements to pop."
84 return 1
85 fi
86 typeset retv="${DS[0]}"
87 shiftStackUp 0
88
89 echo $retv
90 }
91
92 function pushStack
93 {
94 typeset newvalue="$1"
95 typeset -i c=0
96
97 while (( $c < ${#DS[*]} ))
98 do
99 if [[ "${DS[$c]}" == "$newvalue" ]]; then
100 shiftStackUp $c
101 else
102 ((c=c+1))
103 fi
104 done
105 shiftStackDown 0
106 DS[0]="$newvalue"
107 if [[ ${#DS[*]} -gt $DIRSTACK_MAX ]]; then
108 unset DS[$((${#DS[*]}-1))]
109 fi
110 }
111
112 function cd_
113 {
114 typeset ret=0
115
116 if [ $# == 0 ]; then
117 pd "$HOME"
118 ret=$?
119 elif [[ $# == 1 && "$1" == "-" ]]; then
120 pd
121 ret=$?
122 elif [ $# -gt 1 ]; then
123 typeset from="$1"
124 typeset to="$2"
125 typeset c=0
126 typeset path=
127 typeset x=$(pwd)
128 typeset numberOfFroms=$(echo $x | tr '/' '\n' | grep "^$from$" | wc -l)
129 while [ $c -lt $numberOfFroms ]
130 do
131 path=
132 typeset subc=$c
133 typeset tokencount=0
134 for subdir in $(echo $x | tr '/' '\n' | tail -n +2)
135 do
136 if [[ "$subdir" == "$from" ]]; then
137 if [ $subc -eq $tokencount ]; then
138 path="$path/$to"
139 subc=$((subc+1))
140 else
141 path="$path/$from"
142 tokencount=$((tokencount+1))
143 fi
144 else
145 path="$path/$subdir"
146 fi
147 done
148 if [ -d "$path" ]; then
149 break
150 fi
151 c=$((c=c+1))
152 done
153 if [ "$path" == "$x" ]; then
154 echo "Bad substitution"
155 ret=1
156 else
157 pd "$path"
158 ret=$?
159 fi
160 else
161 pd "$1"
162 ret=$?
163 fi
164
165 return $ret
166 }
167
168 function pd
169 {
170 typeset dirname="${1-}"
171 typeset firstdir seconddir ret p oldDIRSTACK
172
173 if [ "$dirname" == "" ]; then
174 firstdir=$(pwd)
175 if [ ${#DS[*]} == 0 ]; then
176 eecho "Stack is empty. Cannot swap."
177 return 1
178 fi
179 seconddir=$(popStack)
180 pushStack "$firstdir"
181 "cd" "$seconddir"
182 ret=$?
183 return $ret
184 else
185 if [ -d "$dirname" ]; then
186 if [ "$dirname" != '.' ]; then
187 pushStack "$(pwd)"
188 fi
189 "cd" "$dirname"
190 ret=$?
191 return $ret
192 else
193 eecho "bash: $dirname: not found"
194 return 1
195 fi
196 fi
197 }
198
199 function ss
200 {
201 typeset f x
202 typeset -i c=0
203 typeset re="${1-}"
204
205 while (( $c < ${#DS[*]} ))
206 do
207 f=${DS[$c]}
208 if [[ -n "$re" && "$(echo $f | grep $re)" == "" ]]; then
209 ((c=c+1))
210 continue
211 fi
212 if (( ${#f} > 120 )); then
213 x="...$(echo $f | cut -c$((${#f}-120))-)"
214 else
215 x=$f
216 fi
217 echo "$((c+1))) $x"
218 ((c=c+1))
219 done
220 }
221
222 function csd
223 {
224 typeset num="${1-}"
225 typeset removedDirectory
226
227 if ! echo "${num##+([0-9])}" | grep -q '^[0-9][0-9]*$'; then
228 c=0
229 re=$num
230 num=0
231 while [ "$c" -lt "${#DS[*]}" ]
232 do
233 if echo "${DS[$c]}" | grep -q $re; then
234 num=$(($c+1))
235 break
236 fi
237 ((c=c+1))
238 done
239 fi
240 if [ "$num" == 0 ]; then
241 echo "usage: csd <number greater than 0 | regular expression>"
242 return 1
243 elif [ "$num" -gt "${#DS[*]}" ]; then
244 echo "$num is beyond the stack size."
245 return 1
246 else
247 num=$((num-1))
248 typeset dir="${DS[$num]}"
249 shiftStackUp $num
250 cd_ "$dir"
251 return $?
252 fi
253 }
254
255 alias cd=cd_
256
257 for f in $(ls ~/.bash/source_these/*);
258 do
259 . $f
260 done
261
262 if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
263 . /etc/bash_completion
264 fi
265
266 if [ -f ~/.bashprompt ]; then
267 . ~/.bashprompt
268 fi
269
270 if [ -f ~/.bashrc_local ]; then
271 . ~/.bashrc_local
272 fi
Something went wrong with that request. Please try again.