Skip to content

History

Justin Hileman edited this page Jul 23, 2017 · 2 revisions

⏳ Managing history

The history command is your primary interface to PsySH history. With this command, you can show, search, save or replay your shell history.

Showing history

When invoked without options, the history command shows all PsySH history. If there’s a lot of it, the output will be paged.

>>> hist
0: function z() { throw new RuntimeException; }
1: function y() { z(); }
2: function x() { y(); }
3: x()
4: wtf
>>>

Show only a slice of history using the --show option: --show 3 will show a single line, --show 1..3 will show a range, and --show 3.. will show from the third to the last line of your history.

>>> hist --show 1..3
1: function y() { z(); }
2: function x() { y(); }
3: x()
>>>

The --head N and --tail M options show the first N lines and the last M lines, respectively.

>>> hist --head 3
0: function z() { throw new RuntimeException; }
1: function y() { z(); }
2: function x() { y(); }
>>> hist --tail 2
3: x()
4: wtf
>>>

Searching history

Use the --grep option to filter your history.

>>> hist --grep wtf
4: wtf
>>>

Use -i to do a case-insensitive search, and -v to show only lines which don’t match the search pattern.

>>> hist --grep WTF -i -v
0: function z() { throw new RuntimeException; }
1: function y() { z(); }
2: function x() { y(); }
3: x()
>>>

The --grep search pattern can be a Perl-compatible regular expression as well.

>>> hist --grep /\{.*\}/
0: function z() { throw new RuntimeException; }
1: function y() { z(); }
2: function x() { y(); }
>>>

Replaying history

Replay your history with the --replay option. This works best when combined with --show, --head, --tail and --grep.

>>> hist --head 3 --replay
Replaying 3 lines of history
-->  function z() { throw new RuntimeException; }
-->  function y() { z(); }
-->  function x() { y(); }
>>> function_exists('x')
=> true
>>>

Saving history

Save your PsySH history to a local file with the --save FILENAME option. You can combine this with --show, --head, --tail and --grep options to limit the slice of history saved.

>>> hist --head 3 --save history.txt
Saving history in history.txt...
History saved.
>>>

Clearing history

Clear your history with the --clear option.

>>> hist --clear
History cleared.
>>> hist
>>>