Open7

Macのターミナル構築でやったこと

sadotchisadotchi

Mac miniを購入し久しぶりにMacの環境構築をしたので覚え書きとしてやったことを残していく。
自分の次回の環境構築を楽にする目的なので、個人の好みも多分に含めていく。

sadotchisadotchi

iTerm2をインストール

https://iterm2.com/ からiTerm2をダウンロード。
ダウンロード後はインストーラーを起動して表示される手順に従ってインストール。

sadotchisadotchi

Homebrewをインストール

iTerm2からHomebrewをインストール。
https://brew.sh/ja/ に書いてあるコマンドをコピーして実行。

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

上記コマンドを実行し終えると最後に下記が出るので、書いてあることに従って3つのコマンドを実行。

==> Next steps:
- Run these commands in your terminal to add Homebrew to your PATH:
    echo >> /Users/{ホームディレクトリ名}/.zprofile
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/{ホームディレクトリ名}/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"

最後にbrewコマンドを実行してインストール動作確認。

brew --version
sadotchisadotchi

Oh My Zshをインストール

https://ohmyz.sh/ に書いてあるcurlコマンドをコピーして実行。

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

Zshをデフォルトのターミナルに設定

下記2コマンドを実行。

brew install zsh
chsh -s /usr/local/bin/zsh

実行後に一度 exit してターミナルを再起動。

sadotchisadotchi

Zshテーマ Powerlevel10k をインストール

https://github.com/romkatv/powerlevel10k

Oh My Zshからインストールしたいので、https://github.com/romkatv/powerlevel10k?tab=readme-ov-file#oh-my-zsh の手順を参照。

まず下記コマンドを実行。

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

その後 vim~/.zshrc を開き、 ZSH_THEME の記載がある行の値を "powerlevel10k/powerlevel10k" に変更。

vim ~/.zshrc

値を変更したら下記を実行し ~/zshrc を再読み込み。

source ~/.zshrc

実行するとPowerlevel10kの初回設定ウィザードが立ち上がり、下記の流れで設定が進む。

  1. Meslo Nerd Fontのインストールをするか聞かれるので y を入力してインストール
  2. インストールが完了するとiTerm2を再起動するよう促されるので一度iTerm2を閉じて再起動
  3. 設定ウィザードの続きとしてインストールしたフォントの確認と見た目の設定が始まるので設問に回答していく
sadotchisadotchi

Zshプラグインを追加

zsh-autosuggestions

https://github.com/zsh-users/zsh-autosuggestions
コマンドをサジェストしてくれるようになるやつ。
↓Oh My Zshからのインストール方法
https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md#oh-my-zsh

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

↑を実行後、 ~/.zshrcplugins={}zsh-autosuggestions を追加。

~/.zshrc
plugins=( 
    # other plugins...
    zsh-autosuggestions
)

zsh-syntax-highlighting

https://github.com/zsh-users/zsh-syntax-highlighting
zshコマンドにシンタックスハイライトをつけてくれるやつ。
↓Oh My Zshからのインストール方法
https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/INSTALL.md#oh-my-zsh

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

↑を実行後、 ~/.zshrcplugins={}zsh-autosuggestions を追加。

~/.zshrc
plugins=( [plugins...] zsh-syntax-highlighting)