When I’m working on a long-running project, It’s not unusual to be working in a specific area of the code base for a while. Being productive with the terminal and take time to set up terminal automation may save a lot of time in the long run.
In this post I will show some of my techniques I do to be more productive. I will be using PowerShell on Windows Terminal in this example.
Imagine we are focusing the upcoming months in an area involving the following:
- A MSSQL database
- An .NET Core API
- A React SPA frontend
- A normal morning would include:
A normal morning could like something like:
- Turn on computer.
- Login
- Start PowerShell
- Cd to git repositories for what I’m working on
- Git fetch/pull/rebase to make sure I have the latest code
- Start Build + Start IDE’s + Run
- Open up available MR’s/PR’s
- Open up the issue management system for example JIRA
- Open up the chat
That’s quite a lot of manual steps.
Let’s look at how we can automate that.
In PowerShell, you can add global functions to your profile.
- Open up PowerShell and edit $PROFILE, for example code $PROFILE
- Add a function called Good-Morning
function Good-Morning {
}
- Step, 3-6 (cd repo, get the latest code, build code, start IDE, run code)
function Good-Morning {
Morning-Frontend
Morning-Backend
Morning-Database
};
function Morning-Frontend {
wt.exe PowerShell.exe, "-NoExit", "-Command",
"& {
Push-Location C:\git-frontend-project \;
git pull \;
npm install \;
code . \;
npm start \;
}"
}
function Morning-Backend {
wt.exe PowerShell.exe, "-NoExit", "-Command",
"& {
Push-Location C:\git-backend-project \;
git pull \;
dotnet build \;
start your-solution-file \;
dotnet watch run your-cs-proj
}"
}
function Morning-Database {
wt.exe PowerShell.exe, "-NoExit", "-Command",
"& {
Push-Location C:\git-database-project \;
git pull \;
docker build -t database . && docker run -it database
}"
}
Ok great! Now that we have that out of the way, the rest of the steps will be easy.
Step 7 and 8. Accessing MR/PR’s on github.com and JIRA with chrome.
chrome.exe "https://github.com" "https://jira.com"
Step 9. Accessing Chat, lets say we use Slack. We bind and access the environment variable.
slack
That pretty much it, now we have the following morning routine:
- Turn on computer.
- Login
- Start PowerShell
- Good-Morning
And when we feel comfortable, we can add it to start-up resulting in:
- Turn on computer.
- Login
Full script below:
function Good-Morning {
Morning-Frontend
Morning-Backend
Morning-Database
chrome.exe "https://github.com" "https://jira.com"
slack
};
# New Terminal, latest code, build npm, open code, run
function Morning-Frontend {
wt.exe PowerShell.exe, "-NoExit", "-Command",
"& {
Push-Location C:\git-database-project \;
git pull \;
npm install \;
code . \;
npm start \;
}"
}
# New Terminal, latest code, build dotnet, open rider, run
function Morning-Backend {
wt.exe PowerShell.exe, "-NoExit", "-Command",
"& {
Push-Location C:\git-database-project \;
git pull \;
dotnet build \;
start your-solution-file \;
dotnet watch run your-cs-proj
}"
}
# New Terminal, latest code, build dockerfile and run
function Morning-Database {
wt.exe PowerShell.exe, "-NoExit", "-Command",
"& {
Push-Location C:\git-database-project \;
git pull \;
docker build -t database . && docker run -it database
}"
}
Happy Coding!