Windows Vista Forums

FEATURE REQUEST: better history support
  1. #1


    Adam Milazzo [MSFT] Guest

    FEATURE REQUEST: better history support

    The incremental history search (Ctrl-R, Ctrl-S) in bash is VERY nice and we
    need it in PowerShell.

    I wrote a function 'last' to attempt something similar, but it's not nearly
    as good. We need support for this from within the line editor.

    # runs the last command in the history that matches the given regular
    expression.
    # TODO: it'd be nice if this was closer to bash's excellent Ctrl-R support
    # examples:
    # last submit # run, eg, a recent "sd submit -c xxx" command
    # last "sdp pack" # run, eg, a recent "sdp pack" command
    function last($match)
    {
    $local:items = (get-history)
    for($local:i=$items.length-1; $i -gt 0; $i--)
    {
    $local:hi = $items[$i]
    if($hi.commandLine -match $match)
    {
    $local:cl = $hi.commandLine
    # exclude other 'last' commands unless the match explicitly contained
    'last'
    # TODO: this is dumb because by making assumptions about the name, it
    prevents users
    # from effectively aliasing the function. it should be more like
    bash's Ctrl-R support
    if($cl.startsWith("last ") -and !$match.contains("last"))
    {
    continue
    }

    if($cl.length -gt 40) { $cl = $cl.substring(0, 40) + "..." }
    $local:input = (read-host "Run '$cl' [Yes/No/Quit]?").toLower()
    if($input -eq "y" -or $input -eq "yes")
    {
    invoke-history $hi.ID
    return
    }
    elseif($input -eq "q" -or $input -eq "quit")
    {
    return
    }
    }
    }

    echo "No matches."
    }





      My System SpecsSystem Spec

  2. #2


    Keith Hill [MVP] Guest

    Re: FEATURE REQUEST: better history support

    "Adam Milazzo [MSFT]" <adamm@san.rr.com> wrote in message
    news:%236h0U7avGHA.2260@TK2MSFTNGP03.phx.gbl...
    > The incremental history search (Ctrl-R, Ctrl-S) in bash is VERY nice and
    > we need it in PowerShell.


    The built-in history feature of the console is OK. Try typing in the first
    part of a command that you entered before and press F8 (keep pressing F8)
    for more matches. You can also press F7 to get a character mode window of
    the history. Certainly not as powerful as a regex search engine but still
    quite useful.

    --
    Keith


      My System SpecsSystem Spec

  3. #3


    Adam Milazzo [MSFT] Guest

    Re: FEATURE REQUEST: better history support

    Keith Hill [MVP] wrote:
    > "Adam Milazzo [MSFT]" <adamm@san.rr.com> wrote in message
    > news:%236h0U7avGHA.2260@TK2MSFTNGP03.phx.gbl...
    >> The incremental history search (Ctrl-R, Ctrl-S) in bash is VERY nice
    >> and we need it in PowerShell.

    >
    > The built-in history feature of the console is OK. Try typing in the
    > first part of a command that you entered before and press F8 (keep
    > pressing F8) for more matches. You can also press F7 to get a character
    > mode window of the history. Certainly not as powerful as a regex search
    > engine but still quite useful.


    F8, huh? That's not too bad. Although it'd be better if it wasn't a
    prefix, but an arbitrary substring. (Often many commands start the same.)

    It'd also be better if I didn't have to move my hand too far.

    By the way, how did you find out about this? I don't remember reading
    about it in the user guide...

    Thanks,
    -- Adam

      My System SpecsSystem Spec

  4. #4


    =?Utf-8?B?Um9tYW4gS3V6bWlu?= Guest

    Re: FEATURE REQUEST: better history support

    > By the way, how did you find out about this? I don't remember reading
    > about it in the user guide...


    F7, F8 and etc. are standard features of windows console, not PowerShell.
    Try cmd.exe and you will see the same.

    --
    Thanks,
    Roman


      My System SpecsSystem Spec

FEATURE REQUEST: better history support problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Why I think the help & support feature is the best feature on Windows Vista. jan taynton Vista networking & sharing 0 22 May 2009
Feature Request Daniel Live Mail 10 25 Sep 2008
feature request A Live Folder Share 2 02 Jan 2008
feature request m$ Vista General 1 26 Dec 2007
RE: Feature Request Robert G Live Folder Share 0 12 Nov 2007