Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kenmasters/0250a7bf5ef2435b18bb2d4714f137e6 to your computer and use it in GitHub Desktop.
Save kenmasters/0250a7bf5ef2435b18bb2d4714f137e6 to your computer and use it in GitHub Desktop.
Create a Shell Script for Laravel Sail
Description: To automatically run Laravel Sail on any Laravel project without having to specify the ./vendor/bin/sail path each time, you can create a simple shell script or alias. This will allow you to start Sail with a single command. Here’s how you can do it:
This instruction was made on Windows 11 Version 23H2 WSL2 Ubuntu22.04
0. Begin
1. Create sail file inside /usr/local/bin
$ sudo touch sail
2. Modify contents of file
$ sudo vim sail
3. Add contents
#!/bin/bash
# Find and run the sail executable from the nearest vendor/bin directory
# Start from the current directory and search upwards
DIR="$(pwd)"
while [ "$DIR" != "/" ]; do
if [ -f "$DIR/vendor/bin/sail" ]; then
"$DIR/vendor/bin/sail" "$@"
exit 0
fi
DIR="$(dirname "$DIR")"
done
echo "No Sail executable found in any parent directory."
exit 1
4. Save and Close the file
Press Esc -> colon -> wq -> Enter
5. Make the Script Executable:
chmod +x sail
6. Done
@kenmasters
Copy link
Author

kenmasters commented Sep 14, 2024

now instead of typing ./vendor/bin/sail [command], now we can just type sail [command] inside of any Laravel project where sail is installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment