Merklin's avatar

[HOW TO] Create short (alias) artisan/composer commands for your editor on Windows.

Most people probably know this, but still, there is very little information on how to do this. Here is how I did it:

  1. Create a file named Microsoft.PowerShell_profile.ps1
  2. Place it somewhere easily accessible. For example in “C:\” drive
  3. Commands should be in the following format:
Set-Alias -Name pa -Value php-artisan
Function php-artisan { php artisan $args}
  • pa => the short tag/command you will use
  • php-artisan => the function name. It MUST be the same on the second line after Function
  • { php artisan $args } => the command to be executed, where $args allows you to add more arguments/options to the command
  1. Save the file.
  2. In your editor terminal run: . <path_to_file> If your file is named Microsoft.PowerShell_profile.ps1 and is in the c:\documents, then run: . c:\ documents\Microsoft.PowerShell_profile.ps1

IMPORTANT: DO NOT MISS the dot(.) in the beginning and the interval(space) after it!

You can take a look at my Gist what I use and download the file if you want to: https://gist.github.com/milenmk/fa8f6debe701147eca1372f70641d797

1 like
2 replies
Merklin's avatar

@tisuchi I am not struggling with this. I am just sharing a bit of experience that may help someone. :)

1 like

Please or to participate in this conversation.