-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path.bash_aliases.example
99 lines (77 loc) · 2.01 KB
/
.bash_aliases.example
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
# docker-compose.yml 绝对路径
DPE_COMPOSE=/home/suyar/repo/docker-php-env/docker-compose.yml
# 挂载的 DIR_SOURCE 绝对路径
DPE_SOURCE=/home/suyar/repo
dpe_workdir() {
local cwd=$PWD
local workdir
local subdir
if [[ ${cwd} =~ ^${DPE_SOURCE}/?$ ]]; then
workdir=/www
elif [[ ${cwd} =~ ^${DPE_SOURCE}/.+ ]]; then
subdir=${cwd#${DPE_SOURCE}}
if [[ -n $subdir ]]; then
workdir=/www${subdir}
fi
fi
echo $workdir
}
tophp() {
if [[ $# -lt 1 ]]; then
local version=php83
else
local version=$1
fi
local workdir=$(dpe_workdir)
if [[ -z $workdir ]]; then
workdir=/www
fi
sudo docker compose -f "${DPE_COMPOSE}" exec -u $(id -u):$(id -g) -w "${workdir}" "${version}" bash
}
alias tophp83='tophp php83'
tonginx() {
local workdir=$(dpe_workdir)
if [[ -z $workdir ]]; then
workdir=/www
fi
sudo docker compose -f "${DPE_COMPOSE}" exec -w "${workdir}" nginx bash
}
tomysql() {
sudo docker compose -f "${DPE_COMPOSE}" exec mysql bash
}
php() {
local workdir=$(dpe_workdir)
local version
local params
if [[ -z $workdir ]]; then
echo "当前目录不属于 ${DPE_SOURCE}"
return
fi
if [[ $# -ge 1 && $1 =~ ^php[0-9]{2}$ ]]; then
version=$1
params=${@:2}
else
version=php83
params=$@
fi
sudo docker compose -f "${DPE_COMPOSE}" exec -u $(id -u):$(id -g) -w "${workdir}" "${version}" php ${params}
}
alias php83='php php83'
composer() {
local workdir=$(dpe_workdir)
local version
local params
if [[ -z $workdir ]]; then
echo "当前目录不属于 ${DPE_SOURCE}"
return
fi
if [[ $# -ge 1 && $1 =~ ^php[0-9]{2}$ ]]; then
version=$1
params=${@:2}
else
version=php83
params=$@
fi
sudo docker compose -f "${DPE_COMPOSE}" exec -u $(id -u):$(id -g) -w "${workdir}" "${version}" composer ${params}
}
alias composer83='composer php83'