Essential Terminal Settings for macOS

zerocodilla

Nadezhda Yuzhakova

Posted on November 20, 2023

Essential Terminal Settings for macOS

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

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.

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 run the command:



/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"


Enter fullscreen mode Exit fullscreen mode

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)"


Enter fullscreen mode Exit fullscreen mode

Oh-My-Zsh

Oh-My-Zsh is a community-driven framework for managing zsh shell configurations.
To install Oh-My-Zsh run the command:



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


Enter fullscreen mode Exit fullscreen mode

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.

  • 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 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.

To install run the command:



git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions


Enter fullscreen mode Exit fullscreen mode

The zsh-syntax-highlighting plugin highlights the commands in a code style.

Feature demonstration: the zsh-syntax-highlighting plugin highlights syntax of the command.

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


Enter fullscreen mode Exit fullscreen mode

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



plugins=(git zsh-autosuggestions zsh-syntax-highlighting web-search)


Enter fullscreen mode Exit fullscreen mode

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
Keyboard Shortcut: option + left. Action: Send Escape Sequence. Esc+b

Keyboard Shortcut: option + right arrow key. Action: Send Escape Sequence. Esc+f
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
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.

💖 💪 🙅 🚩
zerocodilla
Nadezhda Yuzhakova

Posted on November 20, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related