Skip to content

Commit 486f08a

Browse files
committed
Formatting clean up on history section
1 parent f671667 commit 486f08a

File tree

1 file changed

+67
-61
lines changed

1 file changed

+67
-61
lines changed

docs/freefeatures.rst

Lines changed: 67 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,10 @@ the readline history.
253253

254254
.. automethod:: cmd2.cmd2.Cmd.__init__
255255

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::
260260

261261
(Cmd) alias create one !echo one
262262
Alias 'one' created
@@ -267,36 +267,40 @@ following commands::
267267
(Cmd) alias create four !echo four
268268
Alias 'four' created
269269

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::
272273

273274
(Cmd) history
274275
1 alias create one !echo one
275276
2 alias create two !echo two
276277
3 alias create three !echo three
277278
4 alias create four !echo four
278279

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::
280282

281283
(Cmd) history 4
282284
4 alias create four !echo four
283285

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::
287290

288291
(Cmd) history -2
289292
3 alias create three !echo three
290293

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::
293297

294298
(Cmd) history 2:3
295299
2 alias create two !echo two
296300
3 alias create three !echo three
297301

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::
300304

301305
(Cmd) history :2
302306
1 alias create one !echo one
@@ -306,25 +310,26 @@ will continue to the end::
306310
3 alias create three !echo three
307311
4 alias create four !echo four
308312

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::
311315

312316
(Cmd) history -- -3:
313317
2 alias create two !echo two
314318
3 alias create three !echo three
315319
4 alias create four !echo four
316320

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.
320325

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.
325330

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::
328333

329334
(Cmd) history two
330335
2 alias create two !echo two
@@ -334,7 +339,7 @@ Or a regular expression search by enclosing your regex in slashes::
334339
(Cmd) history '/te\ +th/'
335340
3 alias create three !echo three
336341

337-
If your regular expression contains any characters that `argparse` finds
342+
If your regular expression contains any characters that ``argparse`` finds
338343
interesting, like dash or plus, you also need to enclose your regular expression
339344
in quotation marks.
340345

@@ -349,8 +354,8 @@ perform many other actions:
349354
- running previously entered commands, saving the commands and their output to a text file
350355
- clearing the history of entered commands
351356

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
354359
number 1::
355360

356361
(Cmd) history --run 1
@@ -361,80 +366,81 @@ stop looking for options)::
361366
(Cmd) history -r -- -2:
362367

363368
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::
369375

370376
(Cmd) history --edit 2:4
371377

372378
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
375381
save the first 5 commands entered in this session to a text file::
376382

377383
(Cmd) history :5 -o history.txt
378384

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::
383389

384390
(Cmd) history 2:3 --transcript transcript.txt
385391

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.
388394

389395
The last action the history command can perform is to clear the command history
390-
using `-c` or `--clear`::
396+
using ``-c`` or ``--clear``::
391397

392398
(Cmd) history -c
393399

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::
404410

405411
(Cmd) history 1:4 > history.txt
406412

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
408414
commands to the screen without line numbers, so you can copy them to the
409415
clipboard::
410416

411417
(Cmd) history -s 1:3
412418

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::
416422

417423
(Cmd) alias create ls shell ls -aF
418424
Alias 'ls' created
419425
(Cmd) ls -d h*
420426
history.txt htmlcov/
421427

422-
By default, the `history` command shows exactly what we typed::
428+
By default, the ``history`` command shows exactly what we typed::
423429

424430
(Cmd) history
425431
1 alias create ls shell ls -aF
426432
2 ls -d h*
427433

428434
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::
431437

432438
(Cmd) history -x
433439
1 alias create ls shell ls -aF
434440
2 shell ls -aF -d h*
435441

436442
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::
438444

439445
(Cmd) history -v
440446
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
444450
If the entered command had no expansion, it is displayed as usual. However, if
445451
there is some change as the result of expanding macros and aliases, then the
446452
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``.
448454

449455
.. _`Readline Emacs editing mode`: http://readline.kablamo.org/emacs.html
450456

0 commit comments

Comments
 (0)