macのターミナルでhistoryで表示されるコマンドが少なすぎるときの対処法

Apple

historyで表示されるコマンドが少なすぎる…

新しいMacbook Airを購入したところ ターミナルでhistoryが少ししか表示されなくなって困りました。 Catalina以降のmacOSではデフォルトのシェルが bashからzshに変更になったようで zshの場合はhistoryが16件しか表示されないようです。
% history
 1154  h
 1155  su -
 1156  vi ~/.zshrc
 1157  source ~/.zshrc
 1158  h
 1159  h
 1160  hg git
 1161  vi ~/.zshrc
 1162  source ~/.zshrc
 1163  h
 1164  vi ~/.zshrc
 1165  source ~/.zshrc
 1166  h
 1167  history
 1168  history -100
 1169  history -30
「history -100」とすれば100件表示できますが 毎回これを打つのは面倒なのでログイン時の設定に書いてしまいましょう。 まずHISTSIZEでhistoryに残したい件数を設定して 「history」コマンドはよく使うので 「h」だけで「history -100」を実行できるよう エイリアスを設定してしまいましょう。 さらにおまけで「hg」に「history -1000|grep」を設定して 直近1000個からコマンドを検索できるようにしましょう。
% vi ~/.zshrc
HISTSIZE=1000

alias h='history -100'
alias hg='history -1000|grep'
設定を再読み込みします。
% source ~/.zshrc
これで「h」だけでコマンド履歴100件表示できるようになりました。
% h
...(長いので省略)
 1151  vi ~/.zshrc
 1152  history
 1153  vi ~/.zshrc
 1154  h
 1155  su -
 1156  vi ~/.zshrc
 1157  source ~/.zshrc
 1158  h
 1159  h
 1160  hg git
 1161  vi ~/.zshrc
 1162  source ~/.zshrc
 1163  h
 1164  vi ~/.zshrc
 1165  source ~/.zshrc
 1166  h
 1167  history
 1168  history -100
 1169  history -30
 1170  history
 1171  history -30
 1172  ll ~/
 1173  vi ~/.zshrc
「hg」でhistoryのgrepもOKですね。
% hg git
 1118  git pull
 1119  git status
 1122  git log
 1123  git status
 1140  hg git
 1142  hg git
 1144  hg git
 1160  hg git
タイトルとURLをコピーしました