This post is a Mac version of a post I wrote a couple of years ago titled Take Your Windows Terminal and Powershell to the next level.

Michael’s PowerShell Terminal

Let’s walk through the steps I took to get my shell working like Michael’s on Mac.

Several items need to be installed for the profile to work:

  • Nerd Font - this is the font that provides the icons for folders and files
  • Starship - The minimal, blazing-fast, and infinitely customizable prompt for any shell!
  • Terminal-Icons - PowerShell module to display the icons from the Nerd Font
  • devtoolbox - a PowerShell module with a bunch of useful aliases for dev tools that Michael released
  • PSReadLine - a PowerShell module that allows predictive suggestions as you type a command

Font Install

Nerd Fonts patches developer targeted fonts with a high number of glyphs (icons). Specifically to add an increased number of extra glyphs from popular ‘iconic fonts’ such as Font Awesome, Devicons, Octicons, and others.

I am using the CaskaydiaCove Nerd Font from Nerd Font.

To install:

  1. Open Terminal or whatever shell you are using

  2. Update brew with the nerd fonts

    brew tap homebrew/cask-fonts
    

    If you are not using brew, you can install it at https://brew.sh

  3. Install the font

    brew install --cask font-caskaydia-cove-nerd-font
    

Powershell Install

  1. After the font is installed, you need to install Powershell

    brew install powershell/tap/powershell
    
  2. To Launch Powershell, run:

    pwsh
    

Powershell Profile Setup

Next, we need to tell Mac Terminal to use the CaskaydiaCove Nerd Font that was just installed.

  1. In Terminal, Open settings by pressing Command+, or clicking on the Terminal menu and selecting Settings
  2. Click the + to add a new Profile or Duplicate your existing profile
  3. Name the new profile Powershell
  4. Click the Change… button under Font
  5. Click All Fonts
  6. Find CaskaydiaCove Nerd Font and Select it
  7. For the style, select Regular
  8. Click the Font Window

Now we need to tell Terminal to automatically launch Powershell as our default Terminal shell

  1. Under the settings for the Powershell profile, click the Shell tab

  2. Under Startup, check the Run command: box

  3. Add the following command:

    /usr/local/microsoft/powershell/7/pwsh
    
  4. Uncheck Run inside shell

  5. Under the Ask Before closing, add the following:

    -pwsh
    pwsh
    
  6. Close the Settings

  7. Quit Terminal and Relaunch it

Use brew in Powershell

In order to use brew in Powershell you need to run the brew shellenv command to set up the profile environment variables.

  1. Run: vi $profile

  2. Add the following to the file:

    $(/opt/homebrew/bin/brew shellenv) | Invoke-Expression
    
  3. Refresh the Powershell profile by running

    . $profile
    

    You might need to restart Terminal for the profile changes to be picked up

Starship

Next, we need to install Starship, the minimal, blazing-fast, and infinitely customizable prompt for any shell!

You install Starship using

curl -sS https://starship.rs/install.sh | sh

Note: I had issues installing starship with brew and Powershell not recognizing starship command, so using manual install above.

Now that we have Starship installed, we need to add it to our PowerShell profile.

  1. Open PowerShell

  2. Open the profile by typing vi $profile

  3. Add the following line at the top of the profile and save it

    Invoke-Expression (&starship init powershell)
    

Terminal-Icons

Terminal Icons is a PowerShell module to show file and folder icons in the terminal.

  1. To install, open PowerShell and run:

    Install-Module Terminal-Icons -Scope CurrentUser
    
  2. To use the Terminal Icons, add the following line to your PowerShell profile

    Import-Module Terminal-Icons
    

devtoolbox

devtoolbox is a set of aliases for common developer command for docker, docker-compose, and git.

You can install devtoolbox from the PowerShell Gallery

Install-Module -Name devtoolbox

To use the devtoolbox now that we have installed it, open up your PowerShell profile and add the following statement.

Import-Module devtoolbox

PSReadLine Predictions

For the predictive suggests when typing commands, we need to install PSReadline.

In a PowerShell administrator shell, run

Install-Module PSReadLine -RequiredVersion 2.2.2 -Force

Needed to use -Force to have it install PSReadLine 2.2

To our PowerShell profile, we need to add the following lines:

Import-Module PSReadLine

Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -EditMode Windows

update function

The update function is designed to make it easy to update powershell to the latest version

function update {
  brew update
  brew upgrade powershell
}

I would suggest that you run the update command and install the latest cross platform version. Once you get the cross-platform version installed, you need to install the PowerShell modules above and create the profile.

profile ended

The last piece is to set up the profile function to launch the profile into VSCode quickly.

function profile {
  code $profile
}

Now your prompt is just like Michael’s.

Full PowerShell Profile

There is a couple of bonus functions like getting a random fact, a dad joke, convert a temp to C, and convert a temp to F.

Originally posted by Michael Jolley

Invoke-Expression (&starship init powershell)
Import-Module Terminal-Icons
Import-Module devtoolbox
Import-Module PSReadLine

Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -EditMode Windows

function fact {
  irm -Uri https://uselessfacts.jsph.pl/random.json?language=en | Select -ExpandProperty text
}

function joke {
  irm https://icanhazdadjoke.com/ -Headers @{accept = 'application/json'} | select -ExpandProperty joke
}

function 2C {
  param (
      [Parameter()]
      [Alias('Temp')]
      [int]
      $Temperature
  )

  ($Temperature - 30) / 2
}

function 2F {
  param (
      [Parameter()]
      [Alias('Temp')]
      [int]
      $Temperature
  )

  ($Temperature * 2) + 30
}

function update {
    brew update
    brew upgrade powershell
}

function profile {
  code $profile
}