Skip to content

Commit 40e14ce

Browse files
author
Bob Grabar
committed
copy edits to shell-line-editing doc
1 parent 5f73027 commit 40e14ce

File tree

1 file changed

+74
-55
lines changed

1 file changed

+74
-55
lines changed

draft/shell-line-editing.txt

Lines changed: 74 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
Interacting with the Mongo Shell
33
================================
44

5-
65
Introduction
76
------------
87

9-
The MongoDB shell is a interactive javascript shell interface to MongoDB. It is invoked by running `mongo` or `mongo.exe`.
10-
11-
8+
The MongoDB shell is a interactive javascript shell interface to
9+
MongoDB. It is invoked by running :program:`mongo` or ``mongo.exe``.
1210

1311
Keyboard Shortcuts
1412
------------------
1513

16-
The MongoDB shell tries to follow familiar keyboard shortcuts as found in bash and emacs.
14+
The MongoDB shell tries to follow familiar keyboard shortcuts as found
15+
in bash and emacs.
1716

18-
The following table illustrates the various keystrokes supported by the MongoDB shell:
17+
The following table illustrates the various keystrokes supported by the
18+
MongoDB shell:
1919

20-
You will notice that we try to accommodate multiple keybinding styles and as a result some functions have multiple bindings that will work.
20+
You will notice that MongoDB accommodates multiple keybinding styles,
21+
and as a result some functions have multiple bindings that will work.
2122

2223
=================== =====================================
2324
Keystroke Function
@@ -70,71 +71,89 @@ Meta-> end-of-history
7071
Custom Prompt
7172
-------------
7273

73-
The shell's prompt can be customized by creating variable 'prompt' in the shell. It can be any arbitrary javascript, including a function that returns a string. This flexibility allows for additional information to be displayed in the prompt.
74+
The shell's prompt can be customized by creating the variable ``prompt``
75+
in the shell. It can be any arbitrary javascript, including a function
76+
that returns a string. This flexibility allows for additional
77+
information to be displayed in the prompt.
7478

75-
The following three examples should give you a good enough idea to get you started.
79+
The following three examples should give you a good enough idea to get
80+
you started.
7681

77-
A prompt that contains the number of commands issued:
82+
.. example::
7883

79-
.. code-block:: javascript
84+
A prompt that contains the number of commands issued:
8085

81-
> cmdCount = 1;
82-
> prompt = function() {
83-
... return (cmdCount++) + "> ";
84-
... }
85-
1> command
86-
2> anothercommand
87-
3>
86+
.. code-block:: javascript
8887

89-
To make the prompt look a bit more familiar, we can make it database@host$:
88+
> cmdCount = 1;
89+
> prompt = function() {
90+
... return (cmdCount++) + "> ";
91+
... }
92+
1> command
93+
2> anothercommand
94+
3>
9095

91-
.. code-block:: javascript
96+
.. example::
9297

93-
> host = db.serverStatus().host; \\ since host should not change
94-
> prompt = function() {
95-
... return db+"@"+host+"$ ";
96-
... }
97-
[email protected]$ use monkeys
98-
switched to db monkeys
99-
98+
A ``database@host$`` prompt:
10099

101-
You could use the prompt to do a bit of database monitoring as well:
100+
.. code-block:: javascript
102101

103-
.. code-block:: javascript
102+
> host = db.serverStatus().host; \\ since host should not change
103+
> prompt = function() {
104+
... return db+"@"+host+"$ ";
105+
... }
106+
[email protected]$ use monkeys
107+
switched to db monkeys
108+
109+
110+
.. example::
111+
112+
A prompt that also performs database monitoring:
104113

105-
> prompt = function() {
106-
... return "Uptime:"+db.serverStatus().uptime+" Files:"+db.stats().objects+" > ";
107-
... }
108-
Uptime:5897 Files:6 > db.monkeys.save({name : "James"});
109-
Uptime:5948 Files:7 >
114+
.. code-block:: javascript
110115

116+
> prompt = function() {
117+
... return "Uptime:"+db.serverStatus().uptime+" Files:"+db.stats().objects+" > ";
118+
... }
119+
Uptime:5897 Files:6 > db.monkeys.save({name : "James"});
120+
Uptime:5948 Files:7 >
111121

112-
Using a real editor
122+
Using a Real Editor
113123
-------------------
114124

115-
MongoDB 2.1+ includes the ability to use an external editor. Just run ``edit nameOfVariableOrFunction`` and the MongoDB shell will open whatever editor you have defined in your $EDITOR environment variable. When you are finished editing simply save and exit (:wq in Vim). If you wish to discard your changes, you can either not save or make your editor exit with an error (:cq in Vim or (kill-emacs 1) in Emacs).
125+
MongoDB version 2.1+ includes the ability to use an external editor. To
126+
do so, run ``edit nameOfVariableOrFunction`` and the MongoDB shell will
127+
open whatever editor you have defined in your ``$EDITOR`` environment
128+
variable. When you are finished editing, simply save and exit (``:wq``
129+
in Vim). If you wish to discard your changes, you can either not save or
130+
make your editor exit with an error (``:cq`` in Vim or ``kill-emacs 1``
131+
in Emacs).
116132

117133
.. code-block:: bash
118134

119-
$ EDITOR=vim mongo --nodb
135+
$ EDITOR=vim mongo --nodb
120136

121137
.. code-block:: javascript
122138

123-
MongoDB shell version: 2.1.0
124-
> function f() {}
125-
> edit f
126-
> f
127-
function f() {
128-
print("this really works");
129-
}
130-
> f()
131-
this really works
132-
> o = {}
133-
{ }
134-
> edit o
135-
> o
136-
{ "soDoes" : "this" }
137-
>
138-
139-
.. note::
140-
It is possible that the code in functions will be slightly modified by the JavaScript compiler when you try to edit it again. For example it may convert 1+1 in to 2 and strip out comments. The actual changes will vary based on the version of JavaScript used, but should not effect the semantics of the code, only its appearance.
139+
MongoDB shell version: 2.1.0
140+
> function f() {}
141+
> edit f
142+
> f
143+
function f() {
144+
print("this really works");
145+
}
146+
> f()
147+
this really works
148+
> o = {}
149+
{ }
150+
> edit o
151+
> o
152+
{ "soDoes" : "this" }
153+
>
154+
155+
.. note:: It is possible that the code in functions will be slightly
156+
modified by the JavaScript compiler when you try to edit it again.
157+
For example, it may convert ``1+1`` to ``2`` or strip out comments.
158+
The actual changes will vary based on the version of JavaScript used
159+
but should not affect the semantics of the code, only the appearance.

0 commit comments

Comments
 (0)