下記のelispを.emacs.el等に貼付けてから M-x zsh-last-historyすると,zshで最後に打ったコマンドを編集中のバッファに挿入します。ChangeLogとか書いてる時にコマンド履歴をいちいちコピペするの面倒だと思って書いた。
環境に依存しないとは思うけど、いちおう*scratch*で動作を試してくださいね。
(defun zsh-last-history (num) "Insert zsh's last history into current buffer." (interactive "p") (let ((command (concat (format "tail -n %s " num) (expand-file-name "~/.zsh-history") " | " "perl -e 'print map{ (split /\\d+:\\d;/)[1] } <>'"))) (shell-command command t)))
注意:
- 自分の.zshrcには setopt extended_history が入ってました。これを点けてないzshだとうまくうごかないかな
- M-数字 M-x zsh-last-history で任意の件数の履歴挿入もできる!
- 改行が含まれているコマンドの場合、うまくいかないです・・・
これだとまだ使いにくいので、kill-summary.elみたいに、任意の件数の履歴を一覧表示し、選択してヤンク ってのを今作ってる。需要は全然なさそうですが。
追記:
bashだとこれ。なんだ簡単だな
(defun bash-last-history (num) "Insert bash's last history into current buffer." (interactive "p") (let ((command (concat (format "tail -n %s " num) (expand-file-name "~/.bash_history")))) (shell-command command t)))
実は全然たいしたものを書いてないんだってことに気づいてがっかり中。