Jungle Coder
written by night, read by day
Just added post themes! Witness The Colors, and Exult!

PowerShell -nologo for interactive OSX shells.

The PowerShell core team has done a great job with improving PowerShell as an interactive experience, to the point that I’ve decided to use it as my interactive shell on OSX.

This will be a short article on setting up pwsh on macOS. It assumes that you have basic shell familiarity, and have homebrew installed.

chsh -s $SHELL is how one changes which shell is used by default for interactive shells. After running brew install pwsh, you should have /usr/local/bin/pwsh at the end of your /etc/shells file.

This works well for the most part, but every time you spawn a pwsh session, you’ll see some startup text. Suppressing this text is quite possible, but isn’t directly documented anywhere.

The first part of the puzzle is that any executable file can work as an entry in /etc/shells, which means we can create a sh (or zsh, in my case) script that starts pwsh with some flags.

Then, looking over the output of pwsh --help, two flags stand out:

-NoLogo | -nol

    Hides the copyright banner at startup of interactive sessions.

-Login | -l

    On Linux and macOS, starts PowerShell as a login shell, using /bin/sh to
    execute login profiles such as /etc/profile and ~/.profile. On Windows,
    this switch does nothing.
    [!IMPORTANT] This parameter must come first to start PowerShell as a login shell. The parameter is ignored if passed in any other position.

EDIT: In an earlier version of this article, I used zsh as the shebang line in these scripts, but ran into some bug around resizing the terminal. Switching to pwsh as the wrapping shell seems to fix that bug.

Putting this all together, I ran sudo nvim /usr/local/bin/pwsh.nologo and filled the file with the following contents:

#! /bin/local/bin/pwsh

/usr/local/bin/pwsh -Login -nol

After saving that, be sure to run sudo chmod +x /usr/local/bin/pwsh.nologo so that the script is executable.

Then, run chsh -s usr/local/bin/pwsh.nologo, and add

$env:SHELL = "/usr/local/bin/pwsh.nologo";

to your PowerShell profile (edit $PROFILE from a pwsh session, creating folders as needed).

Comments

Previously: Learning without Burnout
Next: My Janet Story