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."
}


