Skip to content

Commit 99f7cdf

Browse files
committed
Merge branch 'release/v2023.02.02'
2 parents b6c2a58 + de42b75 commit 99f7cdf

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,25 @@
99
</p>
1010

1111
Plugin for skiping the `php` command when running artisan commands and `./sail` or `./vendor/bin/sail` when running sail commands.
12+
13+
## Installation
14+
15+
```bash
16+
# Using oh-my-zsh
17+
git clone https://github.com/baliestri/laravel.plugin.zsh.git $ZSH_CUSTOM/plugins/laravel.plugin.zsh
18+
# Add laravel to the plugins array in your zshrc file.
19+
20+
# Using zinit
21+
zinit light baliestri/laravel.plugin.zsh
22+
23+
# Using zi
24+
zi light baliestri/laravel.plugin.zsh
25+
```
26+
27+
## Usage
28+
29+
```bash
30+
cd /path/to/laravel/project # laravel subdirectory
31+
artisan # instead of php artisan
32+
sail # instead of ./sail or ./vendor/bin/sail
33+
```

laravel.plugin.zsh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright (c) Bruno Sales <[email protected]>. Licensed under the MIT License.
2+
# See the LICENSE file in the project root for full license information.
3+
4+
function __find_laravel_root() {
5+
local current_path="$(pwd)"
6+
local laravel_path=""
7+
8+
until [[ "${current_path}" -ef "/" ]]; do
9+
if [[ -f "${current_path}/artisan" ]]; then
10+
laravel_path="${current_path}"
11+
break
12+
fi
13+
14+
current_path="$(dirname "${current_path}")"
15+
done
16+
17+
echo "${laravel_path}"
18+
}
19+
20+
function __find_docker_compose() {
21+
if (( ! $+commands[docker] )); then
22+
return 1
23+
fi
24+
25+
local plugin=$(docker compose 2>&1 | grep -o "docker compose")
26+
27+
if [[ -n "${plugin}" ]]; then
28+
echo "docker compose"
29+
elif (( $+commands[docker-compose] )); then
30+
echo "docker-compose"
31+
else
32+
return 1
33+
fi
34+
}
35+
36+
function __artisan_completion() {
37+
compadd $(php $(__find_laravel_root)/artisan list --raw --no-ansi | awk '{print $1}' | sed 's/:$//')
38+
}
39+
40+
function __check_artisan() {
41+
if [[ -z "$(__find_laravel_root)" ]]; then
42+
unfunction artisan &>/dev/null
43+
return 1
44+
fi
45+
46+
function artisan() {
47+
eval "php $(__find_laravel_root)/artisan $@"
48+
}
49+
50+
compdef __artisan_completion artisan
51+
}
52+
53+
function __check_sail() {
54+
if [[ -z "$(__find_laravel_root)" ]] || [[ -z "$(__find_docker_compose)" ]]; then
55+
unfunction sail &>/dev/null
56+
return 1
57+
fi
58+
59+
if [[ ! -f "$(__find_laravel_root)/vendor/bin/sail" ]]; then
60+
unfunction sail &>/dev/null
61+
return 1
62+
fi
63+
64+
function sail() {
65+
eval "$(__find_laravel_root)/vendor/bin/sail $@"
66+
}
67+
}
68+
69+
add-zsh-hook chpwd __check_artisan
70+
add-zsh-hook chpwd __check_sail

0 commit comments

Comments
 (0)