|
| 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