Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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 > Misc Newsgroups > PowerShell

Vista - Tab completion not what I expected

Reply
 
Old 07-14-2009   #1 (permalink)
Tim Munro


 
 

Tab completion not what I expected

Hi all
I've recently installed V2 CTP3. (never had CTP2). When type a command
and then use TAB expansion to (for example) conplete and file name, I get
the previously typed command and not the expanded filename(s). I've
discovered that the problem seems to be the filenames that start with "#".
PS requires that these names be enclosed in quotes, either single or double.

I have a 4 or 5 file files named #missingxxx.txt. When I type dir '#m
<tab> it cycles through all my previous commands rather than just the files
starting with "#m". Does the "#" character mean anything special to PS? In
PS v1 it worked just fine.

--
Confused.



My System SpecsSystem Spec
Old 07-14-2009   #2 (permalink)
Hans Dingemans


 
 

Re: Tab completion not what I expected

This seems to be a "feature" of the built-in TabExpansion function, which
according the help can be redefined.

type Function:\TabExpansion
..
..
..

# Tab complete against history either #<pattern> or
#<id>
'^#(\w*)' {
$_pattern = $matches[1]
if ($_pattern -match '^[0-9]+$')
{
Get-History -ea SilentlyContinue -Id $_pattern |
Foreach { $_.CommandLine }
}
else
{
$_pattern = '*' + $_pattern + '*'
Get-History | Sort-Object -Descending Id|
Foreach { $_.CommandLine } | where { $_ -like $_pattern }
}
break;
}


HTH,
Hans


"Tim Munro" <Excelsior@xxxxxx> wrote in message
news:OBDSiDIBKHA.4376@xxxxxx
Quote:

> Hi all
> I've recently installed V2 CTP3. (never had CTP2). When type a command
> and then use TAB expansion to (for example) conplete and file name, I get
> the previously typed command and not the expanded filename(s). I've
> discovered that the problem seems to be the filenames that start with "#".
> PS requires that these names be enclosed in quotes, either single or
> double.
>
> I have a 4 or 5 file files named #missingxxx.txt. When I type dir '#m
> <tab> it cycles through all my previous commands rather than just the
> files starting with "#m". Does the "#" character mean anything special to
> PS? In PS v1 it worked just fine.
>
> --
> Confused.
>
>
My System SpecsSystem Spec
Old 07-14-2009   #3 (permalink)
Larry__Weiss


 
 

Re: Tab completion not what I expected

Regarding the use of # in PowerShell V2

# is a PS indicator that the rest of the line is a comment
For example
dir *.ps1 # comment

You can have embeddded comments
dir <# comment #> *.ps1

Or multiline comments
<#
comment line 1
comment line 2
#>

- Larry


Tim Munro wrote:
Quote:

> Hi all
> I've recently installed V2 CTP3. (never had CTP2). When type a command
> and then use TAB expansion to (for example) conplete and file name, I get
> the previously typed command and not the expanded filename(s). I've
> discovered that the problem seems to be the filenames that start with "#".
> PS requires that these names be enclosed in quotes, either single or double.
>
> I have a 4 or 5 file files named #missingxxx.txt. When I type dir '#m
> <tab> it cycles through all my previous commands rather than just the files
> starting with "#m". Does the "#" character mean anything special to PS? In
> PS v1 it worked just fine.
>
> --
> Confused.
>
>
My System SpecsSystem Spec
Old 07-14-2009   #4 (permalink)
Larry__Weiss


 
 

Re: Tab completion not what I expected

Hristo Deshev's book "Pro Windows PowerShell" has a section named "Tab
Expansion:How Command Completion Works" in "Chapter 11: The Shell Environment
and it's Configuration" that describes the default TabExpansion function and how
you can replace or extend it.

http://www.amazon.com/Pro-Windows-Po...-Hristo-Deshev



Hans Dingemans wrote:
Quote:

> This seems to be a "feature" of the built-in TabExpansion function,
> which according the help can be redefined.
>
> type Function:\TabExpansion
> .
> .
> .
>
> # Tab complete against history either #<pattern> or
> #<id>
> '^#(\w*)' {
> $_pattern = $matches[1]
> if ($_pattern -match '^[0-9]+$')
> {
> Get-History -ea SilentlyContinue -Id
> $_pattern | Foreach { $_.CommandLine }
> }
> else
> {
> $_pattern = '*' + $_pattern + '*'
> Get-History | Sort-Object -Descending Id|
> Foreach { $_.CommandLine } | where { $_ -like $_pattern }
> }
> break;
> }
>
>
> HTH,
> Hans
>
>
> "Tim Munro" <Excelsior@xxxxxx> wrote in message
> news:OBDSiDIBKHA.4376@xxxxxx
Quote:

>> Hi all
>> I've recently installed V2 CTP3. (never had CTP2). When type a
>> command and then use TAB expansion to (for example) conplete and file
>> name, I get the previously typed command and not the expanded
>> filename(s). I've discovered that the problem seems to be the
>> filenames that start with "#". PS requires that these names be
>> enclosed in quotes, either single or double.
>>
>> I have a 4 or 5 file files named #missingxxx.txt. When I type dir
>> '#m <tab> it cycles through all my previous commands rather than just
>> the files starting with "#m". Does the "#" character mean anything
>> special to PS? In PS v1 it worked just fine.
>>
>> --
>> Confused.
>>
>>
>
My System SpecsSystem Spec
Old 07-16-2009   #5 (permalink)
Tim Munro


 
 

Re: Tab completion not what I expected

Thank you both Hans, and Larry. I've always used the '#' to indicate a
temporary or transivitive file. Therefore if I "del #*" I have no worries.
This also explains why my files need to be enclosed on quotes. I don't think
I'll muck with the PS defaults. I'll find some other convention to denote my
disposable files.

--
Tim.

"Larry__Weiss" <lfw@xxxxxx> wrote in message
news:OzIQgYJBKHA.1252@xxxxxx
Quote:

> Regarding the use of # in PowerShell V2
>
> # is a PS indicator that the rest of the line is a comment
> For example
> dir *.ps1 # comment
>
> You can have embeddded comments
> dir <# comment #> *.ps1
>
> Or multiline comments
> <#
> comment line 1
> comment line 2
> #>
>
> - Larry
>
>
> Tim Munro wrote:
Quote:

>> Hi all
>> I've recently installed V2 CTP3. (never had CTP2). When type a
>> command and then use TAB expansion to (for example) conplete and file
>> name, I get the previously typed command and not the expanded
>> filename(s). I've discovered that the problem seems to be the filenames
>> that start with "#". PS requires that these names be enclosed in quotes,
>> either single or double.
>>
>> I have a 4 or 5 file files named #missingxxx.txt. When I type dir
>> '#m <tab> it cycles through all my previous commands rather than just the
>> files starting with "#m". Does the "#" character mean anything special to
>> PS? In PS v1 it worked just fine.
>>
>> --
>> Confused.
>>
My System SpecsSystem Spec
Old 07-16-2009   #6 (permalink)
Hans Dingemans


 
 

Re: Tab completion not what I expected

>>> I'll find some other convention to denote my disposable files.

Strange, my V2 CTP3 help file suggests there's a New-Path cmdlet...

C:\PS>new-path
C:\Users\admin1\AppData\Local\Temp\tmpD45F.tmp
C:\PS>

.... but PowerShell does not recognize it. Online MSDN help does not mention
the cmdlet (anymore).

In that case, you could use the .NET classes :-)

PS> [IO.Path]::GetTempPath()
C:\Users\Hans Dingemans\AppData\Local\Temp\
PS>
PS> $tmpfile = [IO.Path]::GetTempFileName()
PS> $tmpfile
C:\Users\Hans Dingemans\AppData\Local\Temp\tmp3CE0.tmp
PS>

Hth,
Hans


"Tim Munro" <Excelsior@xxxxxx> wrote in message
news:OC79C%23gBKHA.4336@xxxxxx
Quote:

> Thank you both Hans, and Larry. I've always used the '#' to indicate a
> temporary or transivitive file. Therefore if I "del #*" I have no worries.
> This also explains why my files need to be enclosed on quotes. I don't
> think I'll muck with the PS defaults. I'll find some other convention to
> denote my disposable files.
>
> --
> Tim.
>
> "Larry__Weiss" <lfw@xxxxxx> wrote in message
> news:OzIQgYJBKHA.1252@xxxxxx
Quote:

>> Regarding the use of # in PowerShell V2
>>
>> # is a PS indicator that the rest of the line is a comment
>> For example
>> dir *.ps1 # comment
>>
>> You can have embeddded comments
>> dir <# comment #> *.ps1
>>
>> Or multiline comments
>> <#
>> comment line 1
>> comment line 2
>> #>
>>
>> - Larry
>>
>>
>> Tim Munro wrote:
Quote:

>>> Hi all
>>> I've recently installed V2 CTP3. (never had CTP2). When type a
>>> command and then use TAB expansion to (for example) conplete and file
>>> name, I get the previously typed command and not the expanded
>>> filename(s). I've discovered that the problem seems to be the filenames
>>> that start with "#". PS requires that these names be enclosed in quotes,
>>> either single or double.
>>>
>>> I have a 4 or 5 file files named #missingxxx.txt. When I type dir
>>> '#m <tab> it cycles through all my previous commands rather than just
>>> the files starting with "#m". Does the "#" character mean anything
>>> special to PS? In PS v1 it worked just fine.
>>>
>>> --
>>> Confused.
>>>
>
My System SpecsSystem Spec
Old 07-16-2009   #7 (permalink)
Hans Dingemans


 
 

Re: Tab completion not what I expected

http://msdn.microsoft.com/en-us/libr...mfilename.aspx

Or use GetRandomFileName method if you do not want to create the file (yet).

PS> $tmpfile = [IO.Path]::GetRandomFileName()
PS> $tmpfile
uxoqsxig.y01
PS>


"Hans Dingemans" <hansdingemans@xxxxxx> wrote in message
news:ewSC9thBKHA.5068@xxxxxx
Quote:
Quote:
Quote:

>>>> I'll find some other convention to denote my disposable files.
>
> Strange, my V2 CTP3 help file suggests there's a New-Path cmdlet...
>
> C:\PS>new-path
> C:\Users\admin1\AppData\Local\Temp\tmpD45F.tmp
> C:\PS>
>
> ... but PowerShell does not recognize it. Online MSDN help does not
> mention the cmdlet (anymore).
>
> In that case, you could use the .NET classes :-)
>
> PS> [IO.Path]::GetTempPath()
> C:\Users\Hans Dingemans\AppData\Local\Temp\
> PS>
> PS> $tmpfile = [IO.Path]::GetTempFileName()
> PS> $tmpfile
> C:\Users\Hans Dingemans\AppData\Local\Temp\tmp3CE0.tmp
> PS>
>
> Hth,
> Hans
>
>
> "Tim Munro" <Excelsior@xxxxxx> wrote in message
> news:OC79C%23gBKHA.4336@xxxxxx
Quote:

>> Thank you both Hans, and Larry. I've always used the '#' to indicate a
>> temporary or transivitive file. Therefore if I "del #*" I have no
>> worries. This also explains why my files need to be enclosed on quotes. I
>> don't think I'll muck with the PS defaults. I'll find some other
>> convention to denote my disposable files.
>>
>> --
>> Tim.
>>
>> "Larry__Weiss" <lfw@xxxxxx> wrote in message
>> news:OzIQgYJBKHA.1252@xxxxxx
Quote:

>>> Regarding the use of # in PowerShell V2
>>>
>>> # is a PS indicator that the rest of the line is a comment
>>> For example
>>> dir *.ps1 # comment
>>>
>>> You can have embeddded comments
>>> dir <# comment #> *.ps1
>>>
>>> Or multiline comments
>>> <#
>>> comment line 1
>>> comment line 2
>>> #>
>>>
>>> - Larry
>>>
>>>
>>> Tim Munro wrote:
>>>> Hi all
>>>> I've recently installed V2 CTP3. (never had CTP2). When type a
>>>> command and then use TAB expansion to (for example) conplete and file
>>>> name, I get the previously typed command and not the expanded
>>>> filename(s). I've discovered that the problem seems to be the filenames
>>>> that start with "#". PS requires that these names be enclosed in
>>>> quotes, either single or double.
>>>>
>>>> I have a 4 or 5 file files named #missingxxx.txt. When I type dir
>>>> '#m <tab> it cycles through all my previous commands rather than just
>>>> the files starting with "#m". Does the "#" character mean anything
>>>> special to PS? In PS v1 it worked just fine.
>>>>
>>>> --
>>>> Confused.
>>>>
>>
>
My System SpecsSystem Spec
Old 07-20-2009   #8 (permalink)
Tim Munro


 
 

Re: Tab completion not what I expected

Not that kind of disposable file. The files need specific names as they hold
specific information from a production run. After I've checked over the file
and processesed it, it is no longer of any use. In that sense it's
temporary. Just any random filename wouldn't help I'm afraid.

"Hans Dingemans" <hansdingemans@xxxxxx> wrote in message
news:OToMI0hBKHA.5020@xxxxxx
Quote:

> http://msdn.microsoft.com/en-us/libr...mfilename.aspx
>
> Or use GetRandomFileName method if you do not want to create the file
> (yet).
>
> PS> $tmpfile = [IO.Path]::GetRandomFileName()
> PS> $tmpfile
> uxoqsxig.y01
> PS>
>
>
> "Hans Dingemans" <hansdingemans@xxxxxx> wrote in message
> news:ewSC9thBKHA.5068@xxxxxx
Quote:
Quote:

>>>>> I'll find some other convention to denote my disposable files.
>>
>> Strange, my V2 CTP3 help file suggests there's a New-Path cmdlet...
>>
>> C:\PS>new-path
>> C:\Users\admin1\AppData\Local\Temp\tmpD45F.tmp
>> C:\PS>
>>
>> ... but PowerShell does not recognize it. Online MSDN help does not
>> mention the cmdlet (anymore).
>>
>> In that case, you could use the .NET classes :-)
>>
>> PS> [IO.Path]::GetTempPath()
>> C:\Users\Hans Dingemans\AppData\Local\Temp\
>> PS>
>> PS> $tmpfile = [IO.Path]::GetTempFileName()
>> PS> $tmpfile
>> C:\Users\Hans Dingemans\AppData\Local\Temp\tmp3CE0.tmp
>> PS>
>>
>> Hth,
>> Hans
>>
>>
>> "Tim Munro" <Excelsior@xxxxxx> wrote in message
>> news:OC79C%23gBKHA.4336@xxxxxx
Quote:

>>> Thank you both Hans, and Larry. I've always used the '#' to indicate a
>>> temporary or transivitive file. Therefore if I "del #*" I have no
>>> worries. This also explains why my files need to be enclosed on quotes.
>>> I don't think I'll muck with the PS defaults. I'll find some other
>>> convention to denote my disposable files.
>>>
>>> --
>>> Tim.
>>>
>>> "Larry__Weiss" <lfw@xxxxxx> wrote in message
>>> news:OzIQgYJBKHA.1252@xxxxxx
>>>> Regarding the use of # in PowerShell V2
>>>>
>>>> # is a PS indicator that the rest of the line is a comment
>>>> For example
>>>> dir *.ps1 # comment
>>>>
>>>> You can have embeddded comments
>>>> dir <# comment #> *.ps1
>>>>
>>>> Or multiline comments
>>>> <#
>>>> comment line 1
>>>> comment line 2
>>>> #>
>>>>
>>>> - Larry
>>>>
>>>>
>>>> Tim Munro wrote:
>>>>> Hi all
>>>>> I've recently installed V2 CTP3. (never had CTP2). When type a
>>>>> command and then use TAB expansion to (for example) conplete and file
>>>>> name, I get the previously typed command and not the expanded
>>>>> filename(s). I've discovered that the problem seems to be the
>>>>> filenames that start with "#". PS requires that these names be
>>>>> enclosed in quotes, either single or double.
>>>>>
>>>>> I have a 4 or 5 file files named #missingxxx.txt. When I type dir
>>>>> '#m <tab> it cycles through all my previous commands rather than just
>>>>> the files starting with "#m". Does the "#" character mean anything
>>>>> special to PS? In PS v1 it worked just fine.
>>>>>
>>>>> --
>>>>> Confused.
>>>>>
>>>
>>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Networking result not as expected Vista networking & sharing
When is the next update expected? Any news? Live Mail
Expected release date for PS 2.0? PowerShell
When is a new release expected? Live Mail
April CTP Expected in the next few weeks Vista General


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