かすみん日記

暇なときに何か喋ります

【Mac】メニューバーの日付の色がおかしい

環境

症状

なんかメニューバーの日付の文字色が薄くなった。

f:id:geniusium:20210408223902p:plainf:id:geniusium:20210408223913p:plain
左:文字色がおかしい。右:正しい

OSを再起動しても killall -KILL SystemUIServer しても治らなかったので困った。

解決

どうやら、おやすみモードの仕様?らしい。

コントロールセンターからおやすみモードをオフにしたら治った。

f:id:geniusium:20210408224353p:plain

再びおやすみモードをオンにしたら、日付の文字色がまた薄くなる。

f:id:geniusium:20210408224619p:plain

おやすみモードはオンで、かつ日付の色を薄くしないためには、 メニューバーにおやすみモードのアイコンをおくと良い(コントロールセンターからドラッグ&ドロップ)。

メニューバーにおやすみモードアイコンがあれば、日付の代わりにおやすみモードのアイコン色が薄くなる。

ということで、原因もわかったので解決と。

参考

www.askdavetaylor.com

結果関係なかったけど読んだ記事:

infornography.blue

http://eien.seesaa.net/article/298475902.html

【vscode】rubyのコード整形(formatter)

vscoderubyのフォーマットを行う方法です。

rufo はバカなので使ってはダメです。

手順

vscode拡張機能 prettierprettier+ をインストール。

prettier+ は何か2つありますが、作者が Benas Svipas の方をインストールしてください。

これだけだとrubyに対応していないので、rubyプラグインをnpmでインストールする;

npm install --save-dev prettier @prettier/plugin-ruby

settings.json は、例えば次のような感じ;

  "editor.formatOnSave": true,
  "editor.formatOnPaste": true,
  "[ruby]": {
    "editor.defaultFormatter": "svipas.prettier-plus"
  }

以上。

参考

github.com

qiita.com

vscodeでerbのフォーマット

railsとかで使う erb ファイルのコードの自動整形(フォーマット)をvscodeで行う方法。

Prettierだと対応してないみたいなのでBeautifyという拡張機能を使う。

手順

vscode拡張機能Beautify」をインストール。

設定ファイル settings.json に下記コードを追加;

"[erb]": {
  "editor.defaultFormatter": "HookyQR.beautify"
},
"beautify.language": {
  "html": ["html", "erb"]
},
"editor.formatOnPaste": true,
"editor.formatOnSave": true,

これで、保存やペースト時に自動でフォーマットされる。

Node.jsのインストール(❌公式サイトpkg、❌homebrew)

Node.jsnodebrew を使ってインストール・バージョン管理しましょう。

もしnode.jsの公式サイトからインストーラーをDLしてnodeをインストールしちゃうと、後々面倒なことになります;

geniusium.hatenablog.com

もし brew install node でnodeをインストールしちゃうと、後々面倒なことになります;

geniusium.hatenablog.com

環境

インストール

node のバージョン管理ツール nodebrew を homebrew でインストール;

brew install nodebrew

nodebrew の初期設定;

# セットアップ
nodebrew setup

# パスの追加
echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.zshrc
source ~/.zshrc

インストール可能な node のバージョンを調べる;

nodebrew ls-remote

今回は、最新版の v15.9.0 をインストールする;

nodebrew install v15.9.0

v15.9.0 を使うようにする

nodebrew set v15.9.0

nodenpm のバージョン確認;

% node -v
v15.9.0

% npm -v
7.5.3

参考

qiita.com

qiita.com

【homebrew】Warning: You have unlinked kegs in your Cellar.

brew doctor したら brew link node しろと怒られるが、それができない。

前提

  • 公式サイトからNode.jsをインストールした
  • brewでも node をインストールしている(yarn の依存パッケージとして)
  • nodenodebrew で管理したい(している)

結論

  1. pkgでインストールした node.js を削除
  2. brew uninstall node
  3. npm install --global yarn

症状と挑戦

brew doctor

お医者さんによると以下のような感じ;

% brew doctor

略
Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected header files:
  /usr/local/include/node/略/略.h
  略(大量)

Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause formulae that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  node

brew link

brew link node をしてもパーミションエラー;

% brew link node
Linking /usr/local/Cellar/node/15.9.0... 
Error: Could not symlink include/node/common.gypi
/usr/local/include/node is not writable.

brew unlink node はエラーは出ないがなんの効果もない。

brew reinstall node

brew管理のnodeを再インストールしてみる;

% brew reinstall node
略
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink include/node/common.gypi
/usr/local/include/node is not writable.

You can try again using:
  brew link node
Warning: The post-install step did not complete successfully
You can try again using:
  brew postinstall node
==> Summary
🍺  /usr/local/Cellar/node/15.9.0: 3,390 files, 56.1MB

brew postinstall

じゃあということでポストインストールしてみる;

 % brew postinstall node
==> Postinstalling node
Warning: The post-install step did not complete successfully
You can try again using:
  brew postinstall node

sudo brew

sudo をつけて brew linkbrew postinstall をしてもだめ。

pkgのnodeをアンインストール

以下の記事を参考に、公式サイトからインストールしたnodeを完全に削除してみる;

geniusium.hatenablog.com

pkgでインストールしたnodeを削除してもダメ。 でも、エラーメッセージが少し変わった;

% brew link node
Linking /usr/local/Cellar/node/15.9.0... 
Error: Could not symlink share/systemtap/tapset/node.stp
/usr/local/share/systemtap/tapset is not writable.

解決?

まあ、パーミッションエラーということなので、そのディレクトリに権限付与すればいいだけではある;

sudo chown -R $USER /usr/local/share/systemtap/tapset

すると、エラーは出ない;

% brew link node                                       
Linking /usr/local/Cellar/node/15.9.0... 7 symlinks created.

brew doctor でも該当の警告は消えた。

真の解決法

いや、なんで手動で権限与えなきゃあかんねん。

めんどい、というかどう考えてもbrewの不具合、バグ。

そもそも nodenodebrew で別に管理しているのに yarn のためにそれとは別に node をインストールしなきゃいけないのはおかしい。

yarn インストール時に node はインストールしないような設定があるが、バグでうまくいかないらしい。

yarn を普通にインストールしてから、依存関係無視して node だけアンインストールすればいいらしいが、いや、だからめんどいて。

そして導き出されるたった一つの真実とは、、、そもそも brewyarn をインストールするのをやめる!!!

はい;

brew uninstall yarn
brew uninstall node

これで brew doctor で該当の警告は消えます。

yarn のインストール

npm でインストール;

npm install --global yarn

確認;

% yarn -v
1.22.10

npm list -g でも確認できます。

おしまい。

brewはちょいちょい面倒なことが起こるのであまり過信してはいけない。

参考

classic.yarnpkg.com

これはよくないという方法;

qiita.com

公式サイトからインストールしたNode.jsを完全に削除する

過ち

情弱すぎて害悪公式サイトからNode.jsをインストールしちゃった;;

全部消して、brew なり nodebrew なりでインストールしなおそう!!

環境

  • mac bigsur
  • インストールしたpkgの node.js と npm のバージョン:

f:id:geniusium:20210224025207p:plain

消す!!!

結局、消すべきファイルやディレクトリは以下の通りです;

# node
sudo rm     /usr/local/bin/node
sudo rm -rf /usr/local/include/node/
sudo rm     /usr/local/lib/dtrace/node.d
sudo rm -rf /usr/local/share/doc/
sudo rm     /usr/local/share/man/man1/node.1
sudo rm     /usr/local/share/systemtap/tapset/node.stp

# npm
sudo rm     /usr/local/bin/npm
sudo rm -rf /usr/local/lib/node_modules/
sudo rm -rf /Users/$USER/.npm

# あとこれも
sudo rm     /var/db/receipts/org.nodejs.*

消し残しがあったら教えてください;;

補足

下記の bom ファイル?にインストールされたファイルが書かれているらしい

/var/db/receipts/org.nodejs.node.pkg.bom
/var/db/receipts/org.nodejs.npm.pkg.bom

cat で見ようとするとなんかやばくなるので lsbom コマンドで内容を見る;

lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.npm.pkg.bom

ここに大体のファイルは書いてあるが、以下の取りこぼしもあるっぽい;

/usr/local/bin/npm
/Users/$USER/.npm

あとは bom ファイル自身など

/var/db/receipts/org.nodejs.node.pkg.bom
/var/db/receipts/org.nodejs.npm.pkg.bom
/var/db/receipts/org.nodejs.node.pkg.plist
/var/db/receipts/org.nodejs.npm.pkg.plist

stack overflowに書いてあったのは全部確認したつもり。

このベストアンサーの回答は少しまずいので、この記事の最初に書いたやつか、以下の1行にまとめたコマンドを使うようにしてください;

sudo rm -rv /{usr/local/{bin/{node,npm},lib/{dtrace/node.d,node_modules},share/{doc,man/man1/node.1,systemtap/tapset/node.stp},include/node},Users/$USER/.npm,var/db/receipts/org.nodejs.*}

node の再インストール

nodenodebrew で管理するのがよさそうです。

nodebrew 自体は brew でインストールできます。

詳しくは以下の記事で;

aaa

参考

hacknote.jp

stackoverflow.com

Ignoring GEM because its extensions are not built.

brewでなんかメッセージが出る;

% brew -v
Ignoring eventmachine-1.2.7 because its extensions are not built. Try: gem pristine eventmachine --version 1.2.7
Ignoring ffi-1.11.1 because its extensions are not built. Try: gem pristine ffi --version 1.11.1
Ignoring http_parser.rb-0.6.0 because its extensions are not built. Try: gem pristine http_parser.rb --version 0.6.0
Ignoring sassc-2.2.1 because its extensions are not built. Try: gem pristine sassc --version 2.2.1
Homebrew 3.0.2
Homebrew/homebrew-core (git revision d2b25; last commit 2021-02-23)
Homebrew/homebrew-cask (git revision 12eb5; last commit 2021-02-23)

Tryをトライしても、出力に変わりがない。

rbenv global system でシステムの ruby に切り替えてTryをトライしてみると、パーミッションエラーが出る。

sudu をつけて gem pristine してもパーミッションエラーとなる。は?

仕方がないので、関係するgemをアンインストールすることにする;

gem uninstall eventmachine
gem uninstall ffi
gem uninstall http_parser.rb
gem uninstall sassc

別のgemが依存しているがイイか?と聞かれるが全部 y と回答。

すると、Ignoringなんたらはもう表示されなくなった;

% brew -v
Homebrew 3.0.2
Homebrew/homebrew-core (git revision d2b25; last commit 2021-02-23)
Homebrew/homebrew-cask (git revision 12eb5; last commit 2021-02-23)

rails s とかで特にエラー出たりしないし、まあこれでよかった?

参考

参考にならなかった;

stackoverflow.com