Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart terminal without closing on MacOS

How to restart my current MacOS terminal session without closing the window?

In Linux I use exec bash but it does not work in this environment. I made a few changes to the .bash_profile (prompt, alias etc) I would like to see without closing it and opening again.

thanks in advance

like image 211
blagus Avatar asked Jul 29 '19 23:07

blagus


People also ask

How do I save and exit a Terminal Mac?

You can also use command mode to save and quit in one command: Press the ESC key to enter command mode (getting out of Insert mode) Type :wq and hit return.

How do I reset my Terminal?

The best method to reset your terminal is with the reset command. This will wipe everything that is currently in the terminal, including the scrollback buffer (in most terminal applications), and should fix issues such as a bugged terminal or one that is displaying strange characters.

How do you go to Home and End in Terminal Mac?

For those that prefer to use the arrow keys, hitting fn Shift + Left Arrow will take you home on the command line. Similarly, fn Shift + Right Arrow will take you to the end. Save this answer.


2 Answers

Just type in the command:

exec bash -l 

I guess that should do it.

For zsh,

exec zsh -l 

This is needed because every shell on macOS by default is a login shell.

Justing writing exec bash would replace the current shell with a non-login shell which is not the same effect as closing and re-opening the terminal.

exec would make new bash -l process replace the current shell. If exec is not used, bash -l would spawn a new shell over the current shell incrementing the $SHLVL.

like image 106
Mihir Luthra Avatar answered Sep 19 '22 22:09

Mihir Luthra


For me none of the other solutions work for ZSH.

Simply source ~/.zshrc did the job actually.

Note: running exec zsh -l outputs /Users/my_username/.zprofile:3: command not found: yarn (where my_username is my username). But running only the command mentioned above does the job.

like image 27
Dan Maia Avatar answered Sep 19 '22 22:09

Dan Maia