-
Notifications
You must be signed in to change notification settings - Fork 8
/
tutorial_hist.html
852 lines (811 loc) · 67.9 KB
/
tutorial_hist.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
<!doctype html>
<html class="no-js" lang="en" data-content_root="./">
<head><meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<meta name="color-scheme" content="light dark"><meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" /><link rel="next" title="Tutorial: Macros" href="tutorial_macros.html" /><link rel="prev" title="Tutorial" href="tutorial.html" />
<link rel="shortcut icon" href="_static/magic_conch.ico"/><!-- Generated with Sphinx 7.3.7 and Furo 2024.01.29 -->
<title>Tutorial: History - xonsh 0.16.0 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?v=135e06be" />
<link rel="stylesheet" type="text/css" href="_static/graphviz.css?v=fd3f3429" />
<link rel="stylesheet" type="text/css" href="_static/custom.css?v=c8b63bf6" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo-extensions.css?v=36a5483c" />
<style>
body {
--color-code-background: #eeffcc;
--color-code-foreground: black;
}
@media not print {
body[data-theme="dark"] {
--color-code-background: #202020;
--color-code-foreground: #d0d0d0;
}
@media (prefers-color-scheme: dark) {
body:not([data-theme="light"]) {
--color-code-background: #202020;
--color-code-foreground: #d0d0d0;
}
}
}
</style></head>
<body>
<script>
document.body.dataset.theme = localStorage.getItem("theme") || "auto";
</script>
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<symbol id="svg-toc" viewBox="0 0 24 24">
<title>Contents</title>
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 1024 1024">
<path d="M408 442h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm-8 204c0 4.4 3.6 8 8 8h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56zm504-486H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 632H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM115.4 518.9L271.7 642c5.8 4.6 14.4.5 14.4-6.9V388.9c0-7.4-8.5-11.5-14.4-6.9L115.4 505.1a8.74 8.74 0 0 0 0 13.8z"/>
</svg>
</symbol>
<symbol id="svg-menu" viewBox="0 0 24 24">
<title>Menu</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-menu">
<line x1="3" y1="12" x2="21" y2="12"></line>
<line x1="3" y1="6" x2="21" y2="6"></line>
<line x1="3" y1="18" x2="21" y2="18"></line>
</svg>
</symbol>
<symbol id="svg-arrow-right" viewBox="0 0 24 24">
<title>Expand</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-chevron-right">
<polyline points="9 18 15 12 9 6"></polyline>
</svg>
</symbol>
<symbol id="svg-sun" viewBox="0 0 24 24">
<title>Light mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather-sun">
<circle cx="12" cy="12" r="5"></circle>
<line x1="12" y1="1" x2="12" y2="3"></line>
<line x1="12" y1="21" x2="12" y2="23"></line>
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
<line x1="1" y1="12" x2="3" y2="12"></line>
<line x1="21" y1="12" x2="23" y2="12"></line>
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
</svg>
</symbol>
<symbol id="svg-moon" viewBox="0 0 24 24">
<title>Dark mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-moon">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z" />
</svg>
</symbol>
<symbol id="svg-sun-half" viewBox="0 0 24 24">
<title>Auto light/dark mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-shadow">
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
<circle cx="12" cy="12" r="9" />
<path d="M13 12h5" />
<path d="M13 15h4" />
<path d="M13 18h1" />
<path d="M13 9h4" />
<path d="M13 6h1" />
</svg>
</symbol>
</svg>
<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation">
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc">
<label class="overlay sidebar-overlay" for="__navigation">
<div class="visually-hidden">Hide navigation sidebar</div>
</label>
<label class="overlay toc-overlay" for="__toc">
<div class="visually-hidden">Hide table of contents sidebar</div>
</label>
<div class="page">
<header class="mobile-header">
<div class="header-left">
<label class="nav-overlay-icon" for="__navigation">
<div class="visually-hidden">Toggle site navigation sidebar</div>
<i class="icon"><svg><use href="#svg-menu"></use></svg></i>
</label>
</div>
<div class="header-center">
<a href="contents.html"><div class="brand">xonsh 0.16.0 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
<button class="theme-toggle">
<div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
<svg class="theme-icon-when-auto"><use href="#svg-sun-half"></use></svg>
<svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
<svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
</button>
</div>
<label class="toc-overlay-icon toc-header-icon" for="__toc">
<div class="visually-hidden">Toggle table of contents sidebar</div>
<i class="icon"><svg><use href="#svg-toc"></use></svg></i>
</label>
</div>
</header>
<aside class="sidebar-drawer">
<div class="sidebar-container">
<div class="sidebar-sticky"><a class="sidebar-brand" href="contents.html">
<div class="sidebar-logo-container">
<img class="sidebar-logo" src="_static/ascii_conch_part_transparent_tight.png" alt="Logo"/>
</div>
<span class="sidebar-brand-text">xonsh 0.16.0 documentation</span>
</a><form class="sidebar-search-container" method="get" action="search.html" role="search">
<input class="sidebar-search" placeholder="Search" name="q" aria-label="Search">
<input type="hidden" name="check_keywords" value="yes">
<input type="hidden" name="area" value="default">
</form>
<div id="searchbox"></div><div class="sidebar-scroll"><div class="sidebar-tree">
<ul>
<li class="toctree-l1"><a class="reference internal" href="packages.html">Package Manager</a></li>
<li class="toctree-l1"><a class="reference internal" href="appimage.html">AppImage</a></li>
<li class="toctree-l1"><a class="reference internal" href="containers.html">Docker container</a></li>
</ul>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="tutorial.html">Tutorial</a></li>
<li class="toctree-l1 current current-page"><a class="current reference internal" href="#">Tutorial: History</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial_macros.html">Tutorial: Macros</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial_xontrib.html">Tutorial: Extensions (Xontribs)</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial_xonsh_projects.html">Tutorial: Xonsh Projects</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial_events.html">Tutorial: Events</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial_completers.html">Tutorial: Programmable Tab-Completion</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial_history_backend.html">Tutorial: Write Your Own History Backend</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial_subproc_strings.html">Tutorial: Subprocess Strings</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial_ptk.html">Tutorial: <code class="docutils literal notranslate"><span class="pre">prompt_toolkit</span></code> custom keybindings</a></li>
<li class="toctree-l1"><a class="reference internal" href="bash_to_xsh.html">Bash to Xonsh Translation Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="editors.html">Editor and IDE Support</a></li>
<li class="toctree-l1"><a class="reference internal" href="subproc_types.html">Subprocess Types Table</a></li>
<li class="toctree-l1"><a class="reference internal" href="python_virtual_environments.html">Python Virtual Environments</a></li>
<li class="toctree-l1"><a class="reference internal" href="keyboard_shortcuts.html">Keyboard Shortcuts</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="xonshrc.html">Run Control File</a></li>
<li class="toctree-l1"><a class="reference internal" href="customization.html">Updating and customizing xonsh</a></li>
<li class="toctree-l1"><a class="reference internal" href="envvars.html">Environment Variables</a></li>
<li class="toctree-l1"><a class="reference internal" href="aliases.html">Built-in Aliases</a></li>
<li class="toctree-l1"><a class="reference internal" href="events.html">Core Events</a></li>
<li class="toctree-l1"><a class="reference internal" href="platform-issues.html">Platform-specific tips and tricks</a></li>
</ul>
<ul>
<li class="toctree-l1 has-children"><a class="reference internal" href="api/index.html">Xonsh API</a><input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" role="switch" type="checkbox"/><label for="toctree-checkbox-1"><div class="visually-hidden">Toggle navigation of Xonsh API</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/lang/xonsh.lexer.html">xonsh.lexer</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/lang/xonsh.parser.html">xonsh.parser</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/lang/xonsh.ast.html">xonsh.ast</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/lang/xonsh.execer.html">xonsh.execer</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/lang/xonsh.imphooks.html">xonsh.imphooks</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/cmd/xonsh.built_ins.html">xonsh.built_ins</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/cmd/xonsh.environ.html">xonsh.environ</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/cmd/xonsh.aliases.html">xonsh.aliases</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/cmd/xonsh.dirstack.html">xonsh.dirstack</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/cmd/xonsh.jobs.html">xonsh.jobs</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="api/_autosummary/cmd/xonsh.procs.html">xonsh.procs</a><input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" role="switch" type="checkbox"/><label for="toctree-checkbox-2"><div class="visually-hidden">Toggle navigation of xonsh.procs</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.procs.pipelines.html">xonsh.procs.pipelines</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.procs.posix.html">xonsh.procs.posix</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.procs.proxies.html">xonsh.procs.proxies</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.procs.readers.html">xonsh.procs.readers</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.procs.specs.html">xonsh.procs.specs</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/cmd/xonsh.inspectors.html">xonsh.inspectors</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="api/_autosummary/cmd/xonsh.history.html">xonsh.history</a><input class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" role="switch" type="checkbox"/><label for="toctree-checkbox-3"><div class="visually-hidden">Toggle navigation of xonsh.history</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.history.base.html">xonsh.history.base</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.history.dummy.html">xonsh.history.dummy</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.history.json.html">xonsh.history.json</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.history.main.html">xonsh.history.main</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.history.sqlite.html">xonsh.history.sqlite</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/cmd/xonsh.completer.html">xonsh.completer</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="api/_autosummary/cmd/xonsh.completers.html">xonsh.completers</a><input class="toctree-checkbox" id="toctree-checkbox-4" name="toctree-checkbox-4" role="switch" type="checkbox"/><label for="toctree-checkbox-4"><div class="visually-hidden">Toggle navigation of xonsh.completers</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.completers.base.html">xonsh.completers.base</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.completers.bash.html">xonsh.completers.bash</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.completers.bash_completion.html">xonsh.completers.bash_completion</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.completers.commands.html">xonsh.completers.commands</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.completers.completer.html">xonsh.completers.completer</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.completers.dirs.html">xonsh.completers.dirs</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.completers.environment.html">xonsh.completers.environment</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.completers.imports.html">xonsh.completers.imports</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.completers.init.html">xonsh.completers.init</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.completers.man.html">xonsh.completers.man</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.completers.path.html">xonsh.completers.path</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.completers.python.html">xonsh.completers.python</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.completers.tools.html">xonsh.completers.tools</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="api/_autosummary/cmd/xonsh.prompt.html">xonsh.prompt</a><input class="toctree-checkbox" id="toctree-checkbox-5" name="toctree-checkbox-5" role="switch" type="checkbox"/><label for="toctree-checkbox-5"><div class="visually-hidden">Toggle navigation of xonsh.prompt</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.prompt.base.html">xonsh.prompt.base</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.prompt.cwd.html">xonsh.prompt.cwd</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.prompt.env.html">xonsh.prompt.env</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.prompt.gitstatus.html">xonsh.prompt.gitstatus</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.prompt.job.html">xonsh.prompt.job</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.prompt.times.html">xonsh.prompt.times</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.prompt.vc.html">xonsh.prompt.vc</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/cmd/xonsh.shell.html">xonsh.shell</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/cmd/xonsh.base_shell.html">xonsh.base_shell</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/cmd/xonsh.readline_shell.html">xonsh.readline_shell</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="api/_autosummary/cmd/xonsh.ptk_shell.html">xonsh.ptk_shell</a><input class="toctree-checkbox" id="toctree-checkbox-6" name="toctree-checkbox-6" role="switch" type="checkbox"/><label for="toctree-checkbox-6"><div class="visually-hidden">Toggle navigation of xonsh.ptk_shell</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.ptk_shell.completer.html">xonsh.ptk_shell.completer</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.ptk_shell.formatter.html">xonsh.ptk_shell.formatter</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.ptk_shell.history.html">xonsh.ptk_shell.history</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.ptk_shell.key_bindings.html">xonsh.ptk_shell.key_bindings</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.ptk_shell.shell.html">xonsh.ptk_shell.shell</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.ptk_shell.updator.html">xonsh.ptk_shell.updator</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/cmd/xonsh.pretty.html">xonsh.pretty</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/cmd/xonsh.diff_history.html">xonsh.diff_history</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="api/_autosummary/cmd/xonsh.xoreutils.html">xonsh.xoreutils</a><input class="toctree-checkbox" id="toctree-checkbox-7" name="toctree-checkbox-7" role="switch" type="checkbox"/><label for="toctree-checkbox-7"><div class="visually-hidden">Toggle navigation of xonsh.xoreutils</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.xoreutils.cat.html">xonsh.xoreutils.cat</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.xoreutils.echo.html">xonsh.xoreutils.echo</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.xoreutils.pwd.html">xonsh.xoreutils.pwd</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.xoreutils.tee.html">xonsh.xoreutils.tee</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.xoreutils.tty.html">xonsh.xoreutils.tty</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.xoreutils.ulimit.html">xonsh.xoreutils.ulimit</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.xoreutils.umask.html">xonsh.xoreutils.umask</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.xoreutils.uname.html">xonsh.xoreutils.uname</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.xoreutils.uptime.html">xonsh.xoreutils.uptime</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.xoreutils.util.html">xonsh.xoreutils.util</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.xoreutils.which.html">xonsh.xoreutils.which</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/cmd/xonsh.xoreutils.yes.html">xonsh.xoreutils.yes</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.events.html">xonsh.events</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="api/_autosummary/helpers/xonsh.lib.html">xonsh.lib</a><input class="toctree-checkbox" id="toctree-checkbox-8" name="toctree-checkbox-8" role="switch" type="checkbox"/><label for="toctree-checkbox-8"><div class="visually-hidden">Toggle navigation of xonsh.lib</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/helpers/xonsh.lib.collections.html">xonsh.lib.collections</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/helpers/xonsh.lib.itertools.html">xonsh.lib.itertools</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/helpers/xonsh.lib.modules.html">xonsh.lib.modules</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/helpers/xonsh.lib.os.html">xonsh.lib.os</a></li>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/helpers/xonsh.lib.subprocess.html">xonsh.lib.subprocess</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.tools.html">xonsh.tools</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.platform.html">xonsh.platform</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.jsonutils.html">xonsh.jsonutils</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.lazyjson.html">xonsh.lazyjson</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.lazyasd.html">xonsh.lazyasd</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.openpy.html">xonsh.openpy</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.foreign_shells.html">xonsh.foreign_shells</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.commands_cache.html">xonsh.commands_cache</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.tracer.html">xonsh.tracer</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.main.html">xonsh.main</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.color_tools.html">xonsh.color_tools</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.pyghooks.html">xonsh.pyghooks</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.dumb_shell.html">xonsh.dumb_shell</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.wizard.html">xonsh.wizard</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.xonfig.html">xonsh.xonfig</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.xontribs.html">xonsh.xontribs</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.codecache.html">xonsh.codecache</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/_autosummary/helpers/xonsh.contexts.html">xonsh.contexts</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="api/_autosummary/xontribs/xontrib.html">xontrib</a><input class="toctree-checkbox" id="toctree-checkbox-9" name="toctree-checkbox-9" role="switch" type="checkbox"/><label for="toctree-checkbox-9"><div class="visually-hidden">Toggle navigation of xontrib</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="api/_autosummary/xontribs/xontrib.coreutils.html">xontrib.coreutils</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="advanced_events.html">Advanced Events</a></li>
<li class="toctree-l1"><a class="reference internal" href="devguide.html">Developer’s Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="changelog.html">Xonsh Change Log</a></li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently Asked Questions</a></li>
<li class="toctree-l1"><a class="reference internal" href="todo.html">Wishlist & To-Dos</a></li>
</ul>
</div>
</div>
</div>
</div>
</aside>
<div class="main">
<div class="content">
<div class="article-container">
<a href="#" class="back-to-top muted-link">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12z"></path>
</svg>
<span>Back to top</span>
</a>
<div class="content-icon-container">
<div class="edit-this-page">
<a class="muted-link" href="https://github.com/xonsh/xonsh/edit/main/docs/tutorial_hist.rst" title="Edit this page">
<svg aria-hidden="true" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
<path d="M4 20h4l10.5 -10.5a1.5 1.5 0 0 0 -4 -4l-10.5 10.5v4" />
<line x1="13.5" y1="6.5" x2="17.5" y2="10.5" />
</svg>
<span class="visually-hidden">Edit this page</span>
</a>
</div><div class="theme-toggle-container theme-toggle-content">
<button class="theme-toggle">
<div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
<svg class="theme-icon-when-auto"><use href="#svg-sun-half"></use></svg>
<svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
<svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
</button>
</div>
<label class="toc-overlay-icon toc-content-icon" for="__toc">
<div class="visually-hidden">Toggle table of contents sidebar</div>
<i class="icon"><svg><use href="#svg-toc"></use></svg></i>
</label>
</div>
<article role="main">
<section id="tutorial-history">
<span id="tutorial-hist"></span><h1>Tutorial: History<a class="headerlink" href="#tutorial-history" title="Link to this heading">¶</a></h1>
<p>Import your best Leonard Nimoy documentary voice and get ready for the xonsh tutorial
on <code class="docutils literal notranslate"><span class="pre">history</span></code>.</p>
<section id="how-is-xonsh-history-different">
<h2>How is xonsh history different?<a class="headerlink" href="#how-is-xonsh-history-different" title="Link to this heading">¶</a></h2>
<p>Most shells - bash foremost among them - think of history as a linear sequence of
past commands that have been entered into <em>the</em> terminal. This is saved when <em>the</em>
shell exits, and loaded when <em>the</em> new shell starts. But this is no longer
how the world works.</p>
<p>The world is a messy, asynchronous place. We usually have at least as many terminals
(and shells) open at a time as we can practically handle - and probably even more!
In xonsh, history acknowledges that this is the case. Instead of a single history
file of inputs, xonsh implements a collection of JSON-formatted history files that
can be thought of as having the following structure:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">{</span><span class="s1">'env'</span><span class="p">:</span> <span class="p">{</span><span class="o">...</span><span class="p">},</span> <span class="c1"># Environment that xonsh was started with</span>
<span class="s1">'sessionid'</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="c1"># UUID4 for the session</span>
<span class="s1">'ts'</span><span class="p">:</span> <span class="p">[</span><span class="n">start</span><span class="p">,</span> <span class="n">stop</span><span class="p">],</span> <span class="c1"># start and stop timestamps for session [s since epoch]</span>
<span class="s1">'locked'</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span> <span class="c1"># boolean for whether the file is in use or not</span>
<span class="s1">'cmds'</span><span class="p">:</span> <span class="p">[</span> <span class="c1"># array of commands</span>
<span class="p">{</span><span class="s1">'inp'</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="c1"># input command</span>
<span class="s1">'ts'</span><span class="p">:</span> <span class="p">[</span><span class="n">start</span><span class="p">,</span> <span class="n">stop</span><span class="p">],</span> <span class="c1"># timestamps for the command</span>
<span class="s1">'rtn'</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="c1"># command return code</span>
<span class="s1">'out'</span> <span class="nb">str</span><span class="p">,</span> <span class="c1"># stdout and stderr of command, for subproc commands</span>
<span class="c1"># this is only available select OSs. Off by default.</span>
<span class="p">},</span>
<span class="o">...</span>
<span class="p">],</span>
<span class="p">}</span>
</pre></div>
</div>
<p>This rich set of data allows xonsh to do much more advanced inspection and manipulation.
The sessionid, locking, and one-file-per-shell ideas allow for there to be multiple
instances of xonsh running at the same time without competing and overwriting
history constantly. Of course, an external process deleting a history file can still
cause problems. But hey, the world and the file system are messy places to be!</p>
</section>
<section id="why-have-rich-history">
<h2>Why have rich history?<a class="headerlink" href="#why-have-rich-history" title="Link to this heading">¶</a></h2>
<p>Often by the time you know that you need a historical artifact, it is already too
late. You can’t remember:</p>
<ul class="simple">
<li><p>the input exactly,</p></li>
<li><p>you think that you remember the output but when you rerun the command what you get
now seems somehow different,</p></li>
<li><p>who knows what the return code was,</p></li>
<li><p>and whatever command you ran right before is now lost in the mists of time!</p></li>
</ul>
<p>So the reasons for having rich history are debugging and reproducibility. Xonsh takes the
guess-work out of the past. There is even the ability to store all of stdout, though this
is turned off by default.
If history was just a static file, it would be more like a server log than a traditional
history file.</p>
</section>
<section id="history-command">
<h2><code class="docutils literal notranslate"><span class="pre">history</span></code> command<a class="headerlink" href="#history-command" title="Link to this heading">¶</a></h2>
<p>All xonsh history inspection and manipulation goes through the top-level <code class="docutils literal notranslate"><span class="pre">history</span></code>
alias or command. If you run this without an <code class="docutils literal notranslate"><span class="pre">action</span></code> argument, it will default to
the <code class="docutils literal notranslate"><span class="pre">show</span></code> action, see below.</p>
<div class="highlight-xonshcon notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">history</span>
</pre></div>
</div>
<p>Also note that the history object itself can be accessed through the xonsh built-in variable
<code class="docutils literal notranslate"><span class="pre">__xonsh__.history</span></code>.</p>
</section>
<section id="show-action">
<h2><code class="docutils literal notranslate"><span class="pre">show</span></code> action<a class="headerlink" href="#show-action" title="Link to this heading">¶</a></h2>
<p>The <code class="docutils literal notranslate"><span class="pre">show</span></code> action for the history command mimics what the <code class="docutils literal notranslate"><span class="pre">history</span></code> command does
in other shells. Namely, it displays the past inputs along with the index of these
inputs. This operates on the current session by default and is the default action for
the <code class="docutils literal notranslate"><span class="pre">history</span></code> command. For example,</p>
<div class="highlight-xonshcon notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="mi">1</span> <span class="o">+</span> <span class="mi">1</span>
<span class="go">2</span>
<span class="gp">>>></span> <span class="n">history</span> <span class="n">show</span>
<span class="go"> 0 1 + 1</span>
<span class="gp">>>></span> <span class="n">history</span>
<span class="go"> 0 1 + 1</span>
<span class="go"> 1 history show</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>History is zero-indexed; this is still Python.</p>
</div>
<p>The show command can also optionally take as an argument any integer (to just display
that history index) or a slice (to display a range of history indices). To display
only the even indices from above, you could write:</p>
<div class="highlight-xonshcon notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">history</span> <span class="n">show</span> <span class="p">::</span><span class="mi">2</span>
<span class="go"> 0 1 + 1</span>
<span class="go"> 2 history</span>
</pre></div>
</div>
<p>One can also use many slice/integer arguments to get different portions of history</p>
<p>After <code class="docutils literal notranslate"><span class="pre">show</span></code> an option that indicates which history to be returned can be used:</p>
<p><code class="docutils literal notranslate"><span class="pre">xonsh</span></code> displays the past inputs from all
valid json files found in <code class="docutils literal notranslate"><span class="pre">XONSH_DATA_DIR</span></code>. As such, this operates on all
past and present xonsh sessions.</p>
<p><code class="docutils literal notranslate"><span class="pre">all</span></code> is an alias for <code class="docutils literal notranslate"><span class="pre">xonsh</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">zsh</span></code> will display all history from the history file specified
by the <code class="docutils literal notranslate"><span class="pre">HISTFILE</span></code> environmental variable in zsh.
By default this is <code class="docutils literal notranslate"><span class="pre">~/.zsh_history</span></code>. However, they can also be respectively
specified in both <code class="docutils literal notranslate"><span class="pre">~/.zshrc</span></code> and <code class="docutils literal notranslate"><span class="pre">~/.zprofile</span></code>. Xonsh will parse these files
(rc file first) to check if <code class="docutils literal notranslate"><span class="pre">HISTFILE</span></code> has been set.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">bash</span></code> action will display all history from the history file specified
by the <code class="docutils literal notranslate"><span class="pre">HISTFILE</span></code> environmental variable in bash.
By default this is <code class="docutils literal notranslate"><span class="pre">~/.bash_history</span></code>. However, they can also be respectively
specified in both <code class="docutils literal notranslate"><span class="pre">~/.bashrc</span></code> and <code class="docutils literal notranslate"><span class="pre">~/.bash_profile</span></code>. Xonsh will parse these
files (rc file first) to check if <code class="docutils literal notranslate"><span class="pre">HISTFILE</span></code> has been set.</p>
<p><code class="docutils literal notranslate"><span class="pre">show</span></code> also accepts other options for more control over history output,
the <code class="docutils literal notranslate"><span class="pre">-n</span></code> option is used to enumerate the commands,
the <code class="docutils literal notranslate"><span class="pre">-t</span></code> option is used to show the timestamps,
and more, try out <code class="docutils literal notranslate"><span class="pre">history</span> <span class="pre">show</span> <span class="pre">--help</span></code> for a list of options.</p>
</section>
<section id="id-action">
<h2><code class="docutils literal notranslate"><span class="pre">id</span></code> action<a class="headerlink" href="#id-action" title="Link to this heading">¶</a></h2>
<p>Each xonsh history has its own universally unique <code class="docutils literal notranslate"><span class="pre">sessionid</span></code>. The <code class="docutils literal notranslate"><span class="pre">id</span></code> action is how you
display this identified. For instance,</p>
<div class="highlight-xonshcon notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">history</span> <span class="nb">id</span>
<span class="go">ace97177-f8dd-4a8d-8a91-a98ffd0b3d17</span>
</pre></div>
</div>
</section>
<section id="file-action">
<h2><code class="docutils literal notranslate"><span class="pre">file</span></code> action<a class="headerlink" href="#file-action" title="Link to this heading">¶</a></h2>
<p>Similarly, each xonsh history has its own file associated with it. The <code class="docutils literal notranslate"><span class="pre">file</span></code> action is
how you display the path to this file. For example,</p>
<div class="highlight-xonshcon notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">history</span> <span class="n">file</span>
<span class="go">/home/me/.local/share/xonsh/xonsh-ace97177-f8dd-4a8d-8a91-a98ffd0b3d17.json</span>
</pre></div>
</div>
<p>Note that by these files are stored in <code class="docutils literal notranslate"><span class="pre">$XONSH_DATA_DIR</span></code> environment variable. This
is, by default, set to the <code class="docutils literal notranslate"><span class="pre">xonsh</span></code> dir inside of the free desktop standards
<code class="docutils literal notranslate"><span class="pre">$XDG_DATA_HOME</span></code> environment variable. See
<a class="reference external" href="http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html">this page</a> for
more details.</p>
</section>
<section id="info-action">
<h2><code class="docutils literal notranslate"><span class="pre">info</span></code> action<a class="headerlink" href="#info-action" title="Link to this heading">¶</a></h2>
<p>The info action combines the <code class="docutils literal notranslate"><span class="pre">id</span></code> and <code class="docutils literal notranslate"><span class="pre">file</span></code> actions as well as adds some additional
information about the current state of the history. By default, this prints a key-value
series of lines. However, it can also return a JSON formatted string.</p>
<div class="highlight-xonshcon notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">history</span> <span class="n">info</span>
<span class="go">sessionid: ace97177-f8dd-4a8d-8a91-a98ffd0b3d17</span>
<span class="go">filename: /home/scopatz/.local/share/xonsh/xonsh-ace97177-f8dd-4a8d-8a91-a98ffd0b3d17.json</span>
<span class="go">length: 6</span>
<span class="go">buffersize: 100</span>
<span class="go">bufferlength: 6</span>
</pre></div>
</div>
<div class="highlight-xonshcon notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">history</span> <span class="n">info</span> <span class="o">--</span><span class="n">json</span>
<span class="go">{"sessionid": "ace97177-f8dd-4a8d-8a91-a98ffd0b3d17",</span>
<span class="go"> "filename": "/home/scopatz/.local/share/xonsh/xonsh-ace97177-f8dd-4a8d-8a91-a98ffd0b3d17.json",</span>
<span class="go"> "length": 7, "buffersize": 100, "bufferlength": 7}</span>
</pre></div>
</div>
</section>
<section id="diff-action">
<h2><code class="docutils literal notranslate"><span class="pre">diff</span></code> action<a class="headerlink" href="#diff-action" title="Link to this heading">¶</a></h2>
<p>Between any two history files, we can run the <code class="docutils literal notranslate"><span class="pre">diff</span></code> action. This does more that a simple line
diff that you might generate with the unix <code class="docutils literal notranslate"><span class="pre">diff</span></code> command. (If you want a line diff, just
use the unix command!) Instead this takes advantage of the fact that we know we have xonsh
history files to do a more sophisticated diff on the environment, input, output (if available),
and return values. Of course, the histories inputs should be ‘sufficiently similar’ if the diff
is to be meaningful. However, they don’t need to be exactly the same.</p>
<p>The diff action has one major option, <code class="docutils literal notranslate"><span class="pre">-v</span></code> or <code class="docutils literal notranslate"><span class="pre">--verbose</span></code>. This basically says whether the
diff should go into as much detail as possible or only pick out the relevant pieces. Diffing
the new and next examples, we see the diff looks like:</p>
<div class="highlight-xonshcon notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">history</span> <span class="n">diff</span> <span class="o">~/</span><span class="n">new</span><span class="o">.</span><span class="n">json</span> <span class="o">~/</span><span class="nb">next</span><span class="o">.</span><span class="n">json</span>
<span class="go">--- /home/scopatz/new.json (35712b6f-4b15-4ef9-8ce3-b4c781601bc2) [unlocked]</span>
<span class="go">started: 2015-08-27 15:13:44.873869 stopped: 2015-08-27 15:13:44.918903 runtime: 0:00:00.045034</span>
<span class="go">+++ /home/scopatz/next.json (70d7186e-3eb9-4b1c-8f82-45bb8a1b7967) [unlocked]</span>
<span class="go">started: 2015-08-27 15:15:09.423932 stopped: 2015-08-27 15:15:09.619098 runtime: 0:00:00.195166</span>
<span class="go">Environment</span>
<span class="go">-----------</span>
<span class="go">'PATH' is in both, but differs</span>
<span class="go">- /home/scopatz/.local/bin:/home/scopatz/sandbox/bin:/home/scopatz/miniconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/scopatz/origen22/code/</span>
<span class="go">+ /home/scopatz/.local/bin:/home/scopatz/sandbox/bin:/home/scopatz/miniconda3/bin:/home/scopatz/.local/bin:/home/scopatz/sandbox/bin:/home/scopatz/miniconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/scopatz/origen22/code/:/home/scopatz/origen22/code/</span>
<span class="go">'SHLVL' is in both, but differs</span>
<span class="go">- 2</span>
<span class="go">+ 3</span>
<span class="go">'XONSH_INTERACTIVE' is in both, but differs</span>
<span class="go">- True</span>
<span class="go">+ False</span>
<span class="go">These vars are only in 70d7186e-3eb9-4b1c-8f82-45bb8a1b7967: {'OLDPWD'}</span>
<span class="go">Commands</span>
<span class="go">--------</span>
<span class="go">cmd #4 in 35712b6f-4b15-4ef9-8ce3-b4c781601bc2 input is the same as</span>
<span class="go">cmd #4 in 70d7186e-3eb9-4b1c-8f82-45bb8a1b7967, but output differs:</span>
<span class="go">Outputs differ</span>
<span class="go">- 2 10</span>
<span class="go">+ 2 7 10</span>
<span class="go">cmd #5 in 35712b6f-4b15-4ef9-8ce3-b4c781601bc2 input is the same as</span>
<span class="go">cmd #5 in 70d7186e-3eb9-4b1c-8f82-45bb8a1b7967, but output differs:</span>
<span class="go">Outputs differ</span>
<span class="go">- /home/scopatz/new.json</span>
<span class="go">+ /home/scopatz/next.json</span>
</pre></div>
</div>
<p>As can be seen, the diff has three sections.</p>
<ol class="arabic simple">
<li><p><strong>The header</strong> describes the meta-information about the histories, such as
their file names, sessionids, and time stamps.</p></li>
<li><p><strong>The environment</strong> section describes the differences in the environment
when the histories were started.</p></li>
<li><p><strong>The commands</strong> list this differences in the command themselves.</p></li>
</ol>
<p>For the commands, the input sequences are diff’d first, prior to the outputs
being compared. In a terminal, this will appear in color, with the first history
in red and the second one in green.</p>
</section>
<section id="flush-action">
<h2><code class="docutils literal notranslate"><span class="pre">flush</span></code> action<a class="headerlink" href="#flush-action" title="Link to this heading">¶</a></h2>
<p>Normally, the history entries are kept in memory and are only saved to disk once
the in-memory buffer gets full. This is in order to reduce unnecessary I/O and to
keep session history free from noise from other sessions. Sometimes, however, it
may be useful to share entries between shell sessions. In such a case, one can use
the <code class="docutils literal notranslate"><span class="pre">flush</span></code> action to immediately save the session history to disk and make it
accessible from other shell sessions.</p>
</section>
<section id="pull-action">
<h2><code class="docutils literal notranslate"><span class="pre">pull</span></code> action<a class="headerlink" href="#pull-action" title="Link to this heading">¶</a></h2>
<p>Tries to pull the history from parallel sessions and add to the current session.</p>
<p>For example if there are two parallel terminal windows the run of <code class="docutils literal notranslate"><span class="pre">history</span> <span class="pre">pull</span></code>
command from the second terminal window will get the commands from the first terminal.</p>
</section>
<section id="clear-action">
<h2><code class="docutils literal notranslate"><span class="pre">clear</span></code> action<a class="headerlink" href="#clear-action" title="Link to this heading">¶</a></h2>
<p>Deletes the history from the current session up until this point. Later commands
will still be saved.</p>
</section>
<section id="off-action">
<h2><code class="docutils literal notranslate"><span class="pre">off</span></code> action<a class="headerlink" href="#off-action" title="Link to this heading">¶</a></h2>
<p>Deletes the history from the current session and turns off history saving for the
rest of the session. Only session metadata will be saved, not commands or output.</p>
</section>
<section id="on-action">
<h2><code class="docutils literal notranslate"><span class="pre">on</span></code> action<a class="headerlink" href="#on-action" title="Link to this heading">¶</a></h2>
<p>Turns history saving back on. Previous commands won’t be saved, but future
commands will be.</p>
</section>
<section id="gc-action">
<h2><code class="docutils literal notranslate"><span class="pre">gc</span></code> action<a class="headerlink" href="#gc-action" title="Link to this heading">¶</a></h2>
<p>Last, but certainly not least, the <code class="docutils literal notranslate"><span class="pre">gc</span></code> action is a manual hook into executing
history garbage control. Since history has the potential for a lot of information
to be stored, it is necessary to be able to clean out the cache every once in a
while.</p>
<p>Garbage control is launched automatically for every xonsh thread, but runs in the
a background thread. The garbage collector only operates on unlocked history files.
The action here allows you to manually start a new garbage collector, possibly with
different criteria.</p>
<p>Normally, the garbage collector uses the environment variable <code class="docutils literal notranslate"><span class="pre">$XONSH_HISTORY_SIZE</span></code>
to determine the size and units of what should be allowed to remain on disk. By default,
this is <code class="docutils literal notranslate"><span class="pre">(8128,</span> <span class="pre">'commands')</span></code>. This variable is usually a tuple or list of a
number and a string, as seen here. However, you can also use a string with the same
information, e.g. <code class="docutils literal notranslate"><span class="pre">'8128</span> <span class="pre">commands'</span></code>. On the command line, though, you just pass in
two arguments to the <code class="docutils literal notranslate"><span class="pre">--size</span></code> option, a la <code class="docutils literal notranslate"><span class="pre">--size</span> <span class="pre">8128</span> <span class="pre">commands</span></code>.</p>
<p>The garbage collector accepts four canonical units:</p>
<ol class="arabic simple">
<li><dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">'commands'</span></code> is for limiting the number of past commands executed in the</dt><dd><p>history files,</p>
</dd>
</dl>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">'files'</span></code> is for specifying the total number of history files to keep,</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">'s'</span></code> is for the number of seconds in the past that are allowed - which
is effectively a timeout of the history files, and</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">'b'</span></code> is for the number of bytes that are allowed on the file system
for all history files to collectively consume.</p></li>
</ol>
<p>However, other units, aliases, and appropriate conversion functions have been implemented.
This makes it easier to garbage collect based on human-friendly values.</p>
<p><strong>GC Aliases:</strong></p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">{</span><span class="s1">'commands'</span><span class="p">:</span> <span class="p">[</span><span class="s1">''</span><span class="p">,</span> <span class="s1">'c'</span><span class="p">,</span> <span class="s1">'cmd'</span><span class="p">,</span> <span class="s1">'cmds'</span><span class="p">,</span> <span class="s1">'command'</span><span class="p">],</span>
<span class="s1">'files'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'f'</span><span class="p">],</span>
<span class="s1">'s'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'sec'</span><span class="p">,</span> <span class="s1">'second'</span><span class="p">,</span> <span class="s1">'seconds'</span><span class="p">,</span> <span class="s1">'m'</span><span class="p">,</span> <span class="s1">'min'</span><span class="p">,</span> <span class="s1">'mins'</span><span class="p">,</span> <span class="s1">'h'</span><span class="p">,</span> <span class="s1">'hr'</span><span class="p">,</span> <span class="s1">'hour'</span><span class="p">,</span> <span class="s1">'hours'</span><span class="p">,</span>
<span class="s1">'d'</span><span class="p">,</span> <span class="s1">'day'</span><span class="p">,</span> <span class="s1">'days'</span><span class="p">,</span> <span class="s1">'mon'</span><span class="p">,</span> <span class="s1">'month'</span><span class="p">,</span> <span class="s1">'months'</span><span class="p">,</span> <span class="s1">'y'</span><span class="p">,</span> <span class="s1">'yr'</span><span class="p">,</span> <span class="s1">'yrs'</span><span class="p">,</span> <span class="s1">'year'</span><span class="p">,</span> <span class="s1">'years'</span><span class="p">],</span>
<span class="s1">'b'</span><span class="p">:</span> <span class="p">[</span><span class="s1">'byte'</span><span class="p">,</span> <span class="s1">'bytes'</span><span class="p">,</span> <span class="s1">'kb'</span><span class="p">,</span> <span class="s1">'kilobyte'</span><span class="p">,</span> <span class="s1">'kilobytes'</span><span class="p">,</span> <span class="s1">'mb'</span><span class="p">,</span> <span class="s1">'meg'</span><span class="p">,</span> <span class="s1">'megs'</span><span class="p">,</span> <span class="s1">'megabyte'</span><span class="p">,</span>
<span class="s1">'megabytes'</span><span class="p">,</span> <span class="s1">'gb'</span><span class="p">,</span> <span class="s1">'gig'</span><span class="p">,</span> <span class="s1">'gigs'</span><span class="p">,</span> <span class="s1">'gigabyte'</span><span class="p">,</span> <span class="s1">'gigabytes'</span><span class="p">,</span> <span class="s1">'tb'</span><span class="p">,</span> <span class="s1">'terabyte'</span><span class="p">,</span>
<span class="s1">'terabytes'</span><span class="p">]</span>
<span class="p">}</span>
</pre></div>
</div>
<p>So all said and done, if you wanted to remove all history files older than a month,
you could run the following command:</p>
<div class="highlight-xonshcon notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">history</span> <span class="n">gc</span> <span class="o">--</span><span class="n">size</span> <span class="mi">1</span> <span class="n">month</span>
</pre></div>
</div>
</section>
<section id="history-indexing">
<h2>History Indexing<a class="headerlink" href="#history-indexing" title="Link to this heading">¶</a></h2>
<p>History object (<code class="docutils literal notranslate"><span class="pre">__xonsh__.history</span></code>) acts like a sequence that can be indexed in a special way
that adds extra functionality. At the moment only history from the
current session can be retrieved. Note that the most recent command
is the last item in history.</p>
<p>The index acts as a filter with two parts, command and argument,
separated by comma. Based on the type of each part different
filtering can be achieved,</p>
<dl class="simple">
<dt>for the command part:</dt><dd><ul class="simple">
<li><p>an int returns the command in that position.</p></li>
<li><p>a slice returns a list of commands.</p></li>
</ul>
</dd>
<dt>for the argument part:</dt><dd><ul class="simple">
<li><p>an int returns the argument of the command in that position.</p></li>
<li><p>a slice returns a part of the command based on the argument
position.</p></li>
</ul>
</dd>
</dl>
<p>The argument part of the filter can be omitted but the command part is
required.</p>
<p>Command arguments are separated by white space.</p>
<p>If the filtering produces only one result it is
returned as a string else a list of strings is returned.</p>
<p>examples:</p>
<div class="highlight-xonshcon notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">echo</span> <span class="n">mkdir</span> <span class="k">with</span><span class="o">/</span><span class="n">a</span><span class="o">/</span><span class="n">huge</span><span class="o">/</span><span class="n">name</span><span class="o">/</span>
<span class="go">mkdir with/a/huge/name</span>
<span class="gp">>>></span> <span class="n">__xonsh__</span><span class="o">.</span><span class="n">history</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="go">'with/a/huge/name/'</span>
<span class="gp">>>></span> <span class="n">__xonsh__</span><span class="o">.</span><span class="n">history</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">:]</span>
<span class="go">'mkdir with/a/huge/name'</span>
</pre></div>
</div>
</section>
<section id="exciting-technical-detail-lazy-json">
<h2>Exciting Technical Detail: Lazy JSON<a class="headerlink" href="#exciting-technical-detail-lazy-json" title="Link to this heading">¶</a></h2>
<p>So now you know how to inspect, run, and remove history. But what <em>is</em> a history file exactly?
While xonsh history files are JSON formatted, and they do have the structure indicated at the
top of the page, that isn’t their top-level structure. If you open one up, you’ll see a bunch
of hocus pocus before you get to anything real.</p>
<p>Xonsh has implemented a generic indexing system (sizes, offsets, etc)for JSON files that lives
inside of the file that it indexes. This is known as <code class="docutils literal notranslate"><span class="pre">LazyJSON</span></code> because it allows us to
only read in the parts of a file that we need. For garbage collecting based on the number
of commands, we can get this information from the index and don’t need to read in any of the
original data.</p>
<p>The best part about this is that it is totally generic. Feel free to use <code class="docutils literal notranslate"><span class="pre">xonsh.lazyjson</span></code>
yourself for things other than xonsh history! Of course, if you want to read in xonsh history,
you should probably use the module.</p>
</section>
<section id="exciting-technical-detail-teeing-and-pseudo-terminals">
<h2>Exciting Technical Detail: Teeing and Pseudo Terminals<a class="headerlink" href="#exciting-technical-detail-teeing-and-pseudo-terminals" title="Link to this heading">¶</a></h2>
<p>Xonsh is able to capture all stdout and stderr transparently and responsively. For aliases,
Python code, or xonsh code, this isn’t a big deal. It is easy to redirect information
flowing through <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code> and <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code>. For subprocess commands, this is
considerably harder. Capturing stdout during the session is disabled by default but can be
enabled by setting <code class="docutils literal notranslate"><span class="pre">$XONSH_CAPTURE_ALWAYS=True</span></code>. Storing stdout to the history backend
is disabled by default but can be enabled by setting <code class="docutils literal notranslate"><span class="pre">$XONSH_STORE_STDOUT=True</span></code>.</p>
<p>To be able to tee stdout and stderr and still have the terminal responsive, xonsh implements
its own teeing pseudo-terminal on top of the Python standard library <code class="docutils literal notranslate"><span class="pre">pty</span></code> module. You
can find this class in the <code class="docutils literal notranslate"><span class="pre">xonsh.teepty</span></code> module. Like with lazy JSON, this is independent
from other parts of xonsh and can be used on its own. If you find this useful in other areas,
please let us know!</p>
</section>
<section id="sqlite-history-backend">
<h2>Sqlite History Backend<a class="headerlink" href="#sqlite-history-backend" title="Link to this heading">¶</a></h2>
<p>Xonsh has a second built-in history backend powered by sqlite (other than
the JSON version mentioned all above in this tutorial). It shares the same
functionality as the JSON version in most ways, except it currently doesn’t
support the <code class="docutils literal notranslate"><span class="pre">history</span> <span class="pre">diff</span></code> action and does not store the output of commands,
as the json-backend does. E.g.
<cite>__xonsh__.history[-1].out</cite> will always be <cite>None</cite>.</p>
<p>The Sqlite history backend can provide a speed advantage in loading history
into a just-started xonsh session. The JSON history backend may need to read
potentially thousands of json files and the sqlite backend only reads one.
Note that this does not affect startup time, but the amount of time before
all history is available for searching.</p>
<p>To use sqlite history backend, set <code class="docutils literal notranslate"><span class="pre">$XONSH_HISTORY_BACKEND</span> <span class="pre">=</span> <span class="pre">'sqlite'</span></code> in
your <code class="docutils literal notranslate"><span class="pre">~/.xonshrc</span></code> file. To switch back to JSON version, remove this line,
or set it to <code class="docutils literal notranslate"><span class="pre">'json'</span></code>.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>SQLite history backend currently only supports <code class="docutils literal notranslate"><span class="pre">commands</span></code> as
the unit in <code class="docutils literal notranslate"><span class="pre">$XONSH_HISTORY_SIZE</span></code> in its garbage collection.</p>
</div>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>If you have <a class="reference external" href="https://pypi.python.org/pypi/sqlite-web">sqlite-web</a>
installed, you can read the history easily with command:
<code class="docutils literal notranslate"><span class="pre">sqlite_web</span> <span class="pre">@$(history</span> <span class="pre">file)</span></code>.</p>
</div>
</section>
<section id="fun-ideas-for-history-data">
<h2>Fun ideas for history data<a class="headerlink" href="#fun-ideas-for-history-data" title="Link to this heading">¶</a></h2>
<p>Now that we have all of this history data, it seems like what we have here is just the tip
of the iceberg! Here are some hopefully fun ideas that I think would be great to see
implemented:</p>
<ul class="simple">
<li><p>Basic statistic reports about command usage, timing, etc.,</p></li>
<li><p>Global statistics by collecting anonymized histories from many people,</p></li>
<li><p>MCMC-based tab-completer for inputs,</p></li>
<li><p>and many more!</p></li>
</ul>
<p>Let us know if you’d be interested in working on any of these, inside or outside of xonsh.</p>
</section>
</section>
</article>
</div>
<footer>
<div class="related-pages">
<a class="next-page" href="tutorial_macros.html">
<div class="page-info">
<div class="context">
<span>Next</span>
</div>
<div class="title">Tutorial: Macros</div>
</div>
<svg class="furo-related-icon"><use href="#svg-arrow-right"></use></svg>
</a>
<a class="prev-page" href="tutorial.html">
<svg class="furo-related-icon"><use href="#svg-arrow-right"></use></svg>
<div class="page-info">
<div class="context">
<span>Previous</span>
</div>
<div class="title">Tutorial</div>
</div>
</a>
</div>
<div class="bottom-of-page">
<div class="left-details">
<div class="copyright">
Copyright © 2015, Anthony Scopatz
</div>
Made with <a href="https://www.sphinx-doc.org/">Sphinx</a> and <a class="muted-link" href="https://pradyunsg.me">@pradyunsg</a>'s
<a href="https://github.com/pradyunsg/furo">Furo</a>
</div>
<div class="right-details">
</div>
</div>
</footer>
</div>
<aside class="toc-drawer">
<div class="toc-sticky toc-scroll">
<div class="toc-title-container">
<span class="toc-title">
On this page
</span>
</div>
<div class="toc-tree-container">
<div class="toc-tree">
<ul>
<li><a class="reference internal" href="#">Tutorial: History</a><ul>
<li><a class="reference internal" href="#how-is-xonsh-history-different">How is xonsh history different?</a></li>
<li><a class="reference internal" href="#why-have-rich-history">Why have rich history?</a></li>
<li><a class="reference internal" href="#history-command"><code class="docutils literal notranslate"><span class="pre">history</span></code> command</a></li>
<li><a class="reference internal" href="#show-action"><code class="docutils literal notranslate"><span class="pre">show</span></code> action</a></li>
<li><a class="reference internal" href="#id-action"><code class="docutils literal notranslate"><span class="pre">id</span></code> action</a></li>
<li><a class="reference internal" href="#file-action"><code class="docutils literal notranslate"><span class="pre">file</span></code> action</a></li>
<li><a class="reference internal" href="#info-action"><code class="docutils literal notranslate"><span class="pre">info</span></code> action</a></li>
<li><a class="reference internal" href="#diff-action"><code class="docutils literal notranslate"><span class="pre">diff</span></code> action</a></li>
<li><a class="reference internal" href="#flush-action"><code class="docutils literal notranslate"><span class="pre">flush</span></code> action</a></li>
<li><a class="reference internal" href="#pull-action"><code class="docutils literal notranslate"><span class="pre">pull</span></code> action</a></li>
<li><a class="reference internal" href="#clear-action"><code class="docutils literal notranslate"><span class="pre">clear</span></code> action</a></li>
<li><a class="reference internal" href="#off-action"><code class="docutils literal notranslate"><span class="pre">off</span></code> action</a></li>
<li><a class="reference internal" href="#on-action"><code class="docutils literal notranslate"><span class="pre">on</span></code> action</a></li>
<li><a class="reference internal" href="#gc-action"><code class="docutils literal notranslate"><span class="pre">gc</span></code> action</a></li>
<li><a class="reference internal" href="#history-indexing">History Indexing</a></li>
<li><a class="reference internal" href="#exciting-technical-detail-lazy-json">Exciting Technical Detail: Lazy JSON</a></li>
<li><a class="reference internal" href="#exciting-technical-detail-teeing-and-pseudo-terminals">Exciting Technical Detail: Teeing and Pseudo Terminals</a></li>
<li><a class="reference internal" href="#sqlite-history-backend">Sqlite History Backend</a></li>
<li><a class="reference internal" href="#fun-ideas-for-history-data">Fun ideas for history data</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</aside>
</div>
</div><script src="_static/documentation_options.js?v=ecbec2ee"></script>
<script src="_static/doctools.js?v=9a2dae69"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/scripts/furo.js?v=32e29ea5"></script>
<script src="_static/runthis-client.min.js?v=ad2a40d9"></script>
</body>
</html>