- 投稿日:2020-02-12T17:13:00+09:00
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問題は上のように
- 投稿日:2020-02-12T14:21:16+09:00
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: ...と表示されたときの対処法です。
- ファイル一覧をコピー、テキストファイルにペーストして保存
- 以下のコマンドを実行
sudo xargs rm -v < list.txt
list.txt
はテキストファイルのファイル名に変更してください。参考
- 投稿日:2020-02-12T12:18:45+09:00
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'