Rasmus Olsson

Productive with the Terminal

February 07, 2021

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:

  1. Turn on computer.
  2. Login
  3. Start PowerShell
  4. Cd to git repositories for what I’m working on
  5. Git fetch/pull/rebase to make sure I have the latest code
  6. Start Build + Start IDE’s + Run
  7. Open up available MR’s/PR’s
  8. Open up the issue management system for example JIRA
  9. 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.

  1. Open up PowerShell and edit $PROFILE, for example code $PROFILE
  2. Add a function called Good-Morning
function Good-Morning { }
  1. 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:

  1. Turn on computer.
  2. Login
  3. Start PowerShell
  4. Good-Morning

And when we feel comfortable, we can add it to start-up resulting in:

  1. Turn on computer.
  2. 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!

please share