Creating profiles for PowerShell
A small thing I learned today: you can bundle a bunch of commands you type all the time into a single word. Here's how, and why it's worth doing.
The Problem
I am currently building my academy website, and I run it on my own machine first to test it. Every few testing sessions, I need to download the latest changes from GitHub (I’m building this with Claude), and sometimes I have local changes of my own. I can’t simply grab the new changes unless I wipe my local ones first (or commit them, which I don’t want to do).
So the routine is: throw away the experiments, download the newest version of the project, and start up the local server. Test, tweak, repeat. All day.
The problem is that this is a handful of separate typed commands, in order, every single time (which is really annoying):
cd C:\Users\me\code\academy
git fetch origin
git reset --hard origin/main
git clean -fd
npm run dev
Which means:
- go to the project folder
- wipe local changes and grab the latest
- launch it so I can test in the browser
And every time I get annoyed at something, I ask Claude: hey man, this is annoying, halp!
Well, today I learned I can bundle all of these commands into a single word I type once. Call it restart, or academyrestart, or whatever you like. So instead of typing out that whole block above every time, I now just type:
academyrestart
(almost). And I can do the same for plenty of other commands, which is the whole reason I’m writing this. Here’s how I set it up.
What’s a profile?
The tool I type commands into is called PowerShell. It comes with a personal settings file called a profile. Anything you put in there loads automatically every time you open a new window, so it’s the perfect home for shortcuts. Open yours like this:
notepad $PROFILE
$PROFILE is just PowerShell’s name for “my settings file.” If it doesn’t exist yet, create it first with New-Item -ItemType File -Path $PROFILE -Force, then run the line above. Notepad opens, and now you can teach PowerShell new words.
By default this file is named Microsoft.PowerShell_profile.ps1. I kept the name as it is, no reason to rename it. (And if I learn new things in the future, I’ll come back and add links here or update this article.)
Writing the shortcut
A shortcut is called a function: a name, then the commands it should run inside curly braces. Here’s academyrestart:
function academyrestart {
Set-Location C:\Users\me\code\academy
git fetch origin
git reset --hard origin/main
git clean -fd
npm run dev
}
Reading it line by line:
function academyrestart { ... }means “make a new word calledacademyrestart; when I type it, run everything inside the braces.”Set-Locationis PowerShell’s version ofcd. It moves into the project folder so the git commands run in the right place.git fetch originchecks GitHub for the newest version of the project.git reset --hard origin/mainis the wipe. It throws away my local experiments and forces the project to match GitHub exactly.git clean -fddeletes any leftover new files the reset didn’t cover, leaving a perfectly clean slate.npm run devstarts the local server so I can open the site in my browser and test it.
That multi-line version is the readable one. If you’d rather keep it on a single line, here it is for each PowerShell version. Use whichever matches yours:
For PowerShell 5:
function academyrestart { Set-Location C:\Users\me\code\academy; git fetch origin; git reset --hard origin/main; git clean -fd; npm run dev }
For PowerShell 7:
function academyrestart { Set-Location C:\Users\me\code\academy; git fetch origin && git reset --hard origin/main && git clean -fd && npm run dev }
The difference is just the separator between commands. Version 5 uses semicolons (;), which run the next command no matter what. Version 7 also understands &&, which only runs the next command if the previous one succeeded, so a failure stops the chain instead of charging ahead. (Notice the Set-Location still uses a semicolon even in the version 7 line: you always want the folder change to happen, so only the git steps are chained with &&.) Not sure which version you’re on? Run $PSVersionTable.PSVersion and check the first number. Either way, the shortcut works.
Save the file (Ctrl+S). To use it without reopening PowerShell, run this once to reload the profile:
. $PROFILE
That leading dot-space is a “re-read my settings now” command. From here on, every new window already knows the word, so you’ll rarely need it again. Type academyrestart in your project and watch every step run itself, ending with the local server booting up.
Note to future me: Yes, you literally just type academyrestart and hit enter. Nothing goes before it. It’s a real command now, exactly like cd or git. The one exception: if you just edited the profile in a window that was already open, run . $PROFILE once (or close and reopen the window) so it picks up the change. Any fresh window already has it loaded.
A few more ideas for the profile
Once you’ve got one shortcut, the same file holds as many as you want. A couple I found genuinely handy:
Save your work to GitHub in one line. This stages everything, commits it with a message you pass in, and pushes. The $args part means “use whatever I type after the command as the commit message”:
function save { git add -A; git commit -m "$args"; git push }
Then you’d type save fixed the login bug and it commits with that message. (Note: this one is the opposite of academyrestart. It keeps your changes and sends them up, rather than throwing them away.)
Open the current folder in File Explorer. Tiny, but handy when you’re deep in a terminal and want the graphical view:
function here { explorer . }
Re-open the profile to edit it. The most meta one of all, a shortcut for editing your shortcuts:
function editprofile { notepad $PROFILE }
In short
Because the profile is saved to disk, it sticks around. You can keep adding as many functions as you like, and they’ll all be loaded and ready the moment you open a new window, or right away if you run . $PROFILE after editing. One file, your whole collection of shortcuts, always there.
So next time something feels repetitive, that’s usually the signal to ask whether it can be one word instead.
Thanks for reading! Let me know how you’re going to use this.