Mac環境構築(Alacritty + Zinit + Starship)

Macの環境構築をしたのでメモ。

#### 環境

- MacBook Pro M2(2023)
- MacOS Sequoia 15.1

## Homebrewインストール

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

## Alacrittyインストール

```sh
brew install --cask alacritty
```

#### `~/.config/alacritty/alacritty.toml`ファイルを作成

```sh:~/.config/alacritty/alacritty.toml
live_config_reload = true

[window]
dimensions = { columns = 200, lines = 60 }
padding = { x = 8, y = 4 }
opacity = 0.85

[cursor]
style = "Beam"

[scrolling]
history = 100000
multiplier = 3

[font]
normal = { family = "Hack Nerd Font", style = "Regular" }
bold = { family = "Hack Nerd Font", style = "Bold" }
italic = { family = "Hack Nerd Font", style = "Italic" }
bold_italic = { family = "Hack Nerd Font", style = "Bold Italic" }
size = 14.0
offset = { x = 0, y = 2 }
```

## Zinitインストール

```sh
bash -c "$(curl --fail --show-error --silent --location https://raw.githubusercontent.com/zdharma-continuum/zinit/HEAD/scripts/install.sh)"
```

```sh
zinit self-update
```

#### `~/.zshrc`を編集

```sh:~/.zshrc
# ----------------------------
# basic
# ----------------------------
# コマンド履歴の管理
HISTFILE=~/.zsh_history
export HISTSIZE=1000
export SAVEHIST=10000

# ----------------------------
# Added by Zinit's installer
# ----------------------------
if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then
    print -P "%F{33} %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
    command mkdir -p "$HOME/.local/share/zinit" && command chmod g-rwX "$HOME/.local/share/zinit"
    command git clone https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git" && \
        print -P "%F{33} %F{34}Installation successful.%f%b" || \
        print -P "%F{160} The clone has failed.%f%b"
fi

source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit

# ----------------------------
# Zinit plugins
# ----------------------------
# Load the pure theme, with zsh-async library that's bundled with it.
zinit ice pick"async.zsh" src"pure.zsh"
zinit light sindresorhus/pure
# シンタックスハイライト
zinit light zsh-users/zsh-syntax-highlighting
# 入力補完
zinit light zsh-users/zsh-autosuggestions
zinit light zsh-users/zsh-completions
# コマンド履歴を検索
zinit light zdharma/history-search-multi-word

# ----------------------------
# alias
# ----------------------------
alias g="git"
alias gb="git branch"
alias gs="git switch"
alias gco="git checkout"
alias gcmsg="git commit -m"
alias gl="git pull"
alias gp="git push"
```

## フォントインストール

starshipで必要なフォントをインストールする

```sh
brew install --cask font-hack-nerd-font
```

## Starshipインストール

```sh
curl -sS https://starship.rs/install.sh | sh
```

#### `~/.zshrc`の最後に以下を追記する

```sh
# ----------------------------
# Starship
# ----------------------------
eval "$(starship init zsh)"
```
#### プリセットを使って見た目を変更する

https://starship.rs/ja-JP/presets/

Pastel Powerlineを使いたい場合は以下のコマンドを実行

```sh
starship preset pastel-powerline -o ~/.config/starship.toml
```

## VSCodeのフォント設定

VSCodeのターミナルでアイコンが表示されるように設定する。

VSCodeで`settings.json`を開いて以下を設定する。

```sh:settings.json
 "terminal.integrated.fontFamily": "Hack Nerd Font"
```

## 参考

https://zenn.dev/okmkm321/scraps/91ceb7a8d8a626

https://zenn.dev/nagan/articles/8168ba0ca407ad