Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

One of the things that drive me crazy in command line under MS-Windows is the order in which the Windows shell (both the standard one and PowerShell) retrieve commands from history when you use the up and down arrow keys.

The standard way I've grown to like, as it is done in basically all other shells in the world, is that the last command is put into the history stack, and then pressing up will retrieve the last command I ran, "up" again will retrieve the one from before that, and so on. If you choose a command from history and submit it again, the command is copied to the top of the stack and if you press up on the next prompt you can see that last command and then the command previous to last. If after browsing the history you press "down" past the most recent command in the history stack, you will be returned to your empty prompt (or whatever you had there before you started browsing history).

In Windows shell, it works weirdly different: if you have 3 commands in the history - for example lets call them "A", "B" and "C" - and you use the up arrow key to select command "B" and execute it again, and then use the up arrow key again on the next prompt, the shell will display "B". But this is not the last command you executed (though "B" was indeed copied to the history stack again) as if you press "up" again you will be shown "A" and not "C". If you browse down (to later entries) you will see "B" again, followed by "C" then followed by "B" again which was the last command entered - but you also can't go any further: there's no going back to an empty prompt except deleting whatever you have on the line or pressing CTRL-C.

My question - is there some setting that one can set to change this behavior?

I'm aware of the option of just getting bash or something like that and using it on Windows, but due to external constraints (as in - that's what I need to write my scripts in), I have to work in PowerShell or another Windows shell that can invoke PowerShell scripts.

share|improve this question
I'd say the answer is "probably not". – Randolph West Aug 13 '12 at 19:48
I can't solve your main problem, but a nice shortcut to remember is to press CRTL-Home to erase the current line. – zdan Aug 13 '12 at 20:50
BTW - this is another example of why making PowerShell be completely object based was not a good idea: by introducing new complex mechanisms you also introduce new frustrating weird behaviors and edge cases. – Guss Sep 3 '12 at 17:55

1 Answer

up vote 1 down vote accepted

There is a different way to control the history stack, it is not what you wanted but it is a different option you should check out.

In Properties (or Default) when you right click the top left corner there is an option "Discard Old Duplicates" tick it and the stack will change its behavior.

in your example performing "A", "B", "C". and then twice up to perform "B", the stack will look: "B","C","A" (first up will be "B")

share|improve this answer
Its not exactly what I wanted, but its so close it doesn't matter much - my main grievance was that hitting UP ARROW after executing a command from history doesn't revert the "current history entry" to the "after last entry" but to "after the entry you last selected" (but before the next one). This fixes it by still having the virtual history cursor "after the entry you last selected", but moving said entry to the end, causing the history cursor to also be "after last entry". Thanks! – Guss Sep 3 '12 at 17:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.