0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

はじめに
Macのデフォルトシェルは既にzshですが、そのままでは少し寂しかったのでこの記事では、zshをより使いやすく、見た目も美しくカスタマイズする方法を初心者向け記載します。もともとは自分用の記録に残そうと思っていたので見にくかったらネットにいろいろ落ちているので調べてみてください。

oh-my-zshを導入することで、以下のような恩恵が受けられます
・美しいテーマで見やすいターミナル
・便利なプラグインで作業効率アップ
・Gitの状態が一目で分かる
・コマンドの補完機能が充実

前提条件
macOS(Apple Silicon または Intel Mac)
ターミナルの基本操作ができる

  1. Homebrewのインストール
    Homebrewは、macOSで様々なソフトウェアを簡単にインストールできるパッケージマネージャーです。まずこれをインストールします。

1.1 Homebrewをインストール

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

1.2 PATHの設定(Apple Silicon Macの場合のみ)
インストール完了後、以下のようなメッセージが表示される場合があります:
==> Next steps:

  • Run these commands in your terminal to add Homebrew to your PATH:
    echo >> ~/.zprofile
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
    このメッセージが表示されたら、必ず表示されたコマンドをコピーして実行してください。

1.3 確認

bashbrew --version

バージョン番号が表示されればOKです!
2. oh-my-zshのインストール

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

インストール中に「Do you want to change your default shell to zsh?」と聞かれたら、Yを入力してEnter。

2.2 インストール完了の確認
ターミナルの見た目が変わっていればインストール成功です!デフォルトでは「robbyrussell」というテーマが適用されています。

  1. テーマのカスタマイズ
    oh-my-zshには多くのテーマが用意されています。お好みのテーマに変更してみましょう。
    3.1 人気のテーマ例
    bash# 設定ファイルを開く
nano ~/.zshrc

以下の行を探して、テーマ名を変更します:

bashZSH_THEME="robbyrussell"

おすすめのテーマ:
agnoster - 見やすくて情報量も多い
powerlevel10k - 高機能でカスタマイズ性が高い(別途インストール必要)
refined - シンプルで洗練されたデザイン
jonathan - ミニマルでクリーン

自分はwedisagreeを使っています。

3.2 設定を反映
bashsource ~/.zshrc

3.3 テーマ一覧を確認
bashls ~/.oh-my-zsh/themes/
気になるテーマがあれば試してみてください!

  1. 便利なプラグインの追加
    oh-my-zshの真価はプラグインにあります。作業効率を大幅に向上させる便利なプラグインを導入しましょう。

4.1 おすすめプラグインのインストール
zsh-autosuggestions(コマンド履歴からの自動提案)
bashgit clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
zsh-syntax-highlighting(コマンドの構文ハイライト)
bashgit clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

4.2 プラグインを有効化
bashnano ~/.zshrc

plugins=の行を探して、以下のように編集:
bashplugins=(
  git
  zsh-autosuggestions
  zsh-syntax-highlighting
  colored-man-pages
)

保存して反映:
bashsource ~/.zshrc

  1. Node.js環境のセットアップ
    開発に必須のNode.js環境を構築します。nodenvを使うと、複数のバージョンを簡単に管理できます。
    5.1 nodenvのインストール
    bashbrew install nodenv
    5.2 設定ファイルに追加
    bashecho 'eval "$(nodenv init -)"' >> ~/.zshrc
    source ~/.zshrc
    5.3 Node.jsをインストール
    bash# インストール可能なバージョンを確認
    nodenv install --list

LTS版をインストール(推奨)

nodenv install 20.11.0

デフォルトで使用するバージョンを設定

nodenv global 20.11.0

確認

node -v
npm -v

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?