20201118のMacに関する記事は4件です。

Macのターミナル上でTab補完を有効にしたら、Git操作が爆速になった話

エンジニアの先輩から教わったスキルハックです。

ターミナル上で、pushする際に、git branchでブランチ名確認して、
feature/fix-password-formいちいち打つのめんどくさいな〜。」って思っていました。

Tab補完ができれば、feくらいのタイミングでもう入力できます。
楽ちん楽ちん。

コミットする際も地味にめんどくさい。
git commit -m "xxxxxxxx"

g → tab → c → tab → "xxxxxx"
てな感じでスイスイ行きます。

Sourcetreeをaddする時くらいしか使わない自分からするとだいぶありがたい。

だまされたと思ってやってみてください。マジで捗ります。

導入方法

macOS CatalinaからMacのデフォルトのシェルがzshになったそうです。
それまでは、bashだったそう。
シェルについて詳しくないですが、以下の記事がわかりやすくまとまってました。
bashとzshの違い。bashからの乗り換えで気をつけるべき16の事柄

zsh-completionsをインストール

https://formulae.brew.sh/formula/zsh-completions
上記サイトの通り、コマンドを叩く
-[注意]- 就業中や勉強中の方はビール飲みたくなるので、見ないほうがいい。

brew install zsh-completions

設定を有効にするために~/.zshrcに追記

 if type brew &>/dev/null; then
     FPATH=$(brew --prefix)/share/zsh-completions:$FPATH

     autoload -Uz compinit
     compinit
 fi

これだけです。
ちなみに自身は.zshrcファイルがなかったので

touch .zshrc 

でファイルを作ってからvimを使って追記しました。
エディタはなんでもいいと思います。

vim .zshrc

ターミナルを開き直すのは面倒なので以下のコマンドで再読み込み

source .zshrc 

すると、Tab補完が有効になっているはずです。
これで今日から、Tab補完なしで生きれない体になったぜ!!
マジでgitの操作が捗ります。多分1.8倍くらい。ありがたや。アディオス。

参考

Homebrew Formulae
zsh-users/zsh-completions

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Mac M1でhomebrewをインストールできるの?

Rosettaを使用しないとまだ使えない

現状、ターミナルからhomebrewをインストールしようとするとこのような出力が表示されます。

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

Homebrew is not (yet) supported on ARM processors!
Rerun the Homebrew installer under Rosetta 2.
If you really know what you are doing and are prepared for a very broken experience you can use another installation option for installing on ARM:
  https://docs.brew.sh/Installation

出力通り、Rossetaを経由しないとダメみたいですね。

ターミナルをRossetaを使用して開くようにする

  • ターミナルの情報を開きます。

image.png

Rosettaを使用して開くにチェック

そうすることでhomebrewのインストールが可能になります。

$ brew doctor

Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: You are using macOS 11.0.
We do not provide support for this released but not yet supported version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Twitter or any other official channels. You are responsible for resolving
any issues you experience while you are running this
released but not yet supported version.
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Mac M1(Apple Silicon)でhomebrewをインストールできるの?

今まで通りにインストールしようとしたら...

現状、ターミナルから今まで通りhomebrewをインストールしようとするとこのような出力が表示されます。

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

Homebrew is not (yet) supported on ARM processors!
Rerun the Homebrew installer under Rosetta 2.
If you really know what you are doing and are prepared for a very broken experience you can use another installation option for installing on ARM:
  https://docs.brew.sh/Installation

今まで通りではダメみたいですね。

対策1 ターミナルをRossetaを使用して開くようにする

  • ターミナルの情報を開きます。

image.png

Rosettaを使用して開くにチェック

そうすることでhomebrewのインストールが可能になります。

$ brew doctor

Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: You are using macOS 11.0.
We do not provide support for this released but not yet supported version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Twitter or any other official channels. You are responsible for resolving
any issues you experience while you are running this
released but not yet supported version.

対策2 /opt/homebrewに保存するように実行する

https://docs.brew.sh/Installation では

However do yourself a favour and install to /usr/local on macOS Intel, /opt/homebrew on macOS ARM, and /home/linuxbrew/.linuxbrew on Linux.

とあります。
macOS ARMでは/opt/homebrewにインストールしてねと案内されています。

実行コマンド

cd /opt
mkdir homebrew
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew

まとめ

せっかくのARMなので極力Rosetta使用したくないですよね。
いずれはuniversalに移行するのに...

状況に応じてインストールしましょう!

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Mac に RISC-V の開発環境構築

Mac に RISC-V Toolchain をインストール

Mac に RISC-V の クロスコンパイラ等が含まれる、RISC-V Toolchain をインストールする。

インストール

homebrew をインストールする。

homebrew は大抵の人が入れていると思うのでここはスキップ。

tap する

$ brew tap riscv/riscv
  • tap について
    • 公式ではないリポジトリをHomebrewに追加するもの。
    • install, uninstall, update ができるようになる。
    • github で <user>/homebrew-hoge となっているリポジトリは brew tap <user>/hoge で tapできる。

ToolChain をインストールする

64bit だけでいい人

# brew install riscv-tools

32bit も欲しい人

# brew install riscv-gnu-toolchain --with-multilib

アップデート

  • アップデートは以下のコマンド brew reinstall --build-from-source riscv-gnu-toolchain

インストールでエラーが出ました

fatal: Needed a single revision
Unable to find current revision in submodule path 'qemu/roms/u-boot'
Failed to recurse into submodule path 'qemu'
Error: Failed to download resource "riscv-gnu-toolchain"
Failure while executing; `git submodule update --init --recursive` exited with 1. Here's the output:
fatal: Needed a single revision
Unable to find current revision in submodule path 'qemu/roms/u-boot'
Failed to recurse into submodule path 'qemu'
  • とりあえずqemuを削除してもう一回手動でやってみる
$ cd ~/Library/Caches/Homebrew/riscv-gnu-toolchain--git
$ rm -rf qemu
$ git submodule update --init --recursive
$ brew install riscv-gnu-toolchain --with-multilib

できた

Big Sur の人

エラーが出て make に失敗します!!!

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む