ちょっと話題の記事

ぼくのMac環境 ver.のんピ

のんピのMacの設定の見れるってよ
2022.07.11

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

何年後かの自分へ

こんにちは、のんピ(@non____97)です。

業務で使用する新しいMacが届きました。

新しいMacを初期セットアップするにあたって「今の設定どうだったっけ...」と調べる時間が結構かかってしまいました

ということで何年後かの自分がまた新しいMacに乗り換える際に手間取らないように、設定した内容を書き記しておきます。

移行先のMacの情報は以下の通りです。M1 Max、嬉しい。

# OSのバージョンの確認
> sw_vers
ProductName:	macOS
ProductVersion:	12.4
BuildVersion:	21F79

# カーネルのバージョン確認
> uname -r
21.5.0

# CPUのアーキテクチャの確認
> uname -m
arm64

# CPUの詳細確認
> sysctl -a machdep.cpu
machdep.cpu.cores_per_package: 10
machdep.cpu.core_count: 10
machdep.cpu.logical_per_package: 10
machdep.cpu.thread_count: 10
machdep.cpu.brand_string: Apple M1 Max

OSのアップデート

まず、OSのアップデートです。

出荷状態から家に届くまでのアップデートがあればアップデートしておきます。

システム環境設定

一般

次にシステム環境設定を変更していきます。

まず、一般です。

私はダークモードが大好き & Chrome使いなので以下のように変更します。

  • 外観モードをライトからダークに変更
  • デフォルトのWebブラウザをSafariからGoogle Chromeに変更

システム環境設定 - 一般

Dockとメニューバー

次にDockとメニューバーです。

Dockはあまり主張しないのが好きなので以下のように変更します。

  • Dockのサイズをやや小さめに変更
  • 拡大にチェックを入れる
    • ポインタをアイコン上に移動したときにアイコンを拡大するようになる
  • 画面上の位置をに変更
    • 画面の右端に沿ってDockを配置する
  • フルスクリーンでメニューバーを自動的に表示/非表示のチェックを外す
    • アプリケーションをフルスクリーンで使用しているときもメニューバーを表示させる

システム環境設定 - Dockとメニューバー

メニューバーのみの時計の設定で以下のように設定します。

  • 日付を表示を常にに変更
  • 秒を表示にチェックを入れる

システム環境設定 - Dockとメニューバー - 時計

秒を表示しておくと、おおよそ何秒かかったのか確認する時に結構便利です。

Mission Control

Mission Controlです。

大量のウィンドウを開いている状態でMission Controlを使っても、整理が難しいのでアプリケーション毎にグループ化させます。

  • ウィンドウをアプリケーションごとにグループ化にチェックを入れる

システム環境設定_Mission Control

Bluetooth

次はBluetoothです。

設定と言っても、メニューバーにBluetoothを表示にチェックを入れるだけです。

システム環境設定_Bluetooth

メニューバーに表示されるようになりました。

Bluetootheメニューバー

macOS Montereyからサードパーティ製Bluetoothイヤホンやマウスのバッテリー情報が確認できるようになったので、外出する前などにバッテリーが十分かどうか確認するのが非常に楽になりました。

Touch ID

次にTouch IDです。

便利ですよね。Touch ID。

ということで、Touch IDの登録をしてあげます。

システム環境設定_Touch_ID

働く場所によってMacのポジションが変わるので、両手とも登録しておきます。

キーボード

次にキーボードです。

まず、ユーザー辞書の登録をします。メールアドレスを入力することが結構多いので、メールアドレスを辞書登録しておきます。

システム環境設定_キーボード_ユーザー辞書

入力ソースも変更します。

  • 入力モードで半角カタカナにチェックを入れる
    • 無性に半角カタカナを入力したくなることがある
  • Caps LockキーでABC入力モードと切り替えるにチェックを入れる
    • 日本語入力と英字入力の切り替えがCaps Lockキーだけでできるようにする

システム環境設定_キーボード_入力ソース

トラックパッド

次にトラックパッドです。

まず、ポインターの速さを最大にします。

システム環境設定_トラックパッド_ポイントとクリック

その他のジェスチャも変更します。以下のジェスチャを有効にします。

  • ページ間をスワイプ
    • 主にブラウザのページの行き来に使用
  • アプリケーションExpose
    • 特定アプリケーションのすべてのウィンドウの一覧を表示

システム環境設定_トラックパッド_その他のジェスチャ

マウス

次にマウスです。

以下の設定をします。

  • スクロールの方向: ナチュラルにチェックを外す
    • マウスホイールを下にスクロールした時にウィンドウを下にスクロールさせる
  • 軌跡の速さを最大にする
    • 速いのが好きです

システム環境設定_マウス

ディスプレイ

次にディスプレイです。

まず、外付けディスプレイを主ディスプレイになるように変更します。

システム環境設定_ディスプレイ

Macのディスプレイの解像度を1800 × 1169に変更します。

システム環境設定_ディスプレイ_拡張ディスプレイ

外付けディスプレイの解像度も同様に3840 × 2160に変更します。

システム環境設定_ディスプレイ_主ディスプレイ

Google Chrome

次にGoogle Chromeの設定です。

設定と言っても、同じプロファイルでログインすれば今までと同じ拡張機能が使えるので、移行は大変ではありません。

なお、拡張機能の設定が同期されるかは拡張機能毎に異なるようです。私は以下拡張機能の設定を設定しなおしました。

  • FoxyProxy

  • uBlacklist

  • Stylus

StylusではAWSマネージメントコンソールのお気に入りバーのアイコンサイズを大きくするために以下のスタイルを使っています。

@-moz-document domain("console.aws.amazon.com"), domain("phd.aws.amazon.com") {
  #awsc-nav-header > nav > nav > div:nth-child(2) > div > ol > li > a {padding: 2px 4px; margin: 0px;}

  #awsc-nav-header > nav > nav > div:nth-child(2) > div > ol > li > a > div{ width: auto; height: 28px;}
  #awsc-nav-header > nav > nav > div:nth-child(2) > div > ol > li > a > div > img{ width: inherit; height: inherit;}
}

Finder

Finderの使い勝手も重要なので各種設定変更をします。

まず、Finderのメニューバーの表示から以下を設定をします。

  • タブバーを表示をクリック
    • マウス操作で簡単に新規タブ追加ができるようになる
  • パスバーを表示をクリック
    • ディレクトリやファイルパスのコピーが簡単にできるようになる
  • ステータスバーを表示をクリック
    • ディレクトリ内のサブディレクトリやファイル数や空き容量の確認に便利

Finder_view〜を表示をクリックすると〜を非表示と表示されるようになります。

パスバーとステータスバーは私にとってなくてはならない存在です。

Finder

次にFinderの表示項目を変更します。

ホームディレクトリで設定した表示オプションをホームディレクトリ配下全てに反映させるために、ホームディレクトリ配下の.DS_Storeを一旦全て削除します。

# ホームディレクトリ配下の`.DS_Store`を一旦全て削除
# 権限不足で削除できないものは無視
> sudo find ~/ -name ".DS_Store" -delete
find: /<ホームディレクトリ>//Library/Application Support/CallHistoryTransactions: Operation not permitted
find: /<ホームディレクトリ>//Library/Application Support/com.apple.sharedfilelist: Operation not permitted
find: /<ホームディレクトリ>//Library/Application Support/Knowledge: Operation not permitted
find: /<ホームディレクトリ>//Library/Application Support/com.apple.TCC: Operation not permitted
find: /<ホームディレクトリ>//Library/Application Support/FileProvider: Operation not permitted
find: /<ホームディレクトリ>//Library/Application Support/com.apple.avfoundation/Frecents: Operation not permitted
find: /<ホームディレクトリ>//Library/Application Support/CallHistoryDB: Operation not permitted
find: /<ホームディレクトリ>//Library/Assistant/SiriVocabulary: Operation not permitted
find: /<ホームディレクトリ>//Library/Autosave Information: Operation not permitted
find: /<ホームディレクトリ>//Library/IdentityServices: Operation not permitted
^C⏎

# Finderのプロセスを削除
> Killall Finder

Finderを新規に起動して、Finderのメニューバーの表示から表示オプションを表示をクリックし、以下設定を行います。

  • 表示する項目で以下項目のチェックを入れる
    • 作成日
    • 最後に開いた日
    • 全てのサイズを計算
  • 表示する項目で以下項目のチェックを外す
    • 相対日時 (昨日/今日) を使用
  • デフォルトとして使用をクリックする

Finder表示オプション

私好みのFinderになってきました。

Finder表示オプション変更後

次は隠しディレクトリや隠しファイルの表示です。

デフォルトでは隠しディレクトリや隠しファイルは表示されません。

隠しディレクトリや隠しファイルを表示するために、Finderのウィンドウを選択した状態でCommand + Shift + .を押下します。すると、隠しディレクトリや隠しファイルが表示されるようになります。

Finder_hidden_file

次にFinderの環境設定の詳細から以下設定を行います。

  • 全てのファイル名拡張子を表示にチェックを入れる
  • 検索実行時 : 現在のフォルダ内を検索に変更

Finder環境設定_詳細

最後にサイドバーのよく使う項目にホームディレクトリや頻繁にアクセスするディレクトリを追加しておきます。

よく使う項目

Homebrew

macOSのパッケージマネージャーとしてHomebrewをインストールします。

% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
==> Checking for `sudo` access (which may request your password)...
Password:
==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
.
.
(中略)
.
.
remote: Total 1223274 (delta 193), reused 286 (delta 159), pack-reused 1222945
Receiving objects: 100% (1223274/1223274), 487.37 MiB | 13.58 MiB/s, done.
Resolving deltas: 100% (844343/844343), done.
From https://github.com/Homebrew/homebrew-core
 * [new branch]              master     -> origin/master
HEAD is now at a036681a810 k6: update 0.39.0 bottle.
Warning: /opt/homebrew/bin is not in your PATH.
  Instructions on how to configure your shell for Homebrew
  can be found in the 'Next steps' section below.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations

==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /<ホームディレクトリ>/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

インストールが完了したらパスを通します。

# zshのプロファイルにパスを通す
% echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /<ホームディレクトリ>/.zprofile

# 現在のセッションにHomebrewのパスを認識させる
% eval "$(/opt/homebrew/bin/brew shellenv)"

# Homebrewのバージョン確認
% brew -v                                                                            
Homebrew 3.5.3
Homebrew/homebrew-core (git revision a036681a810; last commit 2022-07-05)

バージョンも確認できましたね。

iTerm2

インストール

次にiTerm2をインストールします。

Homebrewでインストールします。

% brew install --cask iterm2
==> Tapping homebrew/cask
Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-cask'...
remote: Enumerating objects: 653154, done.
remote: Counting objects: 100% (180/180), done.
remote: Compressing objects: 100% (102/102), done.
remote: Total 653154 (delta 96), reused 149 (delta 78), pack-reused 652974
Receiving objects: 100% (653154/653154), 308.18 MiB | 14.10 MiB/s, done.
Resolving deltas: 100% (462744/462744), done.
Tapped 4028 casks (4,100 files, 329MB).
==> Downloading https://iterm2.com/downloads/stable/iTerm2-3_4_16.zip
######################################################################## 100.0%
==> Installing Cask iterm2
==> Moving App 'iTerm.app' to '/Applications/iTerm.app'
?  iterm2 was successfully installed!

ウィンドウサイズ

iTerm2の初期ウィンドウサイズを変更します。

Preferences-Profiles-Windowで以下設定をします。

  • Columns: 80から120に変更
  • Columns: 25から30に変更

iTem2_Preferences_Window

無限スクロール

iTerm2が無限にスクロールできるようにします。

Preferences-Profiles-TerminalUnlimited scrollbackにチェックを入れます。

iTem2_Preferences_Terminal

ログ出力

セッションを間違えて閉じてしまっても後追いできるようにログの出力設定もしておきます。

Preferences-Profiles-SessionAutomatically log session input to files in:にチェックを入れて、任意のディレクトリを指定します。また、ログをプレーンテキストで出力するためにLog plain textにもチェックを入れておきます。

iTem2_Preferences_Session

Hotkey

iTerm2のウィンドウを簡単に開くためにHotkeyの設定をします。

Preferences-Keys-HotkeyCreate a Dedicated Hotkey Windowをクリックします。

iTem2_Preferences_Keys

Ctrlを2回押した時にウィンドウを開くように以下の設定をします。

  • Double-tap keyにチェックを入れる
  • ^Controlを選択
  • Pin hotkey window (stays open on loss of keyboad focus)にチェックを入れる
    • Hotkeyで開いたウィンドウからフォーカスが外れた際もウィンドウを開いたままにする

iTem2_Preferences_Hotkey

Hotkey WindowというHotkeyで開いたウィンドウ用のプロファイルが作成されます。以下のように設定変更します。

  • Columns: 25から30に変更
  • Style: Full-Width Top of ScreenからNormalに変更
    • Hotkeyで開いたウィンドウを自由に動かせるようにする

iTem2_Preferences_Hotkey_Window

Ctrlを2回押した時にiTem2の半透明なウィンドウが開くようになりました。

iTem2_Hotkey_Window

閉じる場合もCtrlを2回です。

fish

インストール

次にみんな大好きfishです。

以下記事を参考に設定します。

何はともあれ、まずはfishのインストールです。

% brew install fish
==> Downloading https://ghcr.io/v2/homebrew/core/ncurses/manifests/6.3
######################################################################## 100.0%
.
.
(中略)
.
.
==> Installing fish
==> Pouring fish--3.5.0.arm64_monterey.bottle.tar.gz
?  /opt/homebrew/Cellar/fish/3.5.0: 1,418 files, 15.1MB
==> Running `brew cleanup fish`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

インストールが完了したらデフォルトのシェルをfishに変更します。

# ログインシェルとして有効なシェルの一覧を確認
% cat /etc/shells
# 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

# fishのパスを確認
% which fish
/opt/homebrew/bin/fish

# ログインシェルとして有効なシェルにfishを追加
% sudo vi /etc/shells
Password:

# ログインシェルとして有効なシェルにfishが追加されたことを確認
% cat /etc/shells
# 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

# ログインシェルをfishに変更
% chsh -s /opt/homebrew/bin/fish
Changing shell for <ユーザー名>.
Password for <ユーザー名>:

iTerm2を再起動して以下のようなメッセージが表示されることを確認します。

Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish

色の変更

次に色を変更します。

今まで使っていたMacのfishからfishの色設定を確認して、新しいMacで同じ設定をします。

% set fish_color_autosuggestion   707A8C
% set fish_color_cancel           normal
% set fish_color_command          5CCFE6
% set fish_color_comment          5C6773
% set fish_color_cwd              73D0FF
% set fish_color_cwd_root         800000
% set fish_color_end              F29E74
% set fish_color_error            FF3333
% set fish_color_escape           95E6CB
% set fish_color_history_current  normal
% set fish_color_host             normal
% set fish_color_host_remote      yellow
% set fish_color_match            F28779
% set fish_color_normal           CBCCC6
% set fish_color_operator         FFCC66
% set fish_color_param            CBCCC6
% set fish_color_quote            BAE67E
% set fish_color_redirection      D4BFFF
% set fish_color_search_match     FFCC66
% set fish_color_selection        FFCC66
% set fish_color_status           red
% set fish_color_user             00ff00
% set fish_color_valid_path       normal

プロンプトの変更

次に、プロンプトの変更です。

fishではターミナル上でfish_configを叩くと、ブラウザでターミナルの設定ができます。

私はInformativeを選択しました。

fish_shell_configuration

時刻表示と現在のディレクトリをプロンプトに表示すると横長になってしまいますが、Informativeはプロンプトが2行なので大変ありがたいです。

プロンプトにGitのBranchとStatusを表示

Gitを使用しているとプロンプトに現在のBranchがどこかや、どんなStatusなのかが気になりますよね。

ということで、fishのプロファイルや関数の設定を変更します。

# 現在のfishのプロファイルを確認
> cat ~/.config/fish/config.fish
# AWS
export AWS_DEFAULT_PROFILE=cm-non-97
export AWS_DEFAULT_REGION=us-east-1
export CDK_DEFAULT_REGION=us-east-1
export CDK_DEFAULT_ACCOUNT=<AWSアカウントID>

# LSCOLORS
export LSCOLORS=gxfxcxdxbxegedabagacad

# fzf
set -U FZF_LEGACY_KEYBINDINGS 0
set -U FZF_REVERSE_ISEARCH_OPTS "--reverse --height=100%"

# ALIAS
alias tree='tree -a -I "\.DS_Store|\.git|node_modules|cdk.out|venv|package|vendor\/bundle" -N'

if status is-interactive
    # Commands to run in interactive sessions can go here
    # brew
    eval (/opt/homebrew/bin/brew shellenv)

    # anyenv
    source (anyenv init -|psub)
end

### MANAGED BY RANCHER DESKTOP START (DO NOT EDIT)
set --export --prepend PATH "/Users/yamamoto.ryota/.rd/bin"
### MANAGED BY RANCHER DESKTOP END (DO NOT EDIT)

# fishの環境変数を設定
> vi ~/.config/fish/config.fish

# 変更後のfishのプロファイルを確認
> cat ~/.config/fish/config.fish
# AWS
export AWS_DEFAULT_PROFILE=cm-non-97
export AWS_DEFAULT_REGION=us-east-1
export CDK_DEFAULT_REGION=us-east-1
export CDK_DEFAULT_ACCOUNT=<AWSアカウントID>

# LSCOLORS
export LSCOLORS=gxfxcxdxbxegedabagacad

# fzf
set -U FZF_LEGACY_KEYBINDINGS 0
set -U FZF_REVERSE_ISEARCH_OPTS "--reverse --height=100%"

# Fish git prompt
set __fish_git_prompt_showdirtystate 'yes'
set __fish_git_prompt_showstashstate 'yes'
set __fish_git_prompt_showuntrackedfiles 'yes'
set __fish_git_prompt_showupstream 'yes'
set __fish_git_prompt_color_branch yellow
set __fish_git_prompt_color_upstream_ahead green
set __fish_git_prompt_color_upstream_behind red

# Status Chars
set __fish_git_prompt_char_dirtystate '⚡'
set __fish_git_prompt_char_stagedstate '→'
set __fish_git_prompt_char_untrackedfiles '☡'
set __fish_git_prompt_char_stashstate '↩'
set __fish_git_prompt_char_upstream_ahead '+'
set __fish_git_prompt_char_upstream_behind '-'

# ALIAS
alias tree='tree -a -I "\.DS_Store|\.git|node_modules|cdk.out|venv|package|vendor\/bundle" -N'

if status is-interactive
    # Commands to run in interactive sessions can go here
    # brew
    eval (/opt/homebrew/bin/brew shellenv)

    # anyenv
    source (anyenv init -|psub)
end

### MANAGED BY RANCHER DESKTOP START (DO NOT EDIT)
set --export --prepend PATH "/Users/yamamoto.ryota/.rd/bin"
### MANAGED BY RANCHER DESKTOP END (DO NOT EDIT)

# fishのプロンプトを整形している関数を確認
> cat ~/.config/fish/functions/fish_prompt.fish
function fish_prompt --description 'Informative prompt'
    #Save the return status of the previous command
    set -l last_pipestatus $pipestatus
    set -lx __fish_last_status $status # Export for __fish_print_pipestatus.

    if functions -q fish_is_root_user; and fish_is_root_user
        printf '%s@%s %s%s%s# ' $USER (prompt_hostname) (set -q fish_color_cwd_root
                                                         and set_color $fish_color_cwd_root
                                                         or set_color $fish_color_cwd) \
            (prompt_pwd) (set_color normal)
    else
        set -l status_color (set_color $fish_color_status)
        set -l statusb_color (set_color --bold $fish_color_status)
        set -l pipestatus_string (__fish_print_pipestatus "[" "]" "|" "$status_color" "$statusb_color" $last_pipestatus)

        printf '[%s] %s%s@%s %s%s %s%s%s \n> ' (date "+%H:%M:%S") (set_color brblue) \
            $USER (prompt_hostname) (set_color $fish_color_cwd) $PWD $pipestatus_string \
            (set_color normal)
    end
end

# GitのBranchとStatusを表示するよう変更
> vi ~/.config/fish/functions/fish_prompt.fish

# 変更内容を確認
>  cat ~/.config/fish/functions/fish_prompt.fish
function fish_prompt --description 'Informative prompt'
    #Save the return status of the previous command
    set -l last_pipestatus $pipestatus
    set -lx __fish_last_status $status # Export for __fish_print_pipestatus.

    if functions -q fish_is_root_user; and fish_is_root_user
        printf '%s@%s %s%s%s# ' $USER (prompt_hostname) (set -q fish_color_cwd_root
                                                         and set_color $fish_color_cwd_root
                                                         or set_color $fish_color_cwd) \
            (prompt_pwd) (set_color normal)
    else
        set -l status_color (set_color $fish_color_status)
        set -l statusb_color (set_color --bold $fish_color_status)
        set -l pipestatus_string (__fish_print_pipestatus "[" "]" "|" "$status_color" "$statusb_color" $last_pipestatus)

        printf '[%s] %s%s@%s %s%s %s%s%s \n> ' (date "+%H:%M:%S") (set_color brblue) \
            $USER (prompt_hostname) (set_color $fish_color_cwd) $PWD $pipestatus_string \
            (set_color normal)
    end

    # Git
    set last_status $status
    printf '%s ' (__fish_git_prompt)
    set_color normal
end

# fishのプロファイルの読み込み
> source ~/.config/fish/config.fish

Homebrewのパスを通す

fishがHomebrewを認識できるようにパスを通してあげます。

# fishのプロファイルを編集してHomebrewのパスを通す
> vi ~/.config/fish/config.fish

# ログイン時にHomebrewのパスを通すように設定されたことを確認
> cat ~/.config/fish/config.fish
if status is-interactive
    # Commands to run in interactive sessions can go here
    eval (/opt/homebrew/bin/brew shellenv)
end

# 現在のセッションにHomebrewのパスを認識させる
> eval $(/opt/homebrew/bin/brew shellenv)

# Homebrewのバージョン確認
> brew -v
Homebrew 3.5.3
Homebrew/homebrew-core (git revision a036681a810; last commit 2022-07-05)
Homebrew/homebrew-cask (git revision 3dcdab047f; last commit 2022-07-05)

fisher

fishのためのプラグインマネージャであるjorgebucaran/fisherをインストールします。

# fisherのインストール
> curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher
fisher install version 4.4.2
Fetching https://api.github.com/repos/jorgebucaran/fisher/tarball/HEAD
Installing jorgebucaran/fisher
           /<ホームディレクトリ>/.config/fish/functions/fisher.fish
           /<ホームディレクトリ>/.config/fish/completions/fisher.fish
Installed 1 plugin/s

# fisherのバージョン確認
> fisher -v
fisher, version 4.4.2

z

移動したことがあるディレクトリに簡単に移動できるjethrokuan/zをfisherでインストールします。

> fisher install jethrokuan/z
fisher install version 4.4.2
Fetching https://api.github.com/repos/jethrokuan/z/tarball/HEAD
Installing jethrokuan/z
           /<ホームディレクトリ>/.config/fish/functions/__z.fish
           /<ホームディレクトリ>/.config/fish/functions/__z_add.fish
           /<ホームディレクトリ>/.config/fish/functions/__z_clean.fish
           /<ホームディレクトリ>/.config/fish/functions/__z_complete.fish
           /<ホームディレクトリ>/.config/fish/conf.d/z.fish
Installed 1 plugin/s

zと入力してTabキーを押下すると、移動したことがあるディレクトリを選択することができます。

z

fish-bd

カレントディレクトリから任意の親ディレクトリに簡単に移動できるfish-bdをfisherでインストールします。

> fisher install 0rax/fish-bd
fisher install version 4.4.2
Fetching https://api.github.com/repos/0rax/fish-bd/tarball/HEAD
Installing 0rax/fish-bd
           /<ホームディレクトリ>/.config/fish/functions/bd.fish
           /<ホームディレクトリ>/.config/fish/completions/bd.fish
Installed 1 plugin/s

bdと入力してTabキーを押下すると、任意の親ディレクトリを選択することができます。

fish-bd

fzf

コマンドラインファジーファインダーであるfzfをインストールします。

# fzfのインストール
> brew install fzf
.
.
(中略)
.
.
==> Summary
?  /opt/homebrew/Cellar/fzf/0.30.0: 17 files, 2.6MB
==> Running `brew cleanup fzf`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

# fishでfzfを使えるようにfishermanでfzfをインストール
> fisher install fisherman/fzf
fisher install version 4.4.2
Fetching https://api.github.com/repos/fisherman/fzf/tarball/HEAD
Installing fisherman/fzf
           /<ホームディレクトリ>/.config/fish/functions/__fzf_cd.fish
           /<ホームディレクトリ>/.config/fish/functions/__fzf_complete.fish
           /<ホームディレクトリ>/.config/fish/functions/__fzf_complete_preview.fish
           /<ホームディレクトリ>/.config/fish/functions/__fzf_find_file.fish
           /<ホームディレクトリ>/.config/fish/functions/__fzf_get_dir.fish
           /<ホームディレクトリ>/.config/fish/functions/__fzf_open.fish
           /<ホームディレクトリ>/.config/fish/functions/__fzf_parse_commandline.fish
           /<ホームディレクトリ>/.config/fish/functions/__fzf_reverse_isearch.fish
           /<ホームディレクトリ>/.config/fish/functions/__fzfcmd.fish
           /<ホームディレクトリ>/.config/fish/conf.d/fzf.fish
Installed 1 plugin/s

インストール後、環境変数でキーバインドと検索候補の表示設定を変更します。

# 現在のfishのプロファイルを確認
> cat ~/.config/fish/config.fish
if status is-interactive
    # Commands to run in interactive sessions can go here
    # brew
    eval (/opt/homebrew/bin/brew shellenv)
end

# 環境変数の変更
> vi ~/.config/fish/config.fish

# 環境変数が変更されたことを確認
> cat ~/.config/fish/config.fish
# fzf
set -U FZF_LEGACY_KEYBINDINGS 0
set -U FZF_REVERSE_ISEARCH_OPTS "--reverse --height=100%"

if status is-interactive
    # Commands to run in interactive sessions can go here
    # brew
    eval (/opt/homebrew/bin/brew shellenv)
end

fisherと入力してCtrl + rを押下すると、今までのコマンド履歴からfisherという文字列が含まれるコマンドが表示されました。

fzf_commands

index.tsと入力してCtrl + oを押下すると、カレントディレクトリ配下のindex.tsindex.d.tsの一覧が表示されました。

fzf_files

LSCOLORS

lsコマンドを叩いた際、デフォルトではディレクトリの色が青であり、iTerm2の背景色との関係で視認性が低いです。

ls_default_color

そのため、lsコマンドの色の設定を環境変数LSCOLORSで変更します。

# ディレクトリの色をシアンに変更
> vi ~/.config/fish/config.fish

# 変更後のfishのプロファイルを確認
> cat ~/.config/fish/config.fish
# LSCOLORS
export LSCOLORS=gxfxcxdxbxegedabagacad

# fzf
set -U FZF_LEGACY_KEYBINDINGS 0
set -U FZF_REVERSE_ISEARCH_OPTS "--reverse --height=100%"

if status is-interactive
    # Commands to run in interactive sessions can go here
    # brew
    eval (/opt/homebrew/bin/brew shellenv)
end

# fishのプロファイルの読み込み
> source ~/.config/fish/config.fish

fishのプロファイルの読み込み後、lsコマンドを叩くと以下のようにディレクトリの色がシアンに変わりました。

ls_cyaan_color

sudo時にTouch IDを使えるように変更

sudo時にTouch IDを使えるように変更します。

以下記事を参考にしながら設定変更をします。

# PAM設定ファイルの内容をを確認
> cat /etc/pam.d/sudo
# sudo: auth account password session
auth       sufficient     pam_smartcard.so
auth       required       pam_opendirectory.so
account    required       pam_permit.so
password   required       pam_deny.so
session    required       pam_permit.so

# PAM設定ファイルの権限を確認
> ls -l /etc/pam.d/sudo
-r--r--r--  1 root  wheel  246  5 10 06:30 /etc/pam.d/sudo

# PAM設定ファイルにrootユーザーが書き込めるように変更
> sudo chmod 644 /etc/pam.d/sudo
Password:

# PAM設定ファイルにrootユーザーが書き込めるように変更されたことを確認
> ls -l /etc/pam.d/sudo
-rw-r--r--  1 root  wheel  246  5 10 06:30 /etc/pam.d/sudo

# PAM設定ファイルを編集して、Touch IDによる認証を利用するためのPAMモジュール (pam_tid.so) を追加し、Touch IDによる認証を許可する
> sudo vi /etc/pam.d/sudo

# 変更内容を確認する
> cat /etc/pam.d/sudo
# sudo: auth account password session
auth       sufficient     pam_tid.so
auth       sufficient     pam_smartcard.so
auth       required       pam_opendirectory.so
account    required       pam_permit.so
password   required       pam_deny.so
session    required       pam_permit.so

# PAM設定ファイルの権限を元に戻す
> sudo chmod 444 /etc/pam.d/sudo

# PAM設定ファイルの権限が元に戻ったことを確認する。
> ls -l /etc/pam.d/sudo
-r--r--r--@ 1 root  wheel  283  7  6 10:42 /etc/pam.d/sudo

設定変更後にターミナルを再起動して、sudo lsを叩くと以下のようにtouchIDによる認証を求められました。

sudo-touchID

Visual Studio Code

インストール

Vitual Studio Codeもなくてはならないのでインストールします。

> brew install --cask visual-studio-code
Running `brew update --auto-update`...
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
cargo-bundle                        mle                                 mypaint-brushes                     pax                                 uthash
==> New Casks
gamma-control

==> Downloading https://update.code.visualstudio.com/1.68.1/darwin-arm64/stable
==> Downloading from https://az764295.vo.msecnd.net/stable/30d9c6cd9483b2cc586687151bcbcd635f373630/VSCode-darwin-arm64.zip
######################################################################## 100.0%
==> Installing Cask visual-studio-code
==> Moving App 'Visual Studio Code.app' to '/Applications/Visual Studio Code.app'
==> Linking Binary 'code' to '/opt/homebrew/bin/code'
?  visual-studio-code was successfully installed!

設定の同期

インストール後、GitHubアカウントでサインインして設定を同期します。

設定の同期

GitHubでサインイン

GitHubアカウントの認証情報を入力してSigh inをクリックします。

GitHubの認証

サインインすると、同期された設定をマージするか確認されるのでマージをクリックします。

設定のマージ

拡張機能一覧を出力すると、確かに今まで使っていた拡張機能が表示されました。

> code --list-extensions
4ops.terraform
amazonwebservices.aws-toolkit-vscode
aws-amplify.aws-amplify-vscode
aws-scripting-guy.cform
christian-kohler.npm-intellisense
christian-kohler.path-intellisense
codezombiech.gitignore
csholmq.excel-to-markdown-table
DavidAnson.vscode-markdownlint
dbaeumer.vscode-eslint
dgenzer.suricata-highlight-vscode
donjayamanne.githistory
DotJoshJohnson.xml
eamodio.gitlens
ecmel.vscode-html-css
eg2.vscode-npm-script
emilast.LogFileHighlighter
esbenp.prettier-vscode
formulahendry.auto-close-tag
formulahendry.auto-rename-tag
gamunu.vscode-yarn
GitHub.copilot-labs
GitHub.github-vscode-theme
GitHub.vscode-pull-request-github
hashicorp.terraform
humao.rest-client
HyunKyunMoon.gzipdecompressor
IBM.output-colorizer
jsynowiec.vscode-insertdatestring
kddejong.vscode-cfn-lint
mechatroner.rainbow-csv
mhutchie.git-graph
mosapride.zenkaku
ms-azuretools.vscode-docker
MS-CEINTL.vscode-language-pack-ja
ms-kubernetes-tools.vscode-kubernetes-tools
ms-python.python
ms-python.vscode-pylance
ms-toolsai.jupyter
ms-toolsai.jupyter-keymap
ms-toolsai.jupyter-renderers
ms-vscode-remote.remote-containers
ms-vscode-remote.remote-ssh
ms-vscode-remote.remote-ssh-edit
ms-vscode.js-debug-nightly
ms-vscode.powershell
ms-vscode.wordcount
ms-vsliveshare.vsliveshare
nidu.copy-json-path
oderwat.indent-rainbow
oouo-diogo-perdigao.docthis
Orta.vscode-jest
paulshestakov.aws-step-functions-constructor
redhat.vscode-commons
redhat.vscode-xml
redhat.vscode-yaml
ritwickdey.LiveServer
shd101wyy.markdown-preview-enhanced
streetsidesoftware.code-spell-checker
thekalinga.bootstrap4-vscode
tintinweb.graphviz-interactive-preview
tomoki1207.vscode-input-sequence
usernamehw.errorlens
VisualStudioExptTeam.vscodeintellicode
wix.vscode-import-cost
wmaurer.change-case
yzhang.markdown-all-in-one

設定も同期されていました。

{
  "workbench.colorTheme": "GitHub Dark",
  "editor.formatOnSave": true,
  "editor.linkedEditing": true,
  "": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "terminal.integrated.profiles.osx": {
    "fish": {
      "path": "/opt/homebrew/bin/fish",
      "args": [
        "-l"
      ]
    },
  },
  "terminal.external.osxExec": "iTerm.app",
  "": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "editor.wordSeparators": "`~!@#$%^&*()-=+[{]}\\\\|;:'\\\",.<>/?、。 ",
  "": {
    "editor.defaultFormatter": "vscode.json-language-features"
  },
  "workbench.startupEditor": "newUntitledFile",
  "git.autofetch": true,
  "git.suggestSmartCommit": false,
  "": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "aws.profile": "profile:default",
  "editor.tabSize": 2,
  "[markdown]": {
    "files.trimTrailingWhitespace": false,
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "editor.renderWhitespace": "boundary",
  "markdown-preview-enhanced.previewTheme": "github-light.css",
  "": {
    "editor.defaultFormatter": "DotJoshJohnson.xml"
  },
  "workbench.editorAssociations": {
    "*.ipynb": "jupyter-notebook",
    "*": "default"
  },
  "markdown.extension.toc.levels": "1..4",
  "notebook.cellToolbarLocation": {
    "default": "right",
    "jupyter-notebook": "left"
  },
  "python.formatting.provider": "black",
  "python.formatting.blackPath": "/<ホームディレクトリ>/.anyenv/envs/pyenv/shims/black",
  "yaml.schemas": {},
  "yaml.customTags": [
    "!And",
    "!And sequence",
    "!If",
    "!If sequence",
    "!Not",
    "!Not sequence",
    "!Equals",
    "!Equals sequence",
    "!Or",
    "!Or sequence",
    "!FindInMap",
    "!FindInMap sequence",
    "!Base64",
    "!Join",
    "!Join sequence",
    "!Cidr",
    "!Ref",
    "!Sub",
    "!Sub sequence",
    "!GetAtt",
    "!GetAZs",
    "!ImportValue",
    "!ImportValue sequence",
    "!Select",
    "!Select sequence",
    "!Split",
    "!Split sequence"
  ],
  "indentRainbow.includedLanguages": [],
  "yaml.validate": false,
  "terminal.integrated.defaultProfile.osx": "fish",
  "json.schemas": [],
  "[asl]": {
    "editor.defaultFormatter": "amazonwebservices.aws-toolkit-vscode"
  },
  "editor.bracketPairColorization.enabled": true,
  "editor.guides.bracketPairs": "active",
  "diffEditor.ignoreTrimWhitespace": false,
  "": {
    "editor.defaultFormatter": "redhat.vscode-yaml"
  },
  "jest.debugCodeLens.showWhenTestStateIn": ["fail", "unknown"],
  "cSpell.ignoreWords": ["ONTAP", "CIFS", "SNMP", "classmethod", "elbv2"],
  "editor.suggest.showMethods": true,
  "editor.suggest.preview": true,
  "editor.acceptSuggestionOnEnter": "on",
}

anyenv

Node.jsを使いたいので、anyenvnodenvをインストールします。

まずHomebrewでanyenvをインストールします。

> brew install anyenv
==> Downloading https://ghcr.io/v2/homebrew/core/anyenv/manifests/1.1.4
Already downloaded: /<ホームディレクトリ>/Library/Caches/Homebrew/downloads/1904bfa0232ea0b81d0a21abf4752fccaa5026081a6adff68e49e38e5758f085--anyenv-1.1.4.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/anyenv/blobs/sha256:64a65deada2b73eea41aaf1072d015c193e46cc38d524e3770d8e319b56b54fe
Already downloaded: /<ホームディレクトリ>/Library/Caches/Homebrew/downloads/af88d03b5969c7090a31e56ffe453da19277994477e399e8b66591d236879997--anyenv--1.1.4.arm64_monterey.bottle.tar.gz
==> Pouring anyenv--1.1.4.arm64_monterey.bottle.tar.gz
?  /opt/homebrew/Cellar/anyenv/1.1.4: 23 files, 31.2KB
==> Running `brew cleanup anyenv`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

anyenvインストール後、fishでanyenvのセットアップをします。

# セットアップするためのコマンドを確認
> anyenv init
# Load anyenv automatically by adding
# the following to ~/.config/fish/config.fish:

status --is-interactive; and source (anyenv init -|psub)

# 表示されたコマンドを ~/.config/fish/config.fish に追加
> vi ~/.config/fish/config.fish

# ~/.config/fish/config.fish に追加されたことを確認
> cat ~/.config/fish/config.fish
# LSCOLORS
export LSCOLORS=gxfxcxdxbxegedabagacad

# fzf
set -U FZF_LEGACY_KEYBINDINGS 0
set -U FZF_REVERSE_ISEARCH_OPTS "--reverse --height=100%"

if status is-interactive
    # Commands to run in interactive sessions can go here
    # brew
    eval (/opt/homebrew/bin/brew shellenv)

    # anyenv
    source (anyenv init -|psub)
end

# anyenvの初期化
> anyenv install --init
Manifest directory doesn't exist: /<ホームディレクトリ>/.config/anyenv/anyenv-install
Do you want to checkout https://github.com/anyenv/anyenv-install.git? [y/N]: y
Cloning https://github.com/anyenv/anyenv-install.git master to /<ホームディレクトリ>/.config/anyenv/anyenv-install...
Cloning into '/<ホームディレクトリ>/.config/anyenv/anyenv-install'...
remote: Enumerating objects: 71, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 71 (delta 4), reused 3 (delta 1), pack-reused 57
Receiving objects: 100% (71/71), 13.15 KiB | 4.38 MiB/s, done.
Resolving deltas: 100% (11/11), done.

Completed!

anyenvの初期化が完了したらnodenvをインストールします。

# nodenvがあることを確認
> anyenv install --list
  Renv
  crenv
  denv
  erlenv
  exenv
  goenv
  hsenv
  jenv
  jlenv
  kubectlenv
  luaenv
  nodenv
  phpenv
  plenv
  pyenv
  rbenv
  sbtenv
  scalaenv
  swiftenv
  tfenv

# nodenvをインストール
> anyenv install nodenv
/var/folders/tm/fwpf46g56_d3fc4kk45sx__40000gp/T/nodenv.20220706091646.14211 ~
Cloning https://github.com/nodenv/nodenv.git master to nodenv...
Cloning into 'nodenv'...
.
.
(中略)
.
.
Install nodenv succeeded!
Please reload your profile (exec $SHELL -l) or open a new session.

# シェルの再読み込み
> exec $SHELL -l
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish

# nodenvでインストールできるNode.jsのバージョンを確認
> nodenv install -l
0.1.14
0.1.15
0.1.16
0.1.17
0.1.18
.
.
(中略)
.
.
iojs-3.1.0
iojs-3.2.0
iojs-3.3.0
iojs-3.3.1
nightly
node-dev
rc
v8-canary

# Node.js 18.4.0 をnodenvでインストール
> nodenv install 18.4.0
Downloading node-v18.4.0-darwin-arm64.tar.gz...
-> https://nodejs.org/dist/v18.4.0/node-v18.4.0-darwin-arm64.tar.gz
Installing node-v18.4.0-darwin-arm64...
Installed node-v18.4.0-darwin-arm64 to /<ホームディレクトリ>/.anyenv/envs/nodenv/versions/18.4.0

# Node.js 18.4.0 をグローバルに設定
> nodenv global 18.4.0

# Node.jsのバージョン確認
> node --version
v18.4.0

pyenvもインストールしておきます。

# pyenvのインストール
> anyenv install pyenv
/var/folders/tm/fwpf46g56_d3fc4kk45sx__40000gp/T/pyenv.20220822185834.62201 ~
Cloning https://github.com/pyenv/pyenv.git master to pyenv...
Cloning into 'pyenv'...
.
.
(中略)
.
.
Install pyenv succeeded!
Please reload your profile (exec $SHELL -l) or open a new session.

# シェルの再読み込み
> exec $SHELL -l
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish

# pyenvでインストールできるPythonのバージョンを確認
> pyenv install -l
Available versions:
  2.1.3
  2.2.3
  2.3.7
  2.4.0
  2.4.1
.
.
(中略)
.
.
  stackless-3.3.7
  stackless-3.4-dev
  stackless-3.4.2
  stackless-3.4.7
  stackless-3.5.4
  stackless-3.7.5

# Python 3.10.6 をpyenvでインストール
> pyenv install 3.10.6
python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.10.6.tar.xz...
-> https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tar.xz
Installing Python-3.10.6...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Installed Python-3.10.6 to /<ホームディレクトリ>/.anyenv/envs/pyenv/versions/3.10.6

# Python 3.10.6 をグローバルに設定
> pyenv global 3.10.6

# Pythonのバージョン確認
> python --version
Python 3.10.6

anyenv-update

anyenvでインストールしたnodenvやpyenvなどをアップデートするためにanyenv-updateをインストールします。

> mkdir -p $(anyenv root)/plugins
> git clone https://github.com/znz/anyenv-update.git $(anyenv root)/plugins/anyenv-update
Cloning into '/<ホームディレクトリ>/.anyenv/plugins/anyenv-update'...
remote: Enumerating objects: 87, done.
remote: Total 87 (delta 0), reused 0 (delta 0), pack-reused 87
Receiving objects: 100% (87/87), 13.33 KiB | 1.11 MiB/s, done.
Resolving deltas: 100% (33/33), done.

インストール後、anyenv updateでアップデートします。

> anyenv update
Skipping 'anyenv'; not git repo
Updating 'anyenv/anyenv-update'...
Updating 'nodenv'...
Updating 'nodenv/node-build'...
Updating 'nodenv/nodenv-vars'...
Updating 'anyenv manifest directory'...

1Password

パスワード管理は1Passwordを使っているので1Passwordをインストールします。

> brew install --cask 1password
==> Downloading https://downloads.1password.com/mac/1Password-8.7.3-aarch64.zip
######################################################################## 100.0%
==> Installing Cask 1password
==> Moving App '1Password.app' to '/Applications/1Password.app'
?  1password was successfully installed!

インストール後、セットアップをします。

今まで使用していたMacの1Passwordメニューバーのアカウント-アカウント名-その他のデバイスを設定-セットアップコードからQRコードが表示されるので、新しいMacでそのQRコードを読み込んでセットアップします。

1PasswordセットアップQRコード

Skitch

画面のキャプチャ用にSkitchをインストールします。

> brew install --cask skitch
==> Downloading https://cdn1.evernote.com/skitch/mac/release/Skitch-2.9.zip
######################################################################## 100.0%
==> Installing Cask skitch
==> Moving App 'Skitch.app' to '/Applications/Skitch.app'
?  skitch was successfully installed!

特に設定は変更していません。

Clipy

快適にコピペするためにClipyをインストールします。

> brew install --cask clipy
Running `brew update --auto-update`...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).

==> Downloading https://github.com/Clipy/Clipy/releases/download/1.2.1/Clipy_1.2.1.dmg
==> Downloading from https://objects.githubusercontent.com/github-production-release-asset-2e65be/37778564/4758b700-cd0f-11e8-8f19-2b50c895b989?X-Amz
######################################################################## 100.0%
==> Installing Cask clipy
==> Moving App 'Clipy.app' to '/Applications/Clipy.app'
?  clipy was successfully installed!

インストール後、Clipyの環境設定から記憶する履歴の数を30から70に変更します。

Clipyの環境設定から記憶する履歴の数を30から70に変更

今まで使っていたMacからClipyのスニペットをエクスポートし、新しいMacにインポートします。

Clipyエクスポート_インポート

Notion

Notionのデスクトップアプリをインストールします。

> brew install --cask notion
==> Downloading https://desktop-release.notion-static.com/Notion-2.1.0-arm64.dmg
######################################################################## 100.0%
==> Installing Cask notion
==> Moving App 'Notion.app' to '/Applications/Notion.app'
?  notion was successfully installed!

特に設定は変更していません。インストール後は自分のアカウントでサインインするだけです。

AWS CLI

AWS CLIをインストールします。

# AWS CLIのインストール
> brew install awscli
==> Downloading https://ghcr.io/v2/homebrew/core/gdbm/manifests/1.23
######################################################################## 100.0%
.
.
(中略)
.
.
==> Installing awscli
==> Pouring awscli--2.7.12.arm64_monterey.bottle.tar.gz
==> Caveats
The "examples" directory has been installed to:
  /opt/homebrew/share/awscli/examples
==> Summary
?  /opt/homebrew/Cellar/awscli/2.7.12: 12,612 files, 101.8MB
==> Running `brew cleanup awscli`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> awscli
The "examples" directory has been installed to:
  /opt/homebrew/share/awscli/examples

# AWS CLIのバージョン確認
> aws --version
aws-cli/2.7.12 Python/3.10.5 Darwin/21.5.0 source/arm64 prompt/off

インストール後、アクセスキーやシークレットアクセスキーなどの情報を入力します。

> aws configure
AWS Access Key ID [None]:xxxx
AWS Secret Access Key [None]:xxxx
Default region name [None]: us-east-1
Default output format [None]: json

AWS CLIのセットアップ後、~/.aws/configを編集し、任意のIAMロールにAssume Roleできるようにプロファイルを設定します。

# ~/.aws/config があることを確認
> ls -l ~/.aws/
total 16
-rw-------  1 <ユーザー名>  staff   43  7  6 09:54 config
-rw-------  1 <ユーザー名>  staff  116  7  6 09:54 credentials

# ~/.aws/config にプロファイルを追加
> vi ~/.aws/config

# ~/.aws/config にプロファイルが追加されたことを確認
> cat ~/.aws/config
[default]
region = us-east-1
output = json

[profile cm-non-97]
region = us-east-1
mfa_serial = arn:aws:iam::<Assume Role元のAWSアカウントID>:mfa/<IAMユーザー名>
role_arn = arn:aws:iam::<Assume Role先のAWSアカウントID>:role/<IAMロール名>
source_profile = default

# 常に追加したプロファイルにAssume Roleするようにfishのプロファイルを変更
> vi ~/.config/fish/config.fish

# 変更後のfishのプロファイルを確認
> cat ~/.config/fish/config.fish
# AWS
export AWS_DEFAULT_PROFILE=cm-non-97
export AWS_DEFAULT_REGION=us-east-1
export CDK_DEFAULT_REGION=us-east-1
export CDK_DEFAULT_ACCOUNT=<AWSアカウントID>

# LSCOLORS
export LSCOLORS=gxfxcxdxbxegedabagacad

# fzf
set -U FZF_LEGACY_KEYBINDINGS 0
set -U FZF_REVERSE_ISEARCH_OPTS "--reverse --height=100%"

if status is-interactive
    # Commands to run in interactive sessions can go here
    # brew
    eval (/opt/homebrew/bin/brew shellenv)

    # anyenv
    source (anyenv init -|psub)
end

# fishのプロファイルの読み込み
> source ~/.config/fish/config.fish

# Assume Roleされていることを確認
> aws sts get-caller-identity
Enter MFA code for arn:aws:iam::<Assume Role元のAWSアカウントID>:mfa/<IAMユーザー名>:
{
    "UserId": "AROA6KUFAVPUZTMI6DMFH:botocore-session-1657069632",
    "Account": "<Assume Role先のAWSアカウントID>",
    "Arn": "arn:aws:sts::<Assume Role先のAWSアカウントID>:assumed-role/<IAMロール名>/botocore-session-1657069632"
}

Session Manager plugin for the AWS CLI

SSMセッションマネージャーでポートフォワーディングする時に、Session Manager plugin for the AWS CLIが必要になるのでインストールします。

インストールしない場合、以下のようにエラーで怒られます。

> aws ssm start-session \
          --target <インスタンスID> \
          --document-name AWS-StartPortForwardingSession \
          --parameters '{"portNumber":["3389"],"localPortNumber":["13389"]}'

SessionManagerPlugin is not found. Please refer to SessionManager Documentation here: http://docs.aws.amazon.com/console/systems-manager/session-manager-plugin-not-found

Homebrewでインストールします。

> brew install --cask session-manager-plugin
.
.
(中略)
.
.
==> Downloading https://s3.amazonaws.com/session-manager-downloads/plugin/1.2.339.0/mac/session-manager-plugin.pkg
######################################################################## 100.0%
==> Installing Cask session-manager-plugin
==> Running installer for session-manager-plugin; your password may be necessary.
Package installers may write to any location; options such as `--appdir` are ignored.
installer: Package name is session-manager-plugin
installer: Installing at base path /
installer: The install was successful.
==> Linking Binary 'session-manager-plugin' to '/opt/homebrew/bin/session-manager-plugin'
?  session-manager-plugin was successfully installed!

AWS VPN Client

AWS Client VPNのクライアントをインストールします。

> brew install --cask aws-vpn-client
==> Downloading https://d20adtppz83p9s.cloudfront.net/OSX/3.1.0/AWS_VPN_Client.pkg
######################################################################## 100.0%
==> Installing Cask aws-vpn-client
==> Running installer for aws-vpn-client; your password may be necessary.
Package installers may write to any location; options such as `--appdir` are ignored.
installer: Package name is AWS VPN Client
installer: Installing at base path /
installer: The install was successful.
?  aws-vpn-client was successfully installed!

インストール後、今まで使用していたVPN接続で使用していたプロファイルをインポートします。

AWS VPN Clientプロファイル

Rancher Desktop

dockerdcontainerdも使いたい時があるのでRancher Desktopをインストールします。

> brew install rancher
.
.
(中略)
.
.
==> Installing Cask rancher
==> Moving App 'Rancher Desktop.app' to '/Applications/Rancher Desktop.app'
?  rancher was successfully installed!

インストール後、Rancher Desktopを起動して初期設定をします。コンテナランタイムはdockerdを使用します。

Rancher Desktop

しばらくすると、ネットワークやソケット周りのセットアップで管理者権限を要求されるのでOKをクリックして認証情報を入力します。

Rancher Desktop_Administrator Access Required

Configure PATHAutomaticを選択したのでfishのプロファイルを確認すると、Rancher Desktopが自身へのパスを通していました。

> cat ~/.config/fish/config.fish
# AWS
export AWS_DEFAULT_PROFILE=cm-non-97
export AWS_DEFAULT_REGION=us-east-1
export CDK_DEFAULT_REGION=us-east-1
export CDK_DEFAULT_ACCOUNT=<AWSアカウントID>

# LSCOLORS
export LSCOLORS=gxfxcxdxbxegedabagacad

# fzf
set -U FZF_LEGACY_KEYBINDINGS 0
set -U FZF_REVERSE_ISEARCH_OPTS "--reverse --height=100%"

# ALIAS
alias tree='tree -a -I "\.DS_Store|\.git|node_modules|cdk.out|venv|package|vendor\/bundle" -N'

if status is-interactive
    # Commands to run in interactive sessions can go here
    # brew
    eval (/opt/homebrew/bin/brew shellenv)

    # anyenv
    source (anyenv init -|psub)
end

### MANAGED BY RANCHER DESKTOP START (DO NOT EDIT)
set --export --prepend PATH "/<ホームディレクトリ>/.rd/bin"
### MANAGED BY RANCHER DESKTOP END (DO NOT EDIT)⏎

fishのプロファイルを読み込むとdockerkubectlを叩けれるようになりました。

> docker images
REPOSITORY                         TAG                    IMAGE ID       CREATED         SIZE
rancher/klipper-helm               v0.7.3-build20220613   b524fed05410   3 weeks ago     228MB
rancher/mirrored-library-busybox   1.34.1                 3c19bafed223   4 weeks ago     1.41MB
rancher/mirrored-library-traefik   2.6.2                  2ef507d0470e   3 months ago    99.7MB
rancher/mirrored-coredns-coredns   1.9.1                  f40c41555cd4   4 months ago    49.6MB
rancher/klipper-lb                 v0.3.5                 b12bbec1f461   5 months ago    7.31MB
rancher/local-path-provisioner     v0.0.21                fe8bc53de6e4   6 months ago    32.4MB
rancher/mirrored-metrics-server    v0.5.2                 1d64d3e888a2   7 months ago    60.8MB
rancher/mirrored-pause             3.6                    7d46a07936af   10 months ago   484kB
k8s.gcr.io/pause                   3.6                    7d46a07936af   10 months ago   484kB

> kubectl get nodes
NAME                   STATUS   ROLES                  AGE   VERSION
lima-rancher-desktop   Ready    control-plane,master   14m   v1.23.8+k3s2

他にもhelmrdctlもインストールされたようですね。

> ls -l /<ホームディレクトリ>/.rd/bin/
total 0
lrwxr-xr-x  1 <ユーザー名>  staff   80  7 11 15:39 docker@ -> /Applications/Rancher Desktop.app/Contents/Resources/resources/darwin/bin/docker
lrwxr-xr-x  1 <ユーザー名>  staff   87  7 11 15:39 docker-buildx@ -> /Applications/Rancher Desktop.app/Contents/Resources/resources/darwin/bin/docker-buildx
lrwxr-xr-x  1 <ユーザー名>  staff   88  7 11 15:39 docker-compose@ -> /Applications/Rancher Desktop.app/Contents/Resources/resources/darwin/bin/docker-compose
lrwxr-xr-x  1 <ユーザー名>  staff  101  7 11 15:39 docker-credential-ecr-login@ -> /Applications/Rancher Desktop.app/Contents/Resources/resources/darwin/bin/docker-credential-ecr-login
lrwxr-xr-x  1 <ユーザー名>  staff  103  7 11 15:39 docker-credential-osxkeychain@ -> /Applications/Rancher Desktop.app/Contents/Resources/resources/darwin/bin/docker-credential-osxkeychain
lrwxr-xr-x  1 <ユーザー名>  staff   78  7 11 15:39 helm@ -> /Applications/Rancher Desktop.app/Contents/Resources/resources/darwin/bin/helm
lrwxr-xr-x  1 <ユーザー名>  staff   81  7 11 15:39 kubectl@ -> /Applications/Rancher Desktop.app/Contents/Resources/resources/darwin/bin/kubectl
lrwxr-xr-x  1 <ユーザー名>  staff   81  7 11 15:39 kuberlr@ -> /Applications/Rancher Desktop.app/Contents/Resources/resources/darwin/bin/kuberlr
lrwxr-xr-x  1 <ユーザー名>  staff   81  7 11 15:39 nerdctl@ -> /Applications/Rancher Desktop.app/Contents/Resources/resources/darwin/bin/nerdctl
lrwxr-xr-x  1 <ユーザー名>  staff   79  7 11 15:39 rdctl@ -> /Applications/Rancher Desktop.app/Contents/Resources/resources/darwin/bin/rdctl

Zoom

オンラインミーティングにZoomを使うことがあるので、インストールします。

> brew install --cask zoom
==> Downloading https://cdn.zoom.us/prod/5.11.1.8356/arm64/Zoom.pkg
######################################################################## 100.0%
==> Installing Cask zoom
==> Running installer for zoom; your password may be necessary.
Package installers may write to any location; options such as `--appdir` are ignored.
Password:
installer: Package name is Zoom
installer: Installing at base path /
installer: The install was successful.
==> The Zoom package postinstall script launches the Zoom app
==> Attempting to close zoom.us.app to avoid unwanted user intervention
?  zoom was successfully installed!

インストール後、サインインして以下の設定を行います。

  • ビデオに常に参加者名を表示にチェックを入れる
  • ミーティング参加時にビデオを停止のチェックを外す Zoom_ビデオ
  • ミーティング参加時にマイクをミュートに設定のチェックを外す Zoom_オーディオ
  • 現在のサイズを保持するを選択 Zoom_画面共有
  • バーチャル背景を追加 Zoom_バーチャル背景

Microsoft Teams

オンラインミーティングにMicrosoft Teamsも使うことがあるので、インストールします。

> brew install --cask microsoft-teams
Running `brew update --auto-update`...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/cask).
==> New Casks
wirecast                                                                   yousician

==> Downloading https://statics.teams.cdn.office.net/production-osx/1.5.00.17261/Teams_osx.pkg
######################################################################## 100.0%
==> Installing Cask microsoft-teams
==> Running installer for microsoft-teams; your password may be necessary.
Package installers may write to any location; options such as `--appdir` are ignored.
installer: Package name is Microsoft Teams
installer: Installing at base path /
installer: The install was successful.
?  microsoft-teams was successfully installed!

Microsoft Remote Desktop

RDP接続したい時がたまにあるのでMicrosoft Remote Desktopをインストールします。

> brew install --cask microsoft-remote-desktop
==> Downloading https://officecdn-microsoft-com.akamaized.net/pr/C1297A47-86C4-4C1F-97FA-950631F94777/MacAutoupdate/Microsoft_Remote_Desktop_10.7.7_i
######################################################################## 100.0%
==> Installing Cask microsoft-remote-desktop
==> Running installer for microsoft-remote-desktop; your password may be necessary.
Package installers may write to any location; options such as `--appdir` are ignored.
installer: Package name is Microsoft Remote Desktop v10.7.7
installer: Upgrading at base path /
installer: The upgrade was successful.
?  microsoft-remote-desktop was successfully installed!

インストール後、Preferences-Resolutionsから解像度を1440 × 900に変更します。

Microsoft Remote Desktop

Git

デフォルトでGitはインストールされていますが、GitもHomebrewで管理します。

# デフォルトでGitのバージョン確認
> git --version
git version 2.32.1 (Apple Git-133)

# Gitのインストール
> brew install git
.
.
(中略)
.
.
==> Installing git
==> Pouring git--2.37.0.arm64_monterey.bottle.tar.gz
==> Caveats
The Tcl/Tk GUIs (e.g. gitk, git-gui) are now in the `git-gui` formula.
Subversion interoperability (git-svn) is now in the `git-svn` formula.

Emacs Lisp files have been installed to:
  /opt/homebrew/share/emacs/site-lisp/git
==> Summary
?  /opt/homebrew/Cellar/git/2.37.0: 1,552 files, 45.0MB
==> Running `brew cleanup git`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> git
The Tcl/Tk GUIs (e.g. gitk, git-gui) are now in the `git-gui` formula.
Subversion interoperability (git-svn) is now in the `git-svn` formula.

Emacs Lisp files have been installed to:
  /opt/homebrew/share/emacs/site-lisp/git

# Gitのバージョン確認
> git --version
git version 2.37.0

Gitで使用するユーザー情報を設定します。

> git config --global user.name "non-97"
> git config --global user.email "<GitHubアカウントのメールアドレス>"

.DS_StoreをCommitしないように~/.config/git/ignoreを作成して、.DS_Storeを追加します。

> mkdir -p ~/.config/git/
> echo .DS_Store > ~/.config/git/ignore
> cat ~/.config/git/ignore
.DS_Store

.gitignore.ioで.gitignoreのテンプレートを探して~/.config/git/ignoreに追加しても良いと思います。

GitHub CLI

コマンドでGitHubの操作をするためにGitHub CLIをインストールします。

> brew install gh
==> Downloading https://ghcr.io/v2/homebrew/core/gh/manifests/2.13.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/gh/blobs/sha256:e74682023de43e8cbd2a6497968fbbceff7a52f948e379a775d63ee6b2ab134a
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:e74682023de43e8cbd2a6497968fbbceff7a52f948e379a775d63ee6b2ab134a?se=2022-07-
######################################################################## 100.0%
==> Pouring gh--2.13.0.arm64_monterey.bottle.tar.gz
==> Caveats
fish completions have been installed to:
  /opt/homebrew/share/fish/vendor_completions.d
==> Summary
?  /opt/homebrew/Cellar/gh/2.13.0: 138 files, 34.5MB
==> Running `brew cleanup gh`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

インストール後、GitHubアカウントで認証をします。

# GitHubアカウントで認証
> gh auth login
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Login with a web browser

! First copy your one-time code: XXXX-XXXX
Press Enter to open github.com in your browser...
✓ Authentication complete.
- gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as non-97

# 認証状態の確認
> gh auth status
github.com
  ✓ Logged in to github.com as non-97 (/<ホームディレクトリ>/.config/gh/hosts.yml)
  ✓ Git operations for github.com configured to use https protocol.
  ✓ Token: *******************

試しにGitHub CLIでPublicリポジトリ5件を取得できることを確認します。

> gh repo list --public --limit 5
Flag --public has been deprecated, use `--visibility=public` instead

Showing 5 of 24 repositories in @non-97 that match your search

non-97/amazon-vpc-traffic-mirroring-supports-sending-mirrored-traffic-gateway-load-balancer    public  10d
non-97/assign-ip-addresses-outside-the-rfc-1918-definition-to-the-cidr-block-of-the-vpc        public  26d
non-97/pondering-source-ip-address-of-network-load-balancer                                    public  Jun 10, 2022
non-97/set-all-ec2-instances-in-the-stack-to-ebs-optimized-instances-in-aws-cdk                public  Jun  9, 2022
non-97/access-amazon-fsx-for-netapp-ontap-via-network-load-balancer                            public  Jun  1, 2022

git-secrets

AWSのアクセスキーなどをリポジトリに混入させないようにgit-secretsをインストールします。

> brew install git-secrets
.
.
(中略)
.
.
==> Pouring git-secrets--1.3.0.all.bottle.tar.gz
?  /opt/homebrew/Cellar/git-secrets/1.3.0: 8 files, 66KB
==> Running `brew cleanup git-secrets`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

インストール後、以降のリポジトリにgit-secretsを自動で適用するように設定します。

# AWSアクセスキーの標準パターンをGitの設定ファイルに書き込む
> git secrets --register-aws --global
OK

# ~/.gitconfig が更新されたことを確認
> cat ~/.gitconfig
[user]
	name = non-97
	email = <GitHubアカウントのメールアドレス>
[secrets]
	providers = git secrets --aws-provider
	patterns = (A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}
	patterns = (\"|')?(AWS|aws|Aws)?_?(SECRET|secret|Secret)?_?(ACCESS|access|Access)?_?(KEY|key|Key)(\"|')?\\s*(:|=>|=)\\s*(\"|')?[A-Za-z0-9/\\+=]{40}(\"|')?
	patterns = (\"|')?(AWS|aws|Aws)?_?(ACCOUNT|account|Account)_?(ID|id|Id)?(\"|')?\\s*(:|=>|=)\\s*(\"|')?[0-9]{4}\\-?[0-9]{4}\\-?[0-9]{4}(\"|')?
	allowed = AKIAIOSFODNN7EXAMPLE
	allowed = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

# リポジトリ用のGit hooksを ~/.git-templates/git-secrets にインストール
> git secrets --install ~/.git-templates/git-secrets
✓ Installed commit-msg hook to /<ホームディレクトリ>/.git-templates/git-secrets/hooks/commit-msg
✓ Installed pre-commit hook to /<ホームディレクトリ>/.git-templates/git-secrets/hooks/pre-commit
✓ Installed prepare-commit-msg hook to /<ホームディレクトリ>/.git-templates/git-secrets/hooks/prepare-commit-msg

# インストールしたテンプレートを読み込む
> git config --global init.templatedir '~/.git-templates/git-secrets'

実際に新しいGitの環境でgit-secretsが動作するのか確認します。

# 検証用Git環境の作成
> mkdir git-secrets-test
> cd git-secrets-test/
> git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: 	git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: 	git branch -m <name>
Initialized empty Git repository in /<ホームディレクトリ>/developes-io/git-secrets-test/.git/

# ダミーのシークレットアクセスキーを含むファイルを作成
> echo "aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEa" > aws_credential.txt

# Commitする
> git add .
> git commit -m "initial commit"
aws_credential.txt:1:aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEa

[ERROR] Matched one or more prohibited patterns

Possible mitigations:
- Mark false positives as allowed using: git config --add secrets.allowed ...
- Mark false positives as allowed by adding regular expressions to .gitallowed at repository's root directory
- List your configured patterns: git config --get-all secrets.patterns
- List your configured allowed patterns: git config --get-all secrets.allowed
- List your configured allowed patterns in .gitallowed at repository's root directory
- Use --no-verify if this is a one-time false positive

Matched one or more prohibited patternsと意図した通り、Commitできませんでした。

ちなみに、git initして作成したリポジトリだけでなくgit cloneしたリポジトリも検知対象になります。

その他コマンド

その他、よく使う以下コマンドをHomebrewでインストールします。

# python-yq のインストール
> brew install python-yq
.
.
(中略)
.
.
==> Installing dependencies for python-yq: oniguruma and jq
==> Installing python-yq dependency: oniguruma
==> Pouring oniguruma--6.9.8.arm64_monterey.bottle.tar.gz
?  /opt/homebrew/Cellar/oniguruma/6.9.8: 14 files, 1.4MB
==> Installing python-yq dependency: jq
==> Pouring jq--1.6.arm64_monterey.bottle.1.tar.gz
?  /opt/homebrew/Cellar/jq/1.6: 18 files, 1.2MB
==> Installing python-yq
==> Pouring python-yq--3.0.2.arm64_monterey.bottle.tar.gz
?  /opt/homebrew/Cellar/python-yq/3.0.2: 878 files, 11.3MB
==> Running `brew cleanup python-yq`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

# treeのインストール
> brew install tree
==> Downloading https://ghcr.io/v2/homebrew/core/tree/manifests/2.0.2
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/tree/blobs/sha256:4067f9a8f40d9bbf337272fcee99df3ad4d055ebbaf7166fed039e1bb1a45cb9
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:4067f9a8f40d9bbf337272fcee99df3ad4d055ebbaf7166fed039e1bb1a45cb9
######################################################################## 100.0%
==> Pouring tree--2.0.2.arm64_monterey.bottle.tar.gz
?  /opt/homebrew/Cellar/tree/2.0.2: 8 files, 167.8KB
==> Running `brew cleanup tree`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

インストール後、treeのエイリアスを作成します。

> vi ~/.config/fish/config.fish
> cat ~/.config/fish/config.fish
# AWS
export AWS_DEFAULT_PROFILE=cm-non-97
export AWS_DEFAULT_REGION=us-east-1
export CDK_DEFAULT_REGION=us-east-1
export CDK_DEFAULT_ACCOUNT=<AWSアカウントID>

# LSCOLORS
export LSCOLORS=gxfxcxdxbxegedabagacad

# fzf
set -U FZF_LEGACY_KEYBINDINGS 0
set -U FZF_REVERSE_ISEARCH_OPTS "--reverse --height=100%"

#ALIAS
alias tree='tree -a -I "\.DS_Store|\.git|node_modules|cdk.out|venv|package|vendor\/bundle" -N'

if status is-interactive
    # Commands to run in interactive sessions can go here
    # brew
    eval (/opt/homebrew/bin/brew shellenv)

    # anyenv
    source (anyenv init -|psub)
end

fish_update_completions

最後にfish_update_completionsでシステムにインストールされているマニュアルページを読み込んで入力補完のスクリプトを更新します。

> fish_update_completions
Parsing man pages and writing completions to /<ホームディレクトリ>/.local/share/fish/generated_completions/
  5244 / 5244 : zic.8

随時更新予定

私のMacの初期セットアップ内容を紹介しました。

何か設定変更したら、この記事も随時変更する予定です。

ベストプラクティスおすすめ設定という訳ではないですが、Macの最初にやる設定として参考になればと思います。

この記事が誰かの助けになれば幸いです。

以上、AWS事業本部 コンサルティング部の のんピ(@non____97)でした!