Repository navigation
Expand file tree
/
Copy pathcustom-bashrc
More file actions
255 lines (223 loc) · 7.5 KB
/
Copy pathcustom-bashrc
File metadata and controls
255 lines (223 loc) · 7.5 KB
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
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# Update our PATH if shell-scripts isn't already in the PATH (idempotent add)
[ "$PATH" == "${PATH/shell-scripts/}" ] && export PATH="$PATH:$SCRIPT_DIR"
# Also add $HOME/bin if it's not already there.
if [[ ":$PATH:" != *":$HOME/bin:"* ]]; then
export PATH="$HOME/bin:$PATH"
fi
# Use 'sed $INPLACE' for cross-platform 'sed -i'.
INPLACE="-i"
if [ "$OS" == "Darwin" ]
then
INPLACE="-i ''"
fi
# Incude our private stuff, if the file exists
PRIVATE_BASHRC="$HOME/Code/personal/config/private-bashrc.rc"
if [ -f "$PRIVATE_BASHRC" ]
then
source "$PRIVATE_BASHRC"
fi
# Require THREE ^D characters in a row to exit
export IGNOREEOF=2
# Prevent Control-S from freezing terminal output
tty -s && stty stop undef
export UNISH_TMP=$HOME/tmp/drush-tmp
mkdir -p $UNISH_TMP
export UNISH_NO_TIMEOUTS=1
# Make 'bat' (like 'cat' with syntax hilitig) look right on light terminals
export BAT_THEME=GitHub
# Locale settings For chef:
# https://github.com/berkshelf/berkshelf-api/issues/112#issuecomment-71907310
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export RUBYOPTS="-E utf-8"
# Set up pipx ensurepath if it hasn't already been done.
if [[ ! -d $HOME/.local/bin ]] && which pipx > /dev/null 2>&1 ; then
pipx ensurepath
fi
# Python autocompletion for pipx
if which register-python-argcomplete > /dev/null 2>&1 && which pipx > /dev/null 2>&1 ; then
eval "$(register-python-argcomplete pipx)"
fi
OS="$(uname -s)"
# Detect external keyboard.
if which hidutil > /dev/null 2>&1 ; then
if ioreg -p IOUSB | grep -q 'USB Gaming Keyboard' ; then
# Remap COMMAND and ALT/OPTION key for external keyboard.
# NOTE: This changes these keys to the wrong behavior on the built-in keyboard
# If this does not work, see https://support.apple.com/guide/mac-help/control-access-to-input-monitoring-on-mac-mchl4cedafb6/mac
# (Go to "Input Monitoring" in "Privacy & Security" control panel and allow Terminal to monitor input from keyboard even when using other applications)
hidutil property --set '{
"UserKeyMapping": [
{
"HIDKeyboardModifierMappingSrc": 0x7000000E2,
"HIDKeyboardModifierMappingDst": 0x7000000E3
},
{
"HIDKeyboardModifierMappingSrc": 0x7000000E3,
"HIDKeyboardModifierMappingDst": 0x7000000E2
}
]
}' > /dev/null
else
# Restore key mappings to defaults
hidutil property --set '{"UserKeyMapping":[]}' > /dev/null
fi
fi
# Bash completion. Requires bash-completion. c.f. base-brew-install script.
# Many of these scripts fail with syntax errors, even after upgrading
# bash; however, others work well, so we will just ignore errors.
if [ "$OS" == "Darwin" ] && [ "x$(which brew)" != "x" ] && [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion 2>/dev/null
fi
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion 2>/dev/null
fi
#
# Some aliases and functions that Greg likes:
#
alias please='sudo'
alias sbrc='source $HOME/.bashrc'
alias lla='ls -A -l --si'
alias ll='ls -l --si'
alias la='ls -A'
alias l='ls -CF'
alias f="find . -type f \! -path '*/.git/*' \! -path '*/vendor/*'"
alias fj='find . -name "*.java"'
alias fppt='find . -name "*.ppt"'
alias fxls='find . -name "*.xls"'
alias portscan='nmap -sT -O'
alias openports='portscan localhost'
alias rmrej='rm `find . -name "*.rej"` `find -name "*.orig"`'
alias rot13='tr a-zA-Z n-za-mN-ZA-M'
alias findtabs="find -not -regex '..*/\..*' -exec grep -HP '\t' {} \;"
alias dr=drush
alias randstr='LC_ALL=C tr -dc "AHJ-NP-Za-km-np-z2-9" </dev/urandom | head -c 64 ; echo'
alias short='LC_ALL=C tr -dc "a-km-np-z" </dev/urandom | head -c 8 ; echo'
alias se='subl'
# Run a web server with Python. See: http://www.linuxjournal.com/content/tech-tip-really-simple-http-server-python
alias pyserve='python -m SimpleHTTPServer'
alias pyserver=pyserve
# Run a web server with php
alias phpserve='php -S 127.0.0.1:8001'
alias phpserver=phpserve
# Print every IP address that's listening on port 22
function sshable() {
for i in {1..254}; do
(
ip="10.0.0.$i"
nc -z -w 1 "$ip" 22 2>/dev/null && echo "SSH open: $ip"
) &
done
wait
}
# Switch php version
function php-switch() {
if [ -n "$(ls /opt/homebrew/Cellar/php*/$1* 2>/dev/null)" ] ; then
brew unlink php
brew link "php@$1"
else
echo "php $1 not installed."
echo
echo "Available versions:"
# 'brew list --versions php' doesn't quite do the trick for me (only shows one version)
find /opt/homebrew/Cellar/php* -type d -maxdepth 1 -print | sed -e 's#/opt/homebrew/Cellar/php[^/]*/*##' | grep '^[0-9.]\+$'
fi
}
function pbrew() {
if [ -z "$HOMEBREW_GITHUB_API_TOKEN" ]; then
if ! gh auth status &>/dev/null; then
gh auth login --git-protocol https --hostname github.com --web
fi
export HOMEBREW_GITHUB_API_TOKEN="$(gh auth token)"
fi
brew "$@"
}
if [ "$OS" == "Darwin" ] ; then
alias ssh-copy-id='ssh-copy-id.sh'
fi
function tolower() { tr A-Z a-z <<<$@; }
function mcd() { mkdir -p "$1" && cd "$1"; }
# Thanks to:
# http://stackoverflow.com/questions/141599/how-do-you-get-a-list-of-changes-from-a-subversion-repository-by-date-range
# http://stackoverflow.com/questions/2693173/log-of-svn-activity-for-a-certain-user
function lastweek() {
svn log "$1" -r {$(date --date="Monday last week" "+%F")}:{$(date --date="Sunday last week" "+%F")} | filter-log-by-user "$2"
}
# Create a .pem from a .p12
function p12topem {
openssl pkcs12 -in $HOME/certs/employee.p12 -out $HOME/certs/employee.crt.pem -clcerts -nokeys
openssl pkcs12 -in $HOME/certs/employee.p12 -out $HOME/certs/employee.key.pem -nocerts -nodes
cat $HOME/certs/employee.crt.pem $HOME/certs/employee.key.pem > $HOME/certs/employee.pem
}
function filter-log-by-user {
if [ -n "$1" ] ; then
who="$1"
elif [ -n "$SVNUSER" ] ; then
who="$SVNUSER"
else
who="$(whoami)"
fi
sed -n "/| $SVNUSER |/,/-----\$/ p"
}
# Only useful on the corporate intranet. Prerequisites:
# sudo mkdir /mnt/public
# sudo apt-get install cifs-utils
alias mount-public='sudo mount -t cifs -o user=ganderson //samba/public /mnt/public'
function fingerprints() {
path="$1"
if [ -z "$path" ]; then
path="$HOME/.ssh/authorized_keys"
fi
local file="$path"
while read l; do
[[ -n $l && ${l###} = $l ]] && ssh-keygen -l -f /dev/stdin <<<$l
done < $file
}
source $SCRIPT_DIR/prompt.sh
# Assume that we will use vi
export EDITOR=vi
# Exit here if there is no DISPLAY
#[ -z "$DISPLAY" ] && return
# Set the editor to 'se' if it is available
s=`which sublime_text 2>/dev/null`
s2=`which se 2>/dev/null`
if [ -n "$s" ] && [ -n "$s2" ] ; then
export EDITOR='se -w'
fi
#
# If drush is in the $PATH, then source the
# example bashrc it provides.
#
d=`which drush 2>/dev/null`
if [ -n "$d" ] ; then
# If the file found is a symlink, resolve to the actual file
d2=`readlink $d`
# Get the directory that drush is stored in.
# d2 might be relative or absolute path.
if [ "x${d2:0:1}" == "x/" ] ; then
d=$(dirname "$d2")
else
d=$(dirname $(dirname "$d")"/$d2")
fi
if [ -f "$d/examples/example.bashrc" ] ; then
. "$d/examples/example.bashrc"
# Add aliases for standard bash commands
if [ -n "`type -t cddl`" ] ; then
alias cd='cddl'
fi
if [ -n "`type -t lsd`" ] ; then
alias ls='lsd'
fi
if [ -n "`type -t cpd`" ] ; then
alias cp='cpd'
fi
if [ -n "`type -t dssh`" ] ; then
alias ssh='dssh'
fi
if [ -n "`type -t gitd`" ] ; then
alias git='gitd'
fi
fi
fi