@@ -253,10 +253,10 @@ the readline history.
253
253
254
254
.. automethod :: cmd2.cmd2.Cmd.__init__
255
255
256
- ``cmd2 `` makes a third type of history access available with the `history ` command. Each time
257
- the user enters a command, ``cmd2 `` saves the input. The ` history ` command lets you do interesting
258
- things with that saved input. The examples to follow all assume that you have entered the
259
- following commands::
256
+ ``cmd2 `` makes a third type of history access available with the `` history ``
257
+ command. Each time the user enters a command, ``cmd2 `` saves the input. The
258
+ `` history `` command lets you do interesting things with that saved input. The
259
+ examples to follow all assume that you have entered the following commands::
260
260
261
261
(Cmd) alias create one !echo one
262
262
Alias 'one' created
@@ -267,36 +267,40 @@ following commands::
267
267
(Cmd) alias create four !echo four
268
268
Alias 'four' created
269
269
270
- In it's simplest form, the `history ` command displays previously entered commands. With no
271
- additional arguments, it displays all previously entered commands::
270
+ In it's simplest form, the ``history `` command displays previously entered
271
+ commands. With no additional arguments, it displays all previously entered
272
+ commands::
272
273
273
274
(Cmd) history
274
275
1 alias create one !echo one
275
276
2 alias create two !echo two
276
277
3 alias create three !echo three
277
278
4 alias create four !echo four
278
279
279
- If you give a positive integer as an argument, then it only displays the specified command::
280
+ If you give a positive integer as an argument, then it only displays the
281
+ specified command::
280
282
281
283
(Cmd) history 4
282
284
4 alias create four !echo four
283
285
284
- If you give a negative integer *N * as an argument, then it display the *Nth * last command.
285
- For example, if you give `-1 ` it will display the last command you entered. If you give `-2 `
286
- it will display the next to last command you entered, and so forth::
286
+ If you give a negative integer *N * as an argument, then it display the *Nth *
287
+ last command. For example, if you give ``-1 `` it will display the last command
288
+ you entered. If you give ``-2 `` it will display the next to last command you
289
+ entered, and so forth::
287
290
288
291
(Cmd) history -2
289
292
3 alias create three !echo three
290
293
291
- You can use a similar mechanism to display a range of commands. Simply give two command numbers
292
- separated by `.. ` or `: `, and you will see all commands between those two numbers::
294
+ You can use a similar mechanism to display a range of commands. Simply give two
295
+ command numbers separated by ``.. `` or ``: ``, and you will see all commands
296
+ between those two numbers::
293
297
294
298
(Cmd) history 2:3
295
299
2 alias create two !echo two
296
300
3 alias create three !echo three
297
301
298
- If you omit the first number, it will start at the beginning. If you omit the last number, it
299
- will continue to the end::
302
+ If you omit the first number, it will start at the beginning. If you omit the
303
+ last number, it will continue to the end::
300
304
301
305
(Cmd) history :2
302
306
1 alias create one !echo one
@@ -306,25 +310,26 @@ will continue to the end::
306
310
3 alias create three !echo three
307
311
4 alias create four !echo four
308
312
309
- You can use negative numbers as either the first or second number of the range (but not both). If
310
- you want to display the last three commands entered::
313
+ You can use negative numbers as either the first or second number of the range
314
+ (but not both). If you want to display the last three commands entered::
311
315
312
316
(Cmd) history -- -3:
313
317
2 alias create two !echo two
314
318
3 alias create three !echo three
315
319
4 alias create four !echo four
316
320
317
- Notice the double dashes. These are required because the history command uses `argparse ` to parse
318
- the command line arguments. For reasons I do not understand, `argparse ` thinks `-3: ` is an
319
- option, not an argument, but it thinks `-3 ` is an argument.
321
+ Notice the double dashes. These are required because the history command uses
322
+ ``argparse `` to parse the command line arguments. For reasons I do not
323
+ understand, ``argparse `` thinks ``-3: `` is an option, not an argument, but it
324
+ thinks ``-3 `` is an argument.
320
325
321
- There is no zeroth command, so don't ask for it. If you are a python programmer, you've
322
- probably noticed this looks a lot like the slice syntax for lists and arrays. It is,
323
- with the exception that the first history command is 1, where the first element in
324
- a python array is 0.
326
+ There is no zeroth command, so don't ask for it. If you are a python programmer,
327
+ you've probably noticed this looks a lot like the slice syntax for lists and
328
+ arrays. It is, with the exception that the first history command is 1, where the
329
+ first element in a python array is 0.
325
330
326
- Besides selecting previous commands by number, you can also search for them. You can use a simple
327
- string search::
331
+ Besides selecting previous commands by number, you can also search for them. You
332
+ can use a simple string search::
328
333
329
334
(Cmd) history two
330
335
2 alias create two !echo two
@@ -334,7 +339,7 @@ Or a regular expression search by enclosing your regex in slashes::
334
339
(Cmd) history '/te\ +th/'
335
340
3 alias create three !echo three
336
341
337
- If your regular expression contains any characters that `argparse ` finds
342
+ If your regular expression contains any characters that `` argparse ` ` finds
338
343
interesting, like dash or plus, you also need to enclose your regular expression
339
344
in quotation marks.
340
345
@@ -349,8 +354,8 @@ perform many other actions:
349
354
- running previously entered commands, saving the commands and their output to a text file
350
355
- clearing the history of entered commands
351
356
352
- Each of these actions is invoked using a command line option. The `-r ` or
353
- `--run ` option runs one or more previously entered commands. To run command
357
+ Each of these actions is invoked using a command line option. The `` -r ` ` or
358
+ `` --run ` ` option runs one or more previously entered commands. To run command
354
359
number 1::
355
360
356
361
(Cmd) history --run 1
@@ -361,80 +366,81 @@ stop looking for options)::
361
366
(Cmd) history -r -- -2:
362
367
363
368
Say you want to re-run some previously entered commands, but you would really
364
- like to make a few changes to them before doing so. When you use the `-e ` or
365
- `--edit ` option, `history ` will write the selected commands out to a text file,
366
- and open that file with a text editor. You make whatever changes, additions, or
367
- deletions, you want. When you leave the text editor, all the commands in the
368
- file are executed. To edit and then re-run commands 2-4 you would::
369
+ like to make a few changes to them before doing so. When you use the ``-e `` or
370
+ ``--edit `` option, ``history `` will write the selected commands out to a text
371
+ file, and open that file with a text editor. You make whatever changes,
372
+ additions, or deletions, you want. When you leave the text editor, all the
373
+ commands in the file are executed. To edit and then re-run commands 2-4 you
374
+ would::
369
375
370
376
(Cmd) history --edit 2:4
371
377
372
378
If you want to save the commands to a text file, but not edit and re-run them,
373
- use the `-o ` or `--output-file ` option. This is a great way to create
374
- :ref: `scripts `, which can be loaded and executed using the `load ` command. To
379
+ use the `` -o `` or `` --output-file ` ` option. This is a great way to create
380
+ :ref: `scripts `, which can be loaded and executed using the `` load ` ` command. To
375
381
save the first 5 commands entered in this session to a text file::
376
382
377
383
(Cmd) history :5 -o history.txt
378
384
379
- The `history ` command can also save both the commands and their output to a text
380
- file. This is called a transcript. See :doc: `transcript ` for more information on
381
- how transcripts work, and what you can use them for. To create a transcript use
382
- the `-t ` or `--transcription ` option::
385
+ The `` history `` command can also save both the commands and their output to a
386
+ text file. This is called a transcript. See :doc: `transcript ` for more
387
+ information on how transcripts work, and what you can use them for. To create a
388
+ transcript use the `` -t `` or `` --transcription ` ` option::
383
389
384
390
(Cmd) history 2:3 --transcript transcript.txt
385
391
386
- The `--transcript ` option implies `--run `: the commands must be re-run in order
387
- to capture their output to the transcript file.
392
+ The `` --transcript `` option implies `` --run `` : the commands must be re-run in
393
+ order to capture their output to the transcript file.
388
394
389
395
The last action the history command can perform is to clear the command history
390
- using `-c ` or `--clear `::
396
+ using `` -c `` or `` --clear ` `::
391
397
392
398
(Cmd) history -c
393
399
394
- In addition to these five actions, the `history ` command also has some options
395
- to control how the output is formatted. With no arguments, the `history ` command
396
- displays the command number before each command. This is great when displaying
397
- history to the screen because it gives you an easy reference to identify
398
- previously entered commands. However, when creating a script or a transcript,
399
- the command numbers would prevent the script from loading properly. The ` -s ` or
400
- ` -- script ` option instructs the `history ` command to suppress the line numbers.
401
- This option is automatically set by the `--output-file `, ` --transcript `, and
402
- `-- edit ` options. If you want to output the history commands with line numbers
403
- to a file, you can do it with output redirection::
400
+ In addition to these five actions, the `` history ` ` command also has some options
401
+ to control how the output is formatted. With no arguments, the `` history ``
402
+ command displays the command number before each command. This is great when
403
+ displaying history to the screen because it gives you an easy reference to
404
+ identify previously entered commands. However, when creating a script or a
405
+ transcript, the command numbers would prevent the script from loading properly.
406
+ The `` -s `` or `` -- script `` option instructs the `` history `` command to suppress
407
+ the line numbers. This option is automatically set by the `` --output-file ``,
408
+ `` --transcript ``, and `` -- edit `` options. If you want to output the history
409
+ commands with line numbers to a file, you can do it with output redirection::
404
410
405
411
(Cmd) history 1:4 > history.txt
406
412
407
- You might use `-s ` or `--script ` on it's own if you want to display history
413
+ You might use `` -s `` or `` --script ` ` on it's own if you want to display history
408
414
commands to the screen without line numbers, so you can copy them to the
409
415
clipboard::
410
416
411
417
(Cmd) history -s 1:3
412
418
413
- `cmd2 ` supports both aliases and macros, which allow you to substitute a short,
414
- more convenient input string with a longer replacement string. Say we create an
415
- alias like this, and then use it::
419
+ `` cmd2 `` supports both aliases and macros, which allow you to substitute a
420
+ short, more convenient input string with a longer replacement string. Say we
421
+ create an alias like this, and then use it::
416
422
417
423
(Cmd) alias create ls shell ls -aF
418
424
Alias 'ls' created
419
425
(Cmd) ls -d h*
420
426
history.txt htmlcov/
421
427
422
- By default, the `history ` command shows exactly what we typed::
428
+ By default, the `` history ` ` command shows exactly what we typed::
423
429
424
430
(Cmd) history
425
431
1 alias create ls shell ls -aF
426
432
2 ls -d h*
427
433
428
434
There are two ways to modify that display so you can see what aliases and macros
429
- were expanded to. The first is to use `-x ` or `--expanded `. These options show
430
- the expanded command instead of the entered command::
435
+ were expanded to. The first is to use `` -x `` or `` --expanded `` . These options
436
+ show the expanded command instead of the entered command::
431
437
432
438
(Cmd) history -x
433
439
1 alias create ls shell ls -aF
434
440
2 shell ls -aF -d h*
435
441
436
442
If you want to see both the entered command and the expanded command, use the
437
- `-v ` or `--verbose ` option::
443
+ `` -v `` or `` --verbose ` ` option::
438
444
439
445
(Cmd) history -v
440
446
1 alias create ls shell ls -aF
@@ -444,7 +450,7 @@ If you want to see both the entered command and the expanded command, use the
444
450
If the entered command had no expansion, it is displayed as usual. However, if
445
451
there is some change as the result of expanding macros and aliases, then the
446
452
entered command is displayed with the number, and the expanded command is
447
- displayed with the number followed by an `x `.
453
+ displayed with the number followed by an `` x ` `.
448
454
449
455
.. _`Readline Emacs editing mode` : http://readline.kablamo.org/emacs.html
450
456
0 commit comments