annotate .bash_overrides @ 572:980fd762e354

STUB: .emacs
author Jeff Hammel <k0scist@gmail.com>
date Thu, 16 Jan 2014 15:32:55 -0800
parents 047a53a8fbad
children 753b1c2bd64c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
1 #!/bin/bash
305
fac01a1bcedf add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents: 302
diff changeset
2
fac01a1bcedf add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents: 302
diff changeset
3 ### command overrides too elaborate for aliases
0
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
4
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
5 cd() {
287
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
6
0
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
7 ENV=""
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
8 if [ -n "${VIRTUAL_ENV}" ]
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
9 then
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
10 ENV="${VIRTUAL_ENV}"
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
11 fi
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
12
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
13
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
14 if [ -d "$@" ]
287
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
15 then
0
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
16 command cd "$@"
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
17 else
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
18 if [ -e "$@" ]
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
19 then
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
20 command cd `dirname "$@"`
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
21 else
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
22 if [[ "$@" == "^" && -n "${ENV}" ]]
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
23 then
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
24 command cd "${ENV}"
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
25 else
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
26 command cd "$@"
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
27 fi
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
28 fi
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
29 fi
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
30
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
31 # handle ENVs
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
32 if [ -e "bin/activate" ]
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
33 then
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
34 if [ -n "${ENV}" ]
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
35 then
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
36 if [ "${ENV}" != "${PWD}" ]
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
37 then
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
38 if [[ -n "`type -t deactivate`" ]]
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
39 then
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
40 deactivate
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
41 fi
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
42 else
287
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
43 return
0
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
44 fi
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
45 fi
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
46 source "bin/activate"
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
47 fi
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
48
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
49 ENV=""
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
50 if [ -n "${VIRTUAL_ENV}" ]
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
51 then
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
52 ENV="${VIRTUAL_ENV}"
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
53 fi
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
54
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
55 if [ -n "${ENV}" ]
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
56 then
564
Jeff Hammel <jhammel@mozilla.com>
parents: 559
diff changeset
57 FULLPWD=$(python -c 'import os; print (os.getcwd())')
0
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
58 if (( ! `expr match "${FULLPWD}" "${ENV}"` ))
287
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
59 then
0
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
60 if [[ -n "`type -t deactivate`" ]]
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
61 then
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
62 deactivate
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
63 fi
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
64 fi
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
65 fi
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
66 unset ENV
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
67 }
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
68
287
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
69 function emacsclient() {
0
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
70 command emacsclient $@ > /dev/null &
f3ab51c79813 adding configuration from https://svn.openplans.org/svn/config_jhammel/
k0s <k0scist@gmail.com>
parents:
diff changeset
71 }
287
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
72
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
73 function find {
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
74
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
75 if (( ! $# ))
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
76 then
305
fac01a1bcedf add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents: 302
diff changeset
77 command find
fac01a1bcedf add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents: 302
diff changeset
78 return
287
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
79 fi
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
80
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
81 if [ -d $1 ]
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
82 then
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
83 DIR="$1"
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
84 shift
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
85 else
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
86 DIR="$PWD"
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
87 fi
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
88
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
89 if [ "$#" == "1" ]
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
90 then
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
91 `which find` -L "$PWD" -not -path '*.svn*' -iname "$1"
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
92 return 0
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
93 fi
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
94
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
95 COMMAND="`which find` -L \"$DIR\" -not -path '*.svn*' $@"
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
96 #echo $COMMAND # for debugging
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
97 `which find` -L "$DIR" -not -path '*.svn*' "$@"
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
98 }
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
99
414
41c3ea0a3513 make hg safer, again
Jeff Hammel <jhammel@mozilla.com>
parents: 413
diff changeset
100 # make hg safer since $HOME is versioned
412
5bee5c55a7a0 args test + bash overrides hg safety
Jeff Hammel <jhammel@mozilla.com>
parents: 312
diff changeset
101 function hg {
413
Jeff Hammel <jhammel@mozilla.com>
parents: 412
diff changeset
102 if [[ "$(command hg root)" == "${HOME}" ]]
412
5bee5c55a7a0 args test + bash overrides hg safety
Jeff Hammel <jhammel@mozilla.com>
parents: 312
diff changeset
103 then
5bee5c55a7a0 args test + bash overrides hg safety
Jeff Hammel <jhammel@mozilla.com>
parents: 312
diff changeset
104 if [[ "$*" == st* ]]
5bee5c55a7a0 args test + bash overrides hg safety
Jeff Hammel <jhammel@mozilla.com>
parents: 312
diff changeset
105 then
5bee5c55a7a0 args test + bash overrides hg safety
Jeff Hammel <jhammel@mozilla.com>
parents: 312
diff changeset
106 command hg st -q
5bee5c55a7a0 args test + bash overrides hg safety
Jeff Hammel <jhammel@mozilla.com>
parents: 312
diff changeset
107 return
5bee5c55a7a0 args test + bash overrides hg safety
Jeff Hammel <jhammel@mozilla.com>
parents: 312
diff changeset
108 fi
414
41c3ea0a3513 make hg safer, again
Jeff Hammel <jhammel@mozilla.com>
parents: 413
diff changeset
109 if [[ "$*" == res* ]] || [[ "$*" == pur* ]]
412
5bee5c55a7a0 args test + bash overrides hg safety
Jeff Hammel <jhammel@mozilla.com>
parents: 312
diff changeset
110 then
5bee5c55a7a0 args test + bash overrides hg safety
Jeff Hammel <jhammel@mozilla.com>
parents: 312
diff changeset
111 echo "Aborting \'hg $*\'; hg root is ${HOME}!"
413
Jeff Hammel <jhammel@mozilla.com>
parents: 412
diff changeset
112 return 1
412
5bee5c55a7a0 args test + bash overrides hg safety
Jeff Hammel <jhammel@mozilla.com>
parents: 312
diff changeset
113 fi
5bee5c55a7a0 args test + bash overrides hg safety
Jeff Hammel <jhammel@mozilla.com>
parents: 312
diff changeset
114 fi
417
Jeff Hammel <jhammel@mozilla.com>
parents: 414
diff changeset
115 command hg "$@"
412
5bee5c55a7a0 args test + bash overrides hg safety
Jeff Hammel <jhammel@mozilla.com>
parents: 312
diff changeset
116 }
5bee5c55a7a0 args test + bash overrides hg safety
Jeff Hammel <jhammel@mozilla.com>
parents: 312
diff changeset
117
287
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
118 function lsdiff {
305
fac01a1bcedf add an apply-patch function
Jeff Hammel <jhammel@mozilla.com>
parents: 302
diff changeset
119 # TODO: extract this general pattern as a bash "decorator"
287
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
120 if expr "$1" : 'http[s]\?://.*' &> /dev/null
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
121 then
302
1a177f9b51d4 follow the damn redirects
Jeff Hammel <jhammel@mozilla.com>
parents: 287
diff changeset
122 curl --location "$1" 2> /dev/null | command lsdiff
287
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
123 else
312
597455a28c49 utilize command
Jeff Hammel <jhammel@mozilla.com>
parents: 305
diff changeset
124 command lsdiff "$@"
287
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
125 fi
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
126
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
127 }
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
128
544
Jeff Hammel <jhammel@mozilla.com>
parents: 417
diff changeset
129 function mv {
Jeff Hammel <jhammel@mozilla.com>
parents: 417
diff changeset
130 num=$#
Jeff Hammel <jhammel@mozilla.com>
parents: 417
diff changeset
131 if (( num == 0 ))
Jeff Hammel <jhammel@mozilla.com>
parents: 417
diff changeset
132 then
Jeff Hammel <jhammel@mozilla.com>
parents: 417
diff changeset
133 command mv "$@"
Jeff Hammel <jhammel@mozilla.com>
parents: 417
diff changeset
134 return
Jeff Hammel <jhammel@mozilla.com>
parents: 417
diff changeset
135 fi
Jeff Hammel <jhammel@mozilla.com>
parents: 417
diff changeset
136 last=${!#}
559
501169756134 .bash_overrides
Jeff Hammel <jhammel@mozilla.com>
parents: 544
diff changeset
137 if [[ "${last:(-1)}" == "/" ]]
501169756134 .bash_overrides
Jeff Hammel <jhammel@mozilla.com>
parents: 544
diff changeset
138 then
501169756134 .bash_overrides
Jeff Hammel <jhammel@mozilla.com>
parents: 544
diff changeset
139 directory=${last}
501169756134 .bash_overrides
Jeff Hammel <jhammel@mozilla.com>
parents: 544
diff changeset
140 else
501169756134 .bash_overrides
Jeff Hammel <jhammel@mozilla.com>
parents: 544
diff changeset
141 directory=$(dirname ${last})
501169756134 .bash_overrides
Jeff Hammel <jhammel@mozilla.com>
parents: 544
diff changeset
142 fi
544
Jeff Hammel <jhammel@mozilla.com>
parents: 417
diff changeset
143 if [[ ! -e "${directory}" ]]
Jeff Hammel <jhammel@mozilla.com>
parents: 417
diff changeset
144 then
Jeff Hammel <jhammel@mozilla.com>
parents: 417
diff changeset
145 mkdir -p "${directory}"
Jeff Hammel <jhammel@mozilla.com>
parents: 417
diff changeset
146 fi
Jeff Hammel <jhammel@mozilla.com>
parents: 417
diff changeset
147 command mv "$@"
Jeff Hammel <jhammel@mozilla.com>
parents: 417
diff changeset
148 return
Jeff Hammel <jhammel@mozilla.com>
parents: 417
diff changeset
149
Jeff Hammel <jhammel@mozilla.com>
parents: 417
diff changeset
150 }
Jeff Hammel <jhammel@mozilla.com>
parents: 417
diff changeset
151
287
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
152 function unlink {
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
153 command unlink `echo $@ | sed 's/\/$//g'`
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
154 }
f890a12d8cf5 add lsdiff override for urls
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
155