Improved Shell (MacOS)
Tags: macos, zsh, setup, terminal
Published: 2022-07-23 07:53:00

MacOS comes with a default terminal, but it might be convenient to customized it to improve user experience.

## Homebrew

Homebrew is a package manager for MacOS, we will use it to install all the software on Mac.
- Open the web browser
- Visite [homebrew](https://brew.sh/)
- Follow install instructions...

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

- Proceed with installation
- Follow instructions to add homebrew to your PATH

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

### To install software using homebrew:
- Open the web browser
- Visite [homebrew](https://brew.sh/)
- Search for the software
- Copy the recipe
- Open 'Terminal'
- Paste the recipe and run the command.
- Follow installation instructions...

## Git
Git is a version control software. It is also wildely use to distribure software.
- Open 'Terminal'
- Install git from homebrew

```
brew install git
```

- Check git version

```
git --version
# git version 2.30.1 (Apple Git-130)
```

## Fonts
We will change the default font of the terminal in preparation for the theme we will install later.
- Open the web browser
- Visit [powerlevel10K - Fonts](https://github.com/romkatv/powerlevel10k#meslo-nerd-font-patched-for-powerlevel10k)
- Install the recommended fonts (MenloLGS)
  - Download the font files from the github links
  - Open Font Book
  - Click on '+' icon
  - Select the MesloLGS files
  - Click 'Open'

## Color theme
Default terminal colors can be inappropriate. They do not play well with the theme we will install later.
- Open the web browser
- Visit [tomorrow theme](https://github.com/chriskempson/tomorrow-theme)
- Download the theme for 'OS X Terminal'
- Open 'Terminal'
- Navigate to the menu 'Terminal / Preferences...'
- Navigate to the tab 'Profiles'
- Below the list of profiles, click on '...'
- Select 'Import...'
- Select `Tomorrow Night.terminal` file
- Click on 'Open'
- In the list of profiles, select 'Tomorrow Night'
- Click on 'Default'
- Change font to 'Menlo LGS NF'

## Oh My Zsh
MacOS come with a minimal terminal. In this section, we will configure the terminal to add some features and style using [Oh My ZSH](https://ohmyz.sh/) and the theme [Powerlevel10k](https://github.com/romkatv/powerlevel10k).

- Open the web browser
- Visite [Oh My Zsh](https://ohmyz.sh/)
- Follow Install instructions...

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

![OMZ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/76de0zh3d7yk3dv2lkja.png)

## Powerlevel10K
Theme that add useful infomation right in the prompt.
- Open the web browser
- Visite [powerlevel10k](https://github.com/romkatv/powerlevel10k)
- Follow Powerlevel install instructions...

```
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
```

- Install zsh-autosuggestions plugin that provides autocompletion based on our previous commands

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

- Install exa a modern replacement for ls.

```
brew install exa
```

- Edit .zshrc to enable powerlevel theme

```
vim .zshrc
```

- Press 'i' to enter insert mode
- Uncomment options and edit file as follow...

```
# ZSH_THEME="robbyrussell"
ZSH_THEME="powerlevel10k/powerlevel10k"

DISABLE_MAGIC_FUNCTIONS="true"

DISABLE_LS_COLORS="true"

ENABLE_CORRECTION="true"

COMPLETION_WAITING_DOTS="true"

DISABLE_UNTRACKED_FILES_DIRTY="true"

plugins=(git zsh-autosuggestions)

# Alias of ls using exa
if [ -x "$(command -v exa)" ]; then
    alias ls="exa --icons"
    alias ll="exa --icons --long"
    alias la="exa --icons --long --all --group"
    alias lt="exa --icons --long --all --group --git --tree"
fi
```

- Press 'esc' to exit insert mode
- Press ':' and 'x' end 'return' to save and quit the file
- Update Terminal

```
source .zshrc
```

- Follow instructions to customise the prompt


![EXA](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sgv7bl7jv2p9finurr64.png)

## Check Config

- Install neofetch from homebrew

```
brew install neofetch
```

- Check config

```
neofetch
```

![fetch](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k4a8qy6t6enfay29ftxh.png)

> Next, I suggest you follow [Environment Manager - Conda](https://dev.to/mhebrard/environment-manager-conda-1dcp).