-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlaravel.plugin.zsh
executable file
·70 lines (55 loc) · 1.56 KB
/
laravel.plugin.zsh
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
# Copyright (c) Bruno Sales <me@baliestri.dev>. Licensed under the MIT License.
# See the LICENSE file in the project root for full license information.
function __find_laravel_root() {
local current_path="$(pwd)"
local laravel_path=""
until [[ "${current_path}" -ef "/" ]]; do
if [[ -f "${current_path}/artisan" ]]; then
laravel_path="${current_path}"
break
fi
current_path="$(dirname "${current_path}")"
done
echo "${laravel_path}"
}
function __find_docker_compose() {
if (( ! $+commands[docker] )); then
return 1
fi
local plugin=$(docker compose 2>&1 | grep -o "docker compose")
if [[ -n "${plugin}" ]]; then
echo "docker compose"
elif (( $+commands[docker-compose] )); then
echo "docker-compose"
else
return 1
fi
}
function __artisan_completion() {
compadd $(php $(__find_laravel_root)/artisan list --raw --no-ansi | awk '{print $1}' | sed 's/:$//')
}
function __check_artisan() {
if [[ -z "$(__find_laravel_root)" ]]; then
unfunction artisan &>/dev/null
return 1
fi
function artisan() {
eval "php $(__find_laravel_root)/artisan $@"
}
compdef __artisan_completion artisan
}
function __check_sail() {
if [[ -z "$(__find_laravel_root)" ]] || [[ -z "$(__find_docker_compose)" ]]; then
unfunction sail &>/dev/null
return 1
fi
if [[ ! -f "$(__find_laravel_root)/vendor/bin/sail" ]]; then
unfunction sail &>/dev/null
return 1
fi
function sail() {
eval "$(__find_laravel_root)/vendor/bin/sail $@"
}
}
add-zsh-hook chpwd __check_artisan
add-zsh-hook chpwd __check_sail