Setting up Mac Terminal with iTerm2 and Oh My Zsh
After finishing the configuration of SSH and Git, I hope to use a Mac terminal with an elegant theme. To fulfill this purpose, I used iTerm2 as the terminal and managed Zsh configuration via Oh My Zsh.
Install iTerm2
Install iTerm2, then open and configure its Profile
(color presets) like below.
Zsh is the default shell program on macOS and you can check the current shell by following the command line:
Install Oh My Zsh
To install Oh My Zsh, Runn the following commands in your terminal:
Configure Oh My Zsh
Open ~/.zshrc
to modify ZSH_THEME="robbyrussell"
to ZSH_THEME="agnoster"
.
Install Powerline Fonts
To install Powerline fonts, you can just copy, paste, and run these commands to your terminal.
then configure Font
(Meslo LG M DZ for Powerline) in iTerm2 as below:
Install Oh My Zsh Plugins
Clone zsh-autosuggestions
and zsh-syntax-highlighting
into $ZSH_CUSTOM/plugins (by default ~/.oh-my-zsh/custom/plugins)
Add the plugin to the list of plugins for Oh My Zsh to load (inside ~/.zshrc):
After runing source ~/.zshrc
, you will see as below.
However, I cannot normally use brew
it after installing Oh My Zsh.
Then I figured out that when installing Oh My Zsh,
it moves all contents of the existing .zshrc
file into a new file it creates called ~/.zshrc.pre-oh-my-zsh
.
To solve this issue, I add the following commands into .zshrc
as below:
Customize Keyboard Shortcuts on MacOS
When I used the terminal on Ubuntu, there was a keyboard shortcut, Ctrl
+ Alt
+ T
, which helped me quickly open a terminal.
But there is no same shortcut on macOS. Thus, I need to customize the keyboard shortcut as the same as on Ubuntu.
To customize the keyboard shortcut, click System Setting
> Keyboard
> Keyboard Shortcuts
> App Shortcuts
> +
.
Then I configured the shortcut as follows:
And it works.
Reference
- https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md
- https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/INSTALL.md
- https://stackoverflow.com/questions/76000164/in-macos-how-to-get-back-the-contents-of-zshrc-file-after-installing-oh-my
- https://support.apple.com/guide/mac-help/create-keyboard-shortcuts-for-apps-mchlp2271/14.0/mac/14.0