Essential Terminal Settings for macOS
Tags: linux, beginners, tutorial
Published: 2023-11-20 10:31:27

I recently set up my new MacBook and am glad to share the minimal terminal settings that can benefit everyone, even those who prefer to avoid complicated customizations. As a product manager with foundational Linux skills, I value simplicity in my terminal setup without colorful themes, uncommon shortcuts, and plugins. Nevertheless, there are many features worth exploring and experimenting with.

![My terminal screen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4teat9s993rxv7oo2mcn.png)


## Terminal and Preferences

iTerm is the default terminal for Mac. The main missing functionality is advanced tab management, specifically tab splitting into panes. iTerm2 serves better for multitasking.

Download and install iTerm2 from the official website: [iTerm2 Downloads](https://iterm2.com/downloads.html).

Open iTerm2 and navigate to `iTerm2 -> Preferences -> Profiles -> Text -> Font` to increase the font size. 

## Package Manager

A package manager simplifies the process of installing, updating, and removing software packages on a computer. Homebrew is a package manager designed specifically for macOS.
To install [HomeBrew](https://brew.sh/) run the command:

```
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```
Follow instructions from the installation output to add Homebrew to the path. It should look like the commands below.  Please make sure ”[username]” is filled with your actual username.

```
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/[username]/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
```

## Oh-My-Zsh

Oh-My-Zsh is a community-driven framework for managing zsh shell configurations.
To install [Oh-My-Zsh](https://ohmyz.sh/#install) run the command:

```
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
```

I don’t use too many features and plugins available, but there are some functionalities that I find particularly beneficial:

- Auto-completion with Tab. To try it, type, for example, ‘host’ press the second time to allow cycling through the list and choose the command you want, then it will automatically fill the rest of the words and hit `Enter`.
- Installed Software Checks. If you search for packages, all installed software is checked in the output.


![Feature demonstration: brew search xq. In the output xq utility is marked as installed.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rvhbi086akq4qw1eakwc.png)


- Preset Aliases. Aliases allow users to create custom shortcuts for commonly used commands such as `l=’ls -lah’`. Some of them are already set up. To see the full list of aliases type `alias`; 

- Hiding `user@hostname` for shell prompt.


## ZSH Plugins
There are many plugins to experiment with. I also use some of them.

The [zsh-autosuggestions](https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md) plugin suggests commands that you've previously used in your command history. To accept a suggestion, simply press the right arrow key.


![Feature demonstration: the zsh-autosuggestions plugin suggests the last run command.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ub2zer8b3lw5dyzcmalp.png)


To install run the command:
```
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
```

The [zsh-syntax-highlighting](https://github.com/zsh-users/zsh-syntax-highlighting) plugin highlights the commands in a code style. 


![Feature demonstration: the zsh-syntax-highlighting plugin highlights syntax of the command.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sbkgk3gde7ifw4oi0aby.png)



To install run the command:
```
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
```

Open the ”~/.zshrc” file and modify the plugins line:

```
plugins=(git zsh-autosuggestions zsh-syntax-highlighting web-search)
```
To enable the change run: `source ~/.zshrc`

`web-search` plugin allows you to open browser. Type, for example, `google homebrew`.

## Tabs and Panes
iTerm2 supports tabs and panes for better multitasking. Experiment with `Cmd + T` for tabs and `Cmd + D` or `Cmd + Shift + D` for horizontal and vertical panes. 
For me, the most convenient way to navigate between tabs is pressing `Cmd + left/right`. This is already available if you use `xterm Defaults` mapping. However, many users opt to enable Natural Text Editing. I prefer to retain `xterm Defaults` and configure key mapping available for Natural Text Editing. My must-have is to move the cursor by words and remove words at once.

In the Preferences window, go to the `Profiles` tab and then `Keys -> Key Mappings`.

- Move a word backwards using `option + left` and a word forwards using `option + right`.


![Keyboard Shortcut: option + left arrow key. Action: Send Escape Sequence. Esc+b](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nqyjzq86e66urqarbypw.png)
Keyboard Shortcut: `option + left`. Action: Send Escape Sequence. Esc+b

![Keyboard Shortcut: option + right arrow key. Action: Send Escape Sequence. Esc+f](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4d7nbp0bnjofsfffsbje.png)
Keyboard Shortcut: `option + right`. Action: Send Escape Sequence. Esc+f

- Delete a word backwards using `option + delete`.

![Keyboard Shortcut: option + delete key. Action: Send Hex Code. Code: 0x17](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m4qec3dmx5n044unn75c.png)
Keyboard Shortcut: `option + delete`. Action: Send Hex Code. Code: 0x17

##  Shortcuts
There are many shortcuts that don't need to be configured but are worthy learning. I use the following:
- `ctrl + C` stops a running program immediately;
- `ctrl + U` erases everything from the current cursor position to the beginning of the line;
- `ctrl + L` clears the terminal screen;
- `cmd + W` closes the current tab;
- `ctrl + R`  shows the last command that matches the string you typed. Press again to see older results.

## Conclusion
Although customization might seem time-consuming, minor adjustments can save time and help focus on your day to day tasks. Confidence and efficiency in using your tools are implicit but empower for coming up with great solutions.