Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Repeating previous commands

Closed Thread
 
Thread Tools Display Modes
Old 05-24-2008   #1 (permalink)
snorble
Guest


 

Repeating previous commands

Is there anything in Power Shell that is equivalent to the exclamation
(!) feature in bash?

Here's an example. Let's say I'm working on a Python script: edit the
script, run the script, repeat.

Using PowerShell

PS C:\> vim foo.py
PS C:\> python foo.py
running foo.py... done
PS C:\> vim foo.py
PS C:\> python foo.py
running foo.py... done

Using bash

$ vim foo.py
$ python foo.py
running foo.py... done
$ !v
vim foo.py
$ !p
python foo.py
running foo.py... done

Using bash, I can just type !v and !p to run the last command that
started with a v or p ("vi foo.py", "python foo.py"). In PowerShell, I
type out the full command. Is there anything like the ! in Power
Shell? It may seem like a small detail, but when working on software
development projects for hours at a time, it adds up.
Old 05-25-2008   #2 (permalink)
Robert Aldwinckle
Guest


 

Re: Repeating previous commands

<snorble@xxxxxx> wrote in message
news:2a9a37a9-56bf-4bc4-996b-567cc70ec1eb@xxxxxx
Quote:

> Is there anything in Power Shell that is equivalent to the exclamation
> (!) feature in bash?

F7 (but not in Graphical PS?)

However, since your example involves only a pair
of commands you could get the same result with
fewer keystrokes simply by using CursorUp twice.
And that works in either app. <eg>


---


Old 05-26-2008   #3 (permalink)
Hal Rottenberg
Guest


 

Re: Repeating previous commands

snorble@xxxxxx wrote:
Quote:

> PS C:\> vim foo.py
> PS C:\> python foo.py
> running foo.py... done
To build on what Keith said, add this to your profile (notepad $profile):

function r! ($pattern) {
get-history | where-object { $_.CommandLine -like "$pattern" } |
foreach-object { invoke-history $_ -confirm }
}

If you're brave, remove the -confirm. You'll need to insert asterisks, or you
could add them to the pattern string. Or you could use -match for a regex.
Might be overkill.

--
Author, Tech Prosaic blog (http://halr9000.com)
Webmaster, Psi (http://psi-im.org)
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast (http://powerscripting.net)
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
updates repeating chinga69 Windows Updates 18 06-07-2008 08:29 PM
repeating user name and password gerda Vista mail 0 03-14-2008 01:20 PM
Keyboard continuously repeating Man In Problem Vista hardware & devices 1 11-09-2007 03:59 PM
KB924125 update REPEATING PA Vista General 0 11-08-2006 01:04 AM
repeating a windows update KB924125 =?Utf-8?B?c2FoYXJhIHBvb2xz?= Vista General 0 10-06-2006 05:18 AM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50