TIL Aliasing commands in Powershell
POSTED ON:
TAGS: terminal win10 timesaver
If you happen to use a lot of the same commands in Windows PowerShell, look into creating alias.
//In a Win10 Powershell
notepad $profile
That will open up notepad file. That file is what Powershell will look at before loading.
In that file, paste this in:
function goSomewhereThenOpenGoogleThenDeleteSomething {
cd C:\Users\
Start-Process -FilePath "http://www.google.com"
rm fileName.txt
}
Set-Alias google goSomewhereThenOpenGoogleThenDeleteSomething
Now you can type the word "google" into Windows PowerShell, it will:
- change directory
- open a browser page that points to google.com
- remove a fileName.txt from that user folder.
I use docker/devilbox config. This is my shortcut:
function startDocker {
cd E:\devilbox
docker-compose up -d bind httpd mysql php
Start-Sleep -Second 30
Start-Process -FilePath "http://localhost/"
}
Set-Alias start-docker startDocker
That will change into a directory, turn on my docker, wait 30 seconds (which is roughly how long it takes), and then load a browser page with my docker/devilbox configuration.
Via StackOverflow
I had to modify security settings too. https://stackoverflow.com/a/50309277/4096078
NOTES:
- Be sure to restart powershell so it loads up the file again.
- I used a wait method because i'm still learning PowerShell commands. A better option would be to use a 'when the previous command is finished, then excute the next one'.
Related TILs
Tagged: terminal