[LINUX] Change your Mac terminal user name

This time I would like to explain how to change the part of the user name displayed on the Mac OS terminal. (This time, the explanation is for MacOS Catalina (2019/10) or higher, so the explanation is based on the assumption that a shell called zsh is used. If it is Mojave of an earlier OS, the shell name will be bash. Please note that some content may differ.)

Introduction

It's kind of like the trivia I just learned the other day, but the Mac environment has become a little more comfortable, so I'd like to share it with everyone who is reading this article.

Default display

First of all, I think the default display of the terminal looks like this. (The display has been changed for clarity.)

Terminal


username@hostname~ %

Change example

You can change this display, for example:

Terminal


~ %

This is a modification that hides the username and host name. I think this made it much cleaner and easier to see.

So how to change

Now I would like to explain how to actually change it. From the conclusion, you can customize the display to your liking by setting it in ** in the environment variable of the development environment **. Environment variables in the development environment are directories (folders) called ** ".zshrc" **. Open this directory and add to it. I think that the method of opening this ** ".zshrc" ** is different depending on the settings of each Mac, so sorry to trouble you, but I hope you can check it. If you set it yourself, open the directory with "vim ~ / .zshrc" from the terminal and then press "i" to change to the insert mode where you can edit, so edit after that.

Editing in ".zshrc"

Note that you should never erase existing characters (at the top). Your Mac may not work properly. </ font>

Let's edit it. Make a line with Enter etc. in the empty part at the bottom and edit it as follows.

.zshrc


export PS1="Describe the content you want to display here"

For example, in the case of the change example introduced at the beginning, edit as follows.

.zshrc


export PS1="%1~ %# "

Now the terminal display will look like "~%".


If you want to get the original default display, edit it like this.

.zshrc


export PS1="%n@%m %1~ %# "

Now the terminal display will be the original "username @hostname ~%" I think I'm back in.


After editing

In insert mode, press the esc key and then press: w q to exit ** [.zshrc] **. If you exit, you need to reflect it on the terminal, so enter ** "source ~ / .zshrc" **. (": Wq" means save and exit. ": Q" means save and exit) ("Source ~ / .zshrc" means reload .zshrc to reflect the changes)


You can freely change the terminal display as described above.

Now, let me explain a little about the content described earlier. When adding a new environment variable in the environment variable of the development environment, describe the content you want to add after ** "export" **. ** "PS1" ** used this time is an environment variable that determines the display format of the prompt.

Below is an excerpt from a list of symbols that can be used.

symbol What is displayed
%1~
%#
$ When a general user$, When root#Show
%n User name
%m hostname
%M hostname
%~ Current directory
%d Current directory
%c Current directory(Relative path)
%C Current directory(Relative path)
%# User type
%? Return value of the previous command
%D date(yy-mm-dd)
%W date(yy/mm/dd)
%w date(day dd)
%T time(hh:mm)
%t time(hh:mm(am/pm))

in conclusion

What did you think. Please customize the terminal display and lead a comfortable programming life. I hope this article will be of some help to you.

The site that I referred to this time

Summary of how to change / customize terminal display contents (prompt) [Shorten the lengthy display that appears on the terminal every time](https://qiita.com/tonkotsuboy_com/items/b752a86cee7eaedf28da#%E5%BF%AB%E9%81%A9%E3%81%AA%E3 % 82% BF% E3% 83% BC% E3% 83% 9F% E3% 83% 8A% E3% 83% AB% E3% 83% A9% E3% 82% A4% E3% 83% 95% E3% 82 % 92) [How to change the prompt display (user name etc.) of Mac terminal (zsh)](https://code-graffiti.com/how-to-change-the-prompt-display-on-the-mac-terminal /)

Recommended Posts

Change your Mac terminal user name
File name batch change
[Linux] Change user password
Install numba on your Mac
Install Django on your Mac