You may have noticed, I use Terminal a lot. As do many other Apple administrators. Personally, I like the Terminal to be non-flashy and out of the way with as little embellishment as possible.
That does not mean I don’t modify the standard Terminal settings. Over time I have actually modified them quite a lot and I thought it might be useful to share, what, how and why I changed them.
Of course the desire for minimalism is an entirely personal taste, but you can adapt these instructions to fit your tastes as well.
I use the ‘Basic’ window profile setting from Terminal app (Terminal > Preferences > Profiles) with a few minor changes. I use this trick to have randomly rotating light background colors. That way it is easier to find a specific session.
The default prompt for macOS is quite elaborate:
It shows the computer name, the current working directory name and the user name. As I described in this post on environment variables, you can change the prompt with the
PS1 environment variable. I like to have a short prompt:
export PS1="\W \$ "
This will only display the current working directory name
\W and the prompt
root). I have also added some control codes to color the directory dark gray and bold for some visual contrast. These codes are unfortunately quite illegible:
export PS1="\[\e[1;30m\]\W\[\e[m\] \\$ "
Different Prompt for
This works great when logging in locally. However, I want to be able to tell the difference between shell windows on the local computer and those that are
sshed to a remote computer. You can check for that in your
ssh process sets the
SSH_CLIENT environment variable:
if [[ -z "$SSH_CLIENT" ]]; then # local connection, change prompt export PS1="\[\e[1;30m\]\W\[\e[m\] \\$ " else # ssh connection, print hostname and os version echo "Welcome to $(scutil --get ComputerName) ($(sw_vers -productVersion))" fi
So if the
SSH_CLIENT variable is _un_set (
if [[ -z) then the prompt is changed to the short, colored prompt. Otherwise the default prompt, which shows the computer name and user as well, remains and I print a welcome message with the computer name (
scutil --get ComputerName) and the macOS version (
Of course, the
.bash_profile will have be installed on the remote Mac as well for this to work there.
You can test this by using
ssh to connect to
Suppressing the ‘Last Login’
I also suppress the ‘Last Login: …’ message you get on every new session. You can do this by creating the file
~/.hushlogin. This message can of course serve as a security measure, but only when you actually pay attention it.
.hushlogin file will also suppress the display of a ‘Motto of the Day,’ if present. (The contents of the file
If you still want to know when your account last logged in, you can use the
last command for a long list of logins or this command for just your last login:
$ last -1 $(whomai)