Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 help and support Forum Windows 8 Forum Vista Tutorials

Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Vista Newsgroup Archive > Misc Newsgroups > PowerShell

Vista - prompt function and the last command entered


 
 
07-30-2009   #1 (permalink)
Larry__Weiss


 

prompt function and the last command entered

I'd like my prompt function to have knowledge of the last command entered,
meaning the one that produced output before the next command line prompt is
displayed.

I attempted to use the automatic variable $^ in the prompt function and I have
discovered that the value of $^ is still its older value, not the command that
just executed.



How else can I get the string that represents the last command entered at the
command prompt in a way that it can be used by the prompt function?

- Larry
My System SpecsSystem Spec
07-30-2009   #2 (permalink)
Marco Shaw [MVP]


 

Re: prompt function and the last command entered

If I follow:
PS>function prompt { (get-history -count 1|select -exp commandline)+">" }

"Larry__Weiss" <lfw@xxxxxx> wrote in message
news:OmaaRLXEKHA.1516@xxxxxx
Quote:

> I'd like my prompt function to have knowledge of the last command entered,
> meaning the one that produced output before the next command line prompt
> is displayed.
>
> I attempted to use the automatic variable $^ in the prompt function and I
> have discovered that the value of $^ is still its older value, not the
> command that just executed.
>
> How else can I get the string that represents the last command entered at
> the command prompt in a way that it can be used by the prompt function?
>
> - Larry
My System SpecsSystem Spec
07-31-2009   #3 (permalink)
Larry__Weiss


 

Re: prompt function and the last command entered

That works. Thanks.

Do you think it is a bug that $^ is not yet bound to the value of the last
command at the time that the prompt function is executed?

From: help about_Automatic_Variables
$^ Contains the first token in the last line received by the session

But
function prompt{$^}
is always one line behind.

- Larry


Marco Shaw [MVP] wrote:
Quote:

> If I follow:
> PS>function prompt { (get-history -count 1|select -exp commandline)+">" }
>
> "Larry__Weiss" <lfw@xxxxxx> wrote in message
> news:OmaaRLXEKHA.1516@xxxxxx
Quote:

>> I'd like my prompt function to have knowledge of the last command
>> entered, meaning the one that produced output before the next command
>> line prompt is displayed.
>>
>> I attempted to use the automatic variable $^ in the prompt function
>> and I have discovered that the value of $^ is still its older value,
>> not the command that just executed.
>>
>> How else can I get the string that represents the last command entered
>> at the command prompt in a way that it can be used by the prompt
>> function?
>>
My System SpecsSystem Spec
07-31-2009   #4 (permalink)
Marco Shaw [MVP]


 

Re: prompt function and the last command entered

Good question. I don't know if I'll have time to look into it myself.

Marco

"Larry__Weiss" <lfw@xxxxxx> wrote in message
news:udO2c1cEKHA.4220@xxxxxx
Quote:

> That works. Thanks.
>
> Do you think it is a bug that $^ is not yet bound to the value of the last
> command at the time that the prompt function is executed?
>
> From: help about_Automatic_Variables
> $^ Contains the first token in the last line received by the session
>
> But
> function prompt{$^}
> is always one line behind.
>
> - Larry
>
>
> Marco Shaw [MVP] wrote:
Quote:

>> If I follow:
>> PS>function prompt { (get-history -count 1|select -exp commandline)+">" }
>>
>> "Larry__Weiss" <lfw@xxxxxx> wrote in message
>> news:OmaaRLXEKHA.1516@xxxxxx
Quote:

>>> I'd like my prompt function to have knowledge of the last command
>>> entered, meaning the one that produced output before the next command
>>> line prompt is displayed.
>>>
>>> I attempted to use the automatic variable $^ in the prompt function and
>>> I have discovered that the value of $^ is still its older value, not the
>>> command that just executed.
>>>
>>> How else can I get the string that represents the last command entered
>>> at the command prompt in a way that it can be used by the prompt
>>> function?
>>>
My System SpecsSystem Spec
07-31-2009   #5 (permalink)
Larry__Weiss


 

Re: prompt function and the last command entered

I need to figure out how to file questions like that with the PowerShell team.
I imagine there is a website to do that somewhere.

- Larry


Marco Shaw [MVP] wrote:
Quote:

> Good question. I don't know if I'll have time to look into it myself.
>
> "Larry__Weiss" <lfw@xxxxxx> wrote in message
> news:udO2c1cEKHA.4220@xxxxxx
Quote:

>> That works. Thanks.
>>
>> Do you think it is a bug that $^ is not yet bound to the value of the
>> last command at the time that the prompt function is executed?
>>
>> From: help about_Automatic_Variables
>> $^ Contains the first token in the last line received by the session
>>
>> But
>> function prompt{$^}
>> is always one line behind.
>>
>>
>> Marco Shaw [MVP] wrote:
Quote:

>>> If I follow:
>>> PS>function prompt { (get-history -count 1|select -exp
>>> commandline)+">" }
>>>
>>> "Larry__Weiss" <lfw@xxxxxx> wrote in message
>>> news:OmaaRLXEKHA.1516@xxxxxx
>>>> I'd like my prompt function to have knowledge of the last command
>>>> entered, meaning the one that produced output before the next
>>>> command line prompt is displayed.
>>>>
>>>> I attempted to use the automatic variable $^ in the prompt function
>>>> and I have discovered that the value of $^ is still its older value,
>>>> not the command that just executed.
>>>>
>>>> How else can I get the string that represents the last command
>>>> entered at the command prompt in a way that it can be used by the
>>>> prompt function?
>>>>
My System SpecsSystem Spec
07-31-2009   #6 (permalink)
Marco Shaw [MVP]


 

Re: prompt function and the last command entered

For bugs and/or suggestions:
https://connect.microsoft.com/PowerShell

"Larry__Weiss" <lfw@xxxxxx> wrote in message
news:#AQJwOgEKHA.5780@xxxxxx
Quote:

> I need to figure out how to file questions like that with the PowerShell
> team. I imagine there is a website to do that somewhere.
My System SpecsSystem Spec
 

prompt function and the last command entered problems?



Thread Tools


Similar topics to: prompt function and the last command entered
Thread Forum
A near prompt function I created... PowerShell
customized prompt function PowerShell
Solved Make a command prompt run a command as soon as it opens? General Discussion
echo out interactive parameters that were entered for a command PowerShell
Command prompt "COPY" command not working in brand new Windows Vis Vista file management


Vista Forums 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 Ltd

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