-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Steps to reproduce:
- Run
notepad $PROFILEin powershell - Copy and paste
function Sample {
Write-Output "Sample"
}
Set-Alias -Name example -Value Sample
at the end of file, without trailing whitespaces or line breaks. Save the file.
3. Run twc --install-completion in a new terminal.
4. The block gets directly appended to the existing configuration, breaking both involved parts
Expected behavior:
The completion block should be added on a new line, preserving the existing alias configuration.
Actual behavior:
The completion block is concatenated directly to -Value Sample, creating invalid syntax:
Set-Alias -Name example -Value SampleImport-Module PSReadLine
Set-PSReadLineKeyHandler -Chord Tab -Function MenuComplete
$scriptblock = {
...and producing an error in a fresh terminal session:
Set-Alias : A positional parameter cannot be found that accepts argument 'PSReadLine'.
At A:\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:67 char:1
+ Set-Alias -Name example -Value SampleImport-Module PSReadLine
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-Alias], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetAliasCommand
The gist:
Best practices recommend ending files with a trailing newline, but real-world configuration files frequently don't follow this convention, and robust installation scripts must handle all cases.
And it did in fact break my existing powershell profile, which I had to fix manually afterwards.
Possible solutions:
- Use the PowerShell's built-in
Add-Contentcmdlet to correctly append to the powershell profile - Alternatively, prefix the appended content with
`r`nto guarantee separation.