-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
completion.sh
123 lines (92 loc) · 3.7 KB
/
completion.sh
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
#!/usr/bin/env bash
# shellcheck disable=SC2128
if [[ -z "${BASH_SOURCE}" ]]; then
# shellcheck disable=SC2296
BASH_SOURCE=${(%):-%N}
fi
# shellcheck disable=SC2128
DIR="$(dirname "${BASH_SOURCE}")"
CONFIG_DIR=${XDG_CONFIG_HOME:-${HOME}/.config}
# shellcheck source=.env.dist
source "${CONFIG_DIR}/swdc/env"
# shellcheck disable=SC2086
AVAILABLE_CMDS=$(find $DIR/modules/* -maxdepth 1 -mindepth 1 -iname "*.sh")
if [[ -e "$HOME/.config/swdc/modules/" ]]; then
# shellcheck disable=SC2086
AVAILABLE_CMDS=$(find $DIR/modules/* $HOME/.config/swdc/modules/* -maxdepth 1 -mindepth 1 -iname "*.sh")
fi
function __list_swdc_commands {
prev_arg="${COMP_WORDS[COMP_CWORD-2]}";
build_arg=$prev_arg
if [[ -n "${COMP_WORDS[1]}" ]]; then
build_arg=${COMP_WORDS[1]}
fi
if [[ "$3" == "swdc" ]]; then
local cmds
for file in $AVAILABLE_CMDS; do
file=$(basename "$file")
file=${file%.*}
cmds="$cmds $file"
done
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$cmds" "${COMP_WORDS[COMP_CWORD]}"))
elif [[ "$AVAILABLE_CMDS" == *"$3"* ]]; then
local cmds
# shellcheck disable=SC2044
for file in $(find "$CODE_DIRECTORY/" -maxdepth 1 -mindepth 1); do
file=$(basename "$file")
cmds="$cmds $file"
done
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$cmds" "${COMP_WORDS[COMP_CWORD]}"))
elif [[ "$build_arg" == "snap" || "$build_arg" == "rsnap" ]]; then
local cmds
# shellcheck disable=SC2044
for file in $(find "$CODE_DIRECTORY/snapshots/" -maxdepth 1 -mindepth 1 -iname "$3*.sql"); do
file=$(basename "$file" | cut -d '-' -f 2)
file=${file%.*}
cmds="$cmds $file"
done
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$cmds" "${COMP_WORDS[COMP_CWORD]}"))
elif [[ "$build_arg" == "build" ]]; then
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W '--mysql-host --without-demo-data --without-building --docker-build' -- "${COMP_WORDS[COMP_CWORD]}"))
elif [[ "$build_arg" == "check" ]]; then
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W 'ecs static-analyse phpstan psalm' -- "${COMP_WORDS[COMP_CWORD]}"))
elif [[ "$build_arg" == "config-add" || "$build_arg" == "config-remove" ]]; then
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W '-e disable-csrf array-cache redis-session redis-message-queue-stats disable-profiler' -- "${COMP_WORDS[COMP_CWORD]}"))
elif [[ "$build_arg" == "e2e" ]]; then
if [[ "${#COMP_WORDS[@]}" == "5" ]]; then
project="${COMP_WORDS[COMP_CWORD-2]}"
# shellcheck disable=SC2207
cmds=$(list_sw6_project_plugins "$project")
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$cmds" -- "${COMP_WORDS[COMP_CWORD]}"))
else
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W 'Administration Storefront' -- "${COMP_WORDS[COMP_CWORD]}"))
fi
elif [[ "$build_arg" == "admin-jest" ]]; then
project="${COMP_WORDS[COMP_CWORD-1]}"
# shellcheck disable=SC2207
cmds=$(list_sw6_project_plugins "$project")
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$cmds" -- "${COMP_WORDS[COMP_CWORD]}"))
fi
return 0;
}
function list_sw6_project_plugins()
{
local cmds
# shellcheck disable=SC2044
for file in $(find "$CODE_DIRECTORY/$1/custom/plugins" -maxdepth 1 -mindepth 1); do
file=$(basename "$file" | cut -d '-' -f 2)
file=${file%.*}
cmds="$cmds $file"
done
echo "$cmds"
}
complete -F __list_swdc_commands swdc