-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.bash_functions
237 lines (168 loc) · 4.36 KB
/
.bash_functions
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
# Go up N directories
function up() {
str=""
count=0
while [ "$count" -lt "$1" ];
do
str=$str"../"
let count=count+1
done
cd $str
}
# Show my IP
function myip() {
hostname
ip addr | awk '/inet / {sub(/\/.*/, "", $2); print $2}'
dig +short myip.opendns.com @resolver1.opendns.com
}
# Create a backup file
function bak() {
cp $1{,.bak}
}
# Start PHP server
function phpserver() {
local port="${1:-4000}";
sleep 1
php -S "localhost:${port}";
}
# Start Python server
function pyserver() {
local port="${1:-8000}";
sleep 1
python -m SimpleHTTPServer $port
}
# Determine size of a file or total size of a directory
function fs() {
if du -b /dev/null > /dev/null 2>&1; then
local arg=-sbh;
else
local arg=-sh;
fi
if [[ -n "$@" ]]; then
du $arg -- "$@";
else
du $arg .[^.]* *;
fi;
}
# https://laravel.com/docs/5.7/homestead#daily-usage
function __homestead() {
( cd ~/Homestead && vagrant $* )
}
# https://github.com/mathiasbynens/dotfiles/blob/ec493f5b1bb1650ef4d293291105430c3a982c08/.bash_prompt
function prompt_git() {
local s='';
local branchName='';
# Check if the current directory is in a Git repository.
if [ $(git rev-parse --is-inside-work-tree &>/dev/null; echo "${?}") == '0' ]; then
# check if the current directory is in .git before running git checks
if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == 'false' ]; then
# Ensure the index is up to date.
git update-index --really-refresh -q &>/dev/null;
# Check for uncommitted changes in the index.
if ! $(git diff --quiet --ignore-submodules --cached); then
s+='+';
fi;
# Check for unstaged changes.
if ! $(git diff-files --quiet --ignore-submodules --); then
s+='!';
fi;
# Check for untracked files.
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
s+='?';
fi;
# Check for stashed files.
if $(git rev-parse --verify refs/stash &>/dev/null); then
s+='$';
fi;
fi;
# Get the short symbolic ref.
# If HEAD isn’t a symbolic ref, get the short SHA for the latest commit
# Otherwise, just give up.
branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \
git rev-parse --short HEAD 2> /dev/null || \
echo '(unknown)')";
[ -n "${s}" ] && s=" [${s}]";
echo -e "${1}${branchName}${2}${s}";
else
return;
fi;
}
# https://github.com/elgris/dotfiles/blob/master/bash_aliases#L15
function extract() {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar -zxvf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# https://docs.gitignore.io/install/command-line
function gi() {
curl -L -s https://www.gitignore.io/api/$@
}
# Google search
function google() {
search=""
for term in $@; do
search="$search%20$term"
done
x-www-browser "http://www.google.com/search?q=$search"
}
# https://hub.docker.com/_/composer
function __php_composer() {
docker run \
`tty -s && tty=--tty` \
--init \
--interactive \
--rm \
--user $(id -u):$(id -g) \
--volume /etc/passwd:/etc/passwd:ro \
--volume /etc/group:/etc/group:ro \
--volume $(pwd):/app \
composer "$@"
}
# https://hub.docker.com/r/magnobiet/php
function __php() {
docker run \
--init \
--rm \
--interactive \
--user $(id -u):$(id -g) \
--volume /etc/passwd:/etc/passwd:ro \
--volume /etc/group:/etc/group:ro \
--volume $(pwd):/app \
--workdir /app \
--network host \
magnobiet/php:7.2-cli-alpine \
php "$@"
}
function __phpstan() {
docker run \
--init \
--rm \
--user $(id -u):$(id -g) \
--volume $(pwd):/app \
phpstan/phpstan "$@"
}
function __phpunit() {
docker run \
--init \
--rm \
--volume $(pwd):/app \
phpunit/phpunit "$@"
}
function __phpinsights() {
docker run -it --rm -v $(pwd):/app nunomaduro/phpinsights
}