メインコンテンツへスキップ
見出し画像

M1 MacBook Air の環境構築(開発ツール編)

    休日のお昼をなだらかに過ごしているしょっさんです、こんにちわ。アプリ編に続き、3ヶ月も経過してからの開発ツール編です。

    しかも1月末に環境構築完了しているのに、今まで寝かしている程度にはどうにかしている日々です。まぁ、そんなこんなでせっかくの休日なので、M1 MacBook Air とニーチェアでお休み感を醸し出しているとこです。

    休日は何はともあれ、オフィスチェアを離れて、ニーチェアオススメです。オットマンもどうぞ。なお、ロッキングをオススメします。

    さて。M1 Mac での開発環境準備編です。

    CLI ツールのインストール

    何はともあれ、わたしに不可欠なのはこれ。

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

    めでたく Homebrew も 2月に入って M1 対応の v3.0 も提供され、安心してインストールできます。嬉しいことに、Command Line Tools for Xcode もインストールしてくれるので、まずはこれを実行しておけば良いです。

    ※ Heroku をインストールする場合

    なお、わいのように Heroku を駆使して生活している御仁たちは、'heroku' CLI とは切っても切れない関係です。その場合は、こちらでインストールします。

    brew tap heroku/brew && brew install heroku

    あとは必要なコマンドまるっとインストールです。わたしの必要なコマンドはほぼ全部 M1 対応しててなんとかなっちゃいましたね。

    brew install fish sfdx jq nodenv peco plantuml rbenv reattach-to-user-namespace tmux tree 

    実際にインストールされたパッケージは次の通り

    > brew list
    autoconf                        heroku-node                     pango
    cairo                           icu4c                           pcre
    cmake                           jasper                          pcre2
    fish                            jpeg                            peco
    fontconfig                      jq                              pixman
    freetype                        libevent                        pkg-config
    fribidi                         libffi                          plantuml
    gd                              libpng                          python@3.9
    gdbm                            librsvg                         rbenv
    gdk-pixbuf                      libtiff                         readline
    gettext                         libtool                         reattach-to-user-namespace
    gibo                            lzo                             ruby-build
    glib                            ncurses                         sphinx-doc
    go                              netpbm                          sqlite
    gobject-introspection           nkf                             tcl-tk
    graphite2                       node-build                      tmux
    graphviz                        nodenv                          tree
    gts                             oniguruma                       utf8proc
    harfbuzz                        openjdk                         webp
    heroku                          openssl@1.1                     xz
    sfdx

    fish + fisherman + tmux の設定

    iTerm2 だけでは飽き足らず、tmux がなければ生きていけない体になっています。tmux がないと、キーボードだけで過去を遡ることも、コピー&ペーストすることすらできないのです。

    tmux のプラグイン管理である tpm も使っているので、これでインストールしておきます。

    git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

    tmux と Macクリップボードを共有するための  'reattach-to-user-namespace' も必要です。これも既に brew でインストール済みなので設定だけしておきます。

    ~/.tmux-reattach-to-user-namespace.conf を設定しておきましょう。

    set-option -g default-command "exec reattach-to-user-namespace -l $SHELL"
    
    # unbind-key -T copy-mode-vi Enter
    bind-key -T copy-mode-vi Enter send -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
    
    unbind ]
    bind ] run-shell "reattach-to-user-namespace pbpaste | tmux load-buffer - && tmux paste-buffer"

    結果的にわいの ~/.tmux.conf はこんな感じです。

    viモードにしたり、reattach-to-user-namespace を使うようにしたり、prefix を C-] にしたり、tpm でプラグインを指定したり、その設定をしています。

    set-window-option -g mode-keys vi
    
    if-shell 'test "$(uname -s)" = Darwin && which reattach-to-user-namespace > /dev/null 2>&1' 'source-file ~/.tmux-reattach-to-user-namespace.conf'
    set-option -g prefix C-]
    unbind-key C-b
    bind-key C-] send-prefix
    
    bind-key | split-window -h
    
    # ウィンドウを閉じた時に番号を詰める
    set-option -g renumber-windows on
    
    # set -g mode-mouse on
    set -g mouse on
    
    # reload config
    bind C-r source-file ~/.tmux.conf \; display "~/.tmux.conf is reloaded"
    set -g @tpm_plugins '                \
     tmux-plugins/tpm                   \
     tmux-plugins/tmux-resurrect        \
     tmux-plugins/tmux-continuum        \
    '
    set -g @continuum-boot 'on'
    set -g @continuum-boot-options 'iterm'
    
    set -g @continuum-restore 'on'
    set -g @continuum-save-interval '1'
    
    run-shell '~/.tmux/plugins/tpm/tpm'

    tmux+tpmで参考にした記事はこちら

    fish + fisherman のインストール&設定

    次に fish ですね。fish は brew で既にインストール済みなので、デフォルト shell の設定をします。その後に fisherman をインストールしていきます。

    まずは fish の位置をチェックしておきます。

    which fish
    /opt/homebrew/bin/fish

    vi などで、/etc/shells に fish のパスを追加します。最終行に、先ほどチェックしたパスを追加します。

    # List of acceptable shells for chpass(1).
    # Ftpd will not allow users to connect who are not using
    # one of these shells.
    
    /bin/bash
    /bin/csh
    /bin/dash
    /bin/ksh
    /bin/sh
    /bin/tcsh
    /bin/zsh
    /opt/homebrew/bin/fish

    最後に、ログインシェルの変更です。iTerm を再起動すると、fish shell で起動してきます。

    chsh -s /usr/local/bin/fish

    次にfish のplugin manager である fisherman をインストールします。

    と、その前に。わたしの使っている fish テーマはPowerline用のフォントが必要です。この Cica フォントを使ってたりします。Powerline 用のフォントを入れておかないと、文字化けちゃいます。

    インストールコマンドはこちら

    curl https://git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish

    fisher がインストールできたら、おもむろにプラグインをインストールします

    fisher install oh-my-fish/theme-bobthefish
    fisher install jethrokuan/z
    fisher install oh-my-fish/plugin-peco

    一つ目がいわゆる shell テーマです。かわいいのでこれを使ってます。

    二つ目は 'z' 。簡単に過去のディレクトリを遡りやすくなって便利。

    最後が 'peco' を fish上で使いやすくするプラグイン。

    あとは、fish の設定ファイルをこねくり回して完了です。

    PATH に homebrew でインストールされる実行ファイルのパスを追記します。

    peco を Ctrl+R で実行されるように定義。先ほど fisherman でインストールした peco を制御する関数をコールしています。

    あとはテーマの個別設定と、nodenv / rbenv の定義のみです。

    # PATH
    set PATH "/opt/homebrew/bin:/usr/local/bin:$PATH"
    
    #peco
    function fish_user_key_bindings
       bind \cr peco_select_history
    end
    
    set -g theme_display_git_master_branch yes
    set -g fish_prompt_pwd_dir_length 0
    set -g theme_newline_cursor yes
    set -g theme_display_date no
    set -g theme_display_cmd_duration no
    
    # nodenv
    set PATH "$HOME/.nodenv/bin:$PATH"
    eval (nodenv init - | source)
    
    # rbenv
    status --is-interactive; and source (rbenv init -|psub)
    set -g fish_user_paths "/usr/local/sbin" $fish_user_paths

    多分、これで設定はすべてじゃないかな。最終的にこんな iTerm + fish 画面になります。

    画像1

    fish + fihserman の設定はこちらを参考にしました。



    この記事が参加している募集

     
     
    元IBMのSalesforceITアーキテクト。 ITアーキテクチャの深淵から、日々の何気ない生き様まで、思考の軌跡を「毎日」綴っています。 座右の銘は「人生即是遊戯」。 家族とPerfume、オーディオを愛する私の遊び場が、あなたの日常のちょっとした刺激になれば幸いです。

    あなたへのおすすめ