[SERVER-4034] Command line history in the shell could be better Created: 07/Oct/11  Updated: 11/Jul/16  Resolved: 05/Jan/12

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.0.0
Fix Version/s: 2.1.0

Type: Improvement Priority: Minor - P4
Reporter: Tad Marshall Assignee: Tad Marshall
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Any


Participants:

 Description   

The command line history feature of the shell tends to accumulate multiple copies of commands when it is used. The only test for preventing duplicate commands from being stored is a comparison with the immediately preceding command, so if you up-arrow three times and hit return, you get a new copy of the old command. The bash shell seems to be a lot smarter about this. We should try to be closer to bash in handling history.

A second thought (sorry for two thoughts in one bug report, but they are related) is that the Windows command line (cmd.exe) has a feature that bash doesn't have. In Windows, if your most recent command was retrieved by using up-arrow, then that position is remembered as a "special" location, and if your next keystroke is down-arrow, then the command that followed the one that you just retrieved is recalled, and the special location is updated. This has no effect on what happens on up-arrow and doesn't "rotate the list" or anything like that. It's just a simple hack that lets you issue five commands in sequence and then recall them in the same sequence later. It doesn't break compatibility with bash or other shells because other shells just ignore a down-arrow when you haven't already recalled a command with up-arrow. The reason that I mention this is that it can be very convenient, and Windows users might try it and hope that it is there. If we implement it, we could consider doing it for all versions and not just Windows versions. It can save a lot of keystrokes in some situations and feel very friendly.

> my first command [hit enter]
> my second command [enter]
> my third command [enter]
> [up-arrow] twice shows "my second command" ... [hit enter]
> [down-arrow] on Windows (DOS) command line, this shows "my third command", on bash it does nothing

At the Windows (DOS) command line, down-arrow behaves just like bash if your immediately preceding entry wasn't a recalled command or if the command was edited (changed) before you hit return. Its only appearance as a feature is when you are recalling a sequence of commands.



 Comments   
Comment by auto [ 05/Jan/12 ]

Author:

{u'login': u'', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-4034 fix broken logic, add new logic in cmd history

Don't store edited but un-entered command in history. Add code
to emulate what the Windows command line does on an initial down-
arrow after recalling a previous command: fetch the following
command, so replaying a sequence of commands is easier.
Branch: master
https://github.com/mongodb/mongo/commit/90a86ec1363e692f393d0421754196d621bbef44

Comment by Tad Marshall [ 05/Jan/12 ]

Here's a quick test to show bugginess in the 2.0 code:

C:\Bin\MongoDB\202> mongo
MongoDB shell version: 2.0.2
connecting to: test
> // This line is perfect!
> // just another line
>
Now press up-arrow to get to the "perfect" line and change it, but don't hit return yet.
> // This line is RUINED
Now press down-arrow and return.
> // just another line
Now try press up-arrow and try to find your "perfect" line. It is gone, and has been replaced with the UN-ENTERED edit you made ... your history says that you entered a line saying "This line is RUINED" even though you didn't, and the line that you actually entered is no longer in the history. Bad shell, BAD!

Generated at Thu Feb 08 03:04:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.