This PowerShell script allows you to create a convenient alias for the php artisan command on Windows. The script automates the process of creating a batch file for the alias, adding the directory to the system PATH, and ensuring there are no conflicts with existing aliases. Additionally, it handles the cleanup of empty directories and their removal from the PATH if necessary.
The default alias is pia
- Creates a batch file alias for the
php artisancommand. - Adds the alias directory to the system PATH.
- Checks for conflicts with existing aliases and handles them appropriately.
- While creating an alias, if a php artisan alias already exists, it can clean up the old php artisan alias and delete its directory along with the PATH entry if there are no other files in the directory.
- Windows operating system.
- Administrator privileges to modify the system PATH.
-
Open Command Prompt:
- Press
Win + R, typecmd, and pressEnter.
- Press
-
Download the PowerShell script using the following command:
powershell -NoProfile -ExecutionPolicy Bypass -Command "Invoke-WebRequest -Uri https://raw.githubusercontent.com/Skysea45/windows-artisan-alias/main/windows-artisan-alias.ps1 -OutFile %TEMP%\windows-artisan-alias.ps1"
-
Run the downloaded PowerShell script with admin privileges using the following command:
powershell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File "%TEMP%\windows-artisan-alias.ps1"' -Verb RunAs}"
-
Starting the Script:
- When the script starts, it will check for administrator privileges. If not running as an administrator, it will prompt for the necessary permissions.
-
Options Menu:
- The script will present you with two options:
- Start the process.
- Exit.
- Select
1to proceed with creating the alias or2to exit the script.
- The script will present you with two options:
-
Directory Selection:
- The default directory for storing the alias batch file is
C:\aliases(it automatically detects your system disk even its not labeled as C ). - You will be asked if you want to change the default directory. Press
nto keep the default oryto specify a custom directory.
- The default directory for storing the alias batch file is
-
Alias Name Selection:
- The default alias name is
pia. - You will be asked if you want to change the default alias name. Press
nto keep the default oryto specify a custom alias name.
- The default alias name is
-
Conflict Check and Removal:
- The script will check if there is any existing
php artisanalias in the system PATH. - If a conflict is found, you will be prompted to remove the existing alias and use the new one. Press
yto proceed with the removal ornto cancel the alias creation process.
- The script will check if there is any existing
-
Alias Creation:
- The script will create the alias batch file in the specified directory.
- If the directory does not exist, it will be created.
- The directory will be added to the system PATH if not already present.
-
Cleanup:
- While creating same alies on different location, if an alias is removed and the old alias directory becomes empty, the directory and its PATH entry will also be removed to keep the system clean.
-
Completion:
- A message will be displayed indicating that the alias was successfully created and added to the PATH.
- The script will close automatically after a brief pause.
To ensure the integrity of the script, you can verify the SHA-256 hash of the downloaded script file. The SHA-256 hash for this script is:
SHA-256: DC3140AB9E29F8F8E5A104CA7EE66922EB36EFC9AB33E012A537E659B82CFBD9
To verify the hash on your system, run the following PowerShell command:
Get-FileHash windows-artisan-alias.ps1 -Algorithm SHA256 | Format-List Replace windows-artisan-alias.ps1 with the actual path where you saved the script.
Note: I have prepared this script based on my own testing and use cases. However, I am not responsible for any issues or damages that may arise from using this script.
Feel free to contribute to this project by submitting issues or pull requests on GitHub. Your feedback and contributions are greatly appreciated!
This project is licensed under the MIT License.