diff --git a/laravel-sail.plugin.zsh b/laravel-sail.plugin.zsh index c47108f..c527203 100644 --- a/laravel-sail.plugin.zsh +++ b/laravel-sail.plugin.zsh @@ -1,34 +1,44 @@ export APP_SERVICE=${APP_SERVICE:-"laravel.test"} function s() { - if [[ $1 == "cinit" ]]; then - docker run --rm \ - -u "$(id -u):$(id -g)" \ - -v $(pwd):/var/www/html \ - -w /var/www/html \ - laravelsail/php${2:=81}-composer:latest \ - composer install --ignore-platform-reqs - elif [[ $1 == "ninit" ]]; then - docker run --rm \ - -u "$(id -u):$(id -g)" \ - -v $(pwd):/var/www/html \ - -w /var/www/html \ - node:${2:=17} \ - npm install - else - [ -f sail ] && sh sail $* || sh vendor/bin/sail $* + local sail_path=`_find_sail` + + if [[ $1 == "cinit" ]]; then + docker run --rm \ + -u "$(id -u):$(id -g)" \ + -v $(pwd):/var/www/html \ + -w /var/www/html \ + laravelsail/php${2:=81}-composer:latest \ + composer install --ignore-platform-reqs + elif [[ $1 == "ninit" ]]; then + docker run --rm \ + -u "$(id -u):$(id -g)" \ + -v $(pwd):/var/www/html \ + -w /var/www/html \ + node:${2:=17} \ + npm install + else + if [ "$sail_path" = "" ]; then + >&2 echo "laravel-sail: sail executable not found. Are you in a Laravel directory?\nif yes try install Dependencies using 's cinit' command" + return 1 fi + $sail_path $* + fi +} +function sa() { + s artisan $* +} +function sc() { + s composer $* } # alias s='bash ./vendor/bin/sail' alias sup='s up' alias sud='s up -d' alias sdown='s down' -alias sa='s artisan' alias saqw='s artisan queue:work' alias saql='s artisan queue:listen' alias sasw='s artisan schedule:work' alias sasr='s artisan schedule:run' alias sp='s php' -alias sc='s composer' alias sn='s npm' alias spn='s exec -u sail $APP_SERVICE pnpm' alias sy='s yarn' @@ -47,3 +57,29 @@ alias sbn='s build --no-cache' alias sshare='s share' alias stan='sp ./vendor/bin/phpstan' alias spint='sp ./vendor/bin/pint' +compdef _artisan sa +compdef _composer sc +function _artisan() { + if [ -f "./vendor/bin/sail" ]; then + compadd $(sa --raw --no-ansi list | sed "s/[[:space:]].*//g") + fi +} +function _composer() { + if [ -f "./vendor/bin/sail" ]; then + compadd $(sc --raw --no-ansi list | sed "s/[[:space:]].*//g") + fi +} +function _find_sail() { + local dir=. + until [ $dir -ef / ]; do + if [ -f "$dir/sail" ]; then + echo "$dir/sail" + return 0 + elif [ -f "$dir/vendor/bin/sail" ]; then + echo "$dir/vendor/bin/sail" + return 0 + fi + dir+=/.. + done + return 1 +}