-
Notifications
You must be signed in to change notification settings - Fork 2
/
.bashrc
216 lines (174 loc) · 5.29 KB
/
.bashrc
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
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
DOTFILES_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DOTFILES_DIR/$SOURCE"
done
DOTFILES_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
# Environmental variables
export EDITOR="nano"
export SVN_EDITOR="nano -w"
# todo maybe use \nano or /usr/bin/nano to avoid the -w and force line wrapping during git/svn commits
# Host-specific environmental variables
case $(hostname) in
"macenzie" | "macenzie.local" | "flanders" | "flanders.local" )
export PATH="$HOME/bin:$DOTFILES_DIR/bin:$PATH"
export WP_TESTS_DIR="$HOME/vhosts/localhost/wp-develop.dev/public_html/tests/phpunit"
# export MH_OUTGOING_SMTP="/usr/local/etc/mailhog/outgoing-smtp.json" this isn't working, not sure why
export NVM_DIR="$HOME/.nvm"
source "/usr/local/opt/nvm/nvm.sh"
;;
esac
source $DOTFILES_DIR/bin/git-completion.bash
source $DOTFILES_DIR/bin/hub-completion.bash
source $DOTFILES_DIR/bin/wp-cli-completion.bash
#todo source bash-completion, but need to setup path per environment. dont leak root paths
# maybe more proper to go in .bash_profile that .bashrc
# todo describe
function wordcamp-diff() {
exit
# not done yet
local args=($@)
local rest=(${args[@]:1:${#args[@]}})
local WP_CONTENT="/Users/ian/vhosts/virtual-machines/vvv-personal/www/wordcamp.dev/public_html/wp-content"
local GIT_DIRS=(
"mu-plugins"
"mu-plugins-private/wporg-mu-plugins"
"plugins-meta"
"themes-meta"
"wp-super-cache-plugins"
)
local SVN_DIRS=(
"plugins-external"
"themes-external"
)
for i in "${GIT_DIRS[@]}"
do :
git -C $WP_CONTENT/$i stat
done
for i in "${SVN_DIRS[@]}"
do :
svn stat "$WP_CONTENT/$i" |prune-svn-stat
done
}
# Bump svn:externals in the current directory
#
# $1 - The plugin/theme slug
# $2 - The version to bump to
# $3 - "local" if you want to only make the change locally, short-circuiting the diff/commit/deploy process.
# This is useful when you want to update several externals in a row, then commit them all at once.
#
# Examples:
# svn-bump-ext akismet 3.2
# svn-bump-ext twentyfifteen 1.6 local
#
function svn-bump-ext {
svn-bump-ext-update-property $1 $2
if [[ 'local' == $3 ]]; then
return
fi
printf "Fetching latest externals...\n\n"
svn up
printf "\nDone fetching, you can test the new externals now."
svn-bump-ext-commit $1 $2
}
# svn-bump-ext helper for updating svn:externals
#
# $1 - The plugin/theme slug
# $2 - The version to bump to
function svn-bump-ext-update-property {
# Use printf to avoid adding a trailing newline
printf %s "$(svn propget svn:externals)" > externals.tmp
local search="$1/(tags/)?(.*)/"
local replace="$1/\1$2/"
# The space is a valid delimiter, just like / or @, but improves readability
eval "sed -i '' -E 's $search $replace ' externals.tmp"
svn propset svn:externals -F externals.tmp .
rm -f externals.tmp
}
# svn-bump-ext helper for diff / commit / deploy
#
# $1 - The plugin/theme slug
# $2 - The version to bump to
function svn-bump-ext-commit {
printf "\nExternal differences:\n\n"
svn diff --depth empty
printf "\nCommit and deploy the changes? [y/n]: "
read commit
if [[ 'y' != $commit ]]; then
printf "\nAborting, did not commit.\n"
return
fi
message="Externals: Bump \`$1\` to \`$2\`"
printf "\nCommit message: [$message]: "
read new_message
# Enter and "y" both mean that the user wants to accept the default message
if [[ "" != $new_message && "y" != $new_message ]]; then
message=$new_message
fi
eval "svn ci --depth empty -m '$message'"
printf "\nDeploying...\n"
eval "deploy"
}
# Alias to convert a stereo recording to mono
#
# See https://iandunn.name/2017/06/04/dropping-quicktime-recording-from-stereo-to-mono/
#
# $1 - The input filename
function qtmono {
basename=$(basename "$1")
filename="${basename%.*}"
extension="${basename##*.}"
ffmpeg -i $1 -codec:v copy -af pan="mono: c0=FL" $filename-mono.$extension
}
# todo git checkout HEAD @ date
# git checkout `git rev-list -n 1 --before="2017-01-16 17:00" master`
# probably better to make this a git alias instead of a bash alias
# Deploy the site that corresponds to the current directory
# $1 For w.org, the role to deploy. Otherwise unused.
function deploy {
current_folder=$(pwd)
printf "\n"
# w.org sandbox
if [[ 'iandunn.dev.ord.wordpress.org' = $(hostname) ]]; then
case "$current_folder" in
*wordcamp* )
deploy-wordcamp.sh
;;
*wporg* | *api* )
deploy-dotorg.sh $1
;;
* )
echo "Couldn't detect site to deploy."
;;
esac;
return
fi
# local sandbox
case "$current_folder" in
*wordcamp.test* )
ssh wordcamp.org 'deploy-wordcamp.sh'
;;
*i18n-tools* )
ssh wordpress.org 'deploy-dotorg.sh wporg'
;;
*wp15.wordpress.test* )
ssh -t wp15.wordpress.net 'svn up ~/wp15.wordpress.net'
;;
*wordpressfoundation.test* )
ssh -t wordpressfoundation.org 'svn up ~/public_html/content/plugins/wpf-stripe'
;;
*iandunn.localhost* | *silencedmajority.test* )
deployer deploy
;;
* )
printf "Couldn't detect site to deploy.\n"
;;
esac
}
# Wrapper for phpmd to avoid having to specify report type and config file.
#
# $1 - The file/folder to analyize
function phpmd {
/usr/local/bin/phpmd $1 text ~/vhosts/localhost/wordcamp.test/phpmd.xml.dist
}