Skip to content

Commit

Permalink
Update laravel-sail.plugin.zsh
Browse files Browse the repository at this point in the history
add auto-completion for artisan and composer commands.
add sail discovery so you can run sail commands from any directory inside your laravel project
  • Loading branch information
ariaieboy authored Aug 11, 2022
1 parent 5f70847 commit 5d92553
Showing 1 changed file with 54 additions and 18 deletions.
72 changes: 54 additions & 18 deletions laravel-sail.plugin.zsh
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
}

0 comments on commit 5d92553

Please sign in to comment.