20200212のMacに関する記事は3件です。

Shellのコマンド履歴に任意のコマンドを残したい

Problem

Interactive filterを使っていたりするとコマンドよりも結果をhistoryに残した方が便利なケースが度々あります。

# 例:fzfで選択したファイルをvimで開く
alias v='_vim_fzf'
_vim_fzf () {
  local file
  file=$(fzf +m -q "$1") && vim "$file"
}

上記の場合、historyを遡っても選んだファイルは出てきません。

Solution

Bashではhistory -sを使います。

_vim_fzf () {
  local file
  file=$(fzf +m -q "$1") && history -s "vim $file" && vim "$file"
}

このように書き直すと、vコマンドの代わりにvim [選んだファイル]が履歴に残るのでCtrl-RやCtrl-Pでファイルを再び開くことが可能になります。

Further Work (Zsh)

Zshではprint -sが相当するそうです。

$ print -s "alternative command"
$ history
# ...
#  99 print -s "alternative command"
# 100 alternative command

問題は上のようにprintコマンド自体も保存されてしまうことです。もっと良い方法があれば教えてくださいmm

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

Warning: Unbrewed header files were found in〜の対処法

Warning: Unbrewed header files were found in ...
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:
...

と表示されたときの対処法です。


  1. ファイル一覧をコピー、テキストファイルにペーストして保存
  2. 以下のコマンドを実行
sudo xargs rm -v < list.txt

list.txt はテキストファイルのファイル名に変更してください。

参考

https://discourse.brew.sh/t/unbrewed-header-files/2607/6

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

Apple ScriptでMacを終了・再起動する

確認ダイヤログを表示しないでシャッタダウン

osascript -e 'tell app "System Events" to shut down'

確認ダイアログ(1分)を表示してシャットダウン

osascript -e 'tell app "loginwindow" to «event aevtrsdn»'

確認ダイヤログを表示しないで再起動

osascript -e 'tell app "System Events" to restart'

確認ダイアログ(1分)を表示して再起動

osascript -e 'tell app "loginwindow" to «event aevtrrst»'

確認ダイアログ(1分)を表示してログアウト

osascript -e 'tell app "System Events" to log out'
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む