You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a parameter to Read-Host to allow prefilling the edit buffer #14013
In-PRIndicates that a PR is out for the issueIssue-Enhancementthe issue is more of a feature request than a bugUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendation
It would improve the end-user experience if a Read-Host call were allowed to pre-fill the edit buffer with a default value that the user can either accept as-is or modify:
# WISHFUL THINKING$var=Read-Host-Prompt 'Enter a path'-DefaultValue '/path/to/default/location'
The user would then see:
Enter a path: /path/to/default/location
with the cursor at the end of the value, allowing them to press Enter to accept the default value as-is, or modify the value as needed.
Proposed technical implementation details
If PSReadLine's PSConsoleHostReadLine function were to be enhanced to become a general-purpose prompting function, as proposed in issue #881, the implementation of -DefaultValue could build on that.
This could also open the door for additional enhancements, such as history recall from a custom history file specified via another new parameter.
Reacted by PRASOON KARUNAN V, Andjin, eabase, noamper, Edouard Shamis, 0x0309, Armaan Mcleod, sharpchen and Gene
Thanks, Ilya (@iSazonov), but I see nothing about the ability to pre-fill (pre-populate) the edit buffer in the linked issue, and the WinAPI's ReadConsole function also doesn't seem to support it,
Thanks, Ilya (@iSazonov); since I'm not familiar with the ReadConsole function, let me see if my understanding is correct (happy to hide this comment once we have clarity):
You're saying that ReadConsole's lpBuffer parameter, despite being documented as _Out_ and only receiving data, can de facto also be used to pre-populate the buffer?
In other words: the documentation should be amended to note that, right?
Thanks, Ilya (@iSazonov). I see that you can specify an offset into the buffer, so that ReadConsole copies input starting there, but does that mean that the function is still capable of modifying the content before that offset based on user actions (which is crucial for the functionality I'm looking for)?
(P.S.: There's a grammatical error in one of the variable names: charsReaded should be charsRead).
but does that mean that the function is still capable of modifying the content before that offset based on user actions (which is crucial for the functionality I'm looking for)?
It is my understanding how the code works: we always set the pre-populated buffer.
Also we can edit an input line on Windows :-)
eabase, whatever lower-level features may or may not be available to implement this feature request (I'm still unclear on that part), it hasn't been implemented.
The first step toward that would be for the cmdlets working group to decide on whether the feature is worth implementing.
The issue has been labeled accordingly ("WG-Cmdlets-Utility"), but, unfortunately, there's no telling when this decision will be made.
I presume that the level of community interest helps with prioritizing issues - though I don't know if there's a tool-assisted process for that (such as sorting by the number of thumbs-up votes).
As of this writing, there are 31 feature requests awaiting triage by the cmdlets working group, the oldest dating back to Feb 2021:
The query explicitly excludes issues that also have an "Up-for-Grabs" label, given that this label implies that an issue has been triaged; such issues should no longer have the "Needs-Triage" label, but I guess there's no automated process to remove the latter.
The "In-PR" label by itself does not imply that the issue has been triaged, given that it is automatically assigned when an issue is referenced from a PR and given that a PR may be a user's unilateral initiative.
Does this mean that the working groups will not pay attention to untriaged items that lack the "Neeeds-Triage" label, or is the "WG-*" label alone enough (in the absence of additional labels that imply completed triage)?
If the "Needs-Triage" label is required for the working groups to pay attention to and triage items, then all the issues returned by the query above should be labeled with it.
I did a workaround by using Set-Clipboard, maybe this solution works for somebody else too. $defaultConnString = "Server=$hostname\$sqlInstance;Database=Demo; User Id=######;Password=######;" Set-Clipboard -Value $defaultConnString $connString = Read-Host "ConnectionString is copied to Clipboard, paste and edit"
Reacted by eabase, Nick S, Seuong and Eric Eskildsen
In-PRIndicates that a PR is out for the issueIssue-Enhancementthe issue is more of a feature request than a bugUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendation
Activity
iSazonov commentedon Nov 9, 2020
I think it would be better to implement this in .Net Runtime. I opened an issue for this there.
mklement0 commentedon Nov 9, 2020
Ilya (@iSazonov), you've already opened an issue there? If so, please link to it.
I also wonder what support we need for hosts other than the console (terminal), which would definitely have to be implemented on the PowerShell side.
iSazonov commentedon Nov 10, 2020
The issue dotnet/runtime#800
mklement0 commentedon Nov 11, 2020
Thanks, Ilya (@iSazonov), but I see nothing about the ability to pre-fill (pre-populate) the edit buffer in the linked issue, and the WinAPI's
ReadConsolefunction also doesn't seem to support it,iSazonov commentedon Nov 12, 2020
Michael Klement (@mklement0) The function uses the input buffer as edit buffer and it can be pre-populated.
mklement0 commentedon Nov 12, 2020
Thanks, Ilya (@iSazonov); since I'm not familiar with the
ReadConsolefunction, let me see if my understanding is correct (happy to hide this comment once we have clarity):You're saying that
ReadConsole'slpBufferparameter, despite being documented as_Out_and only receiving data, can de facto also be used to pre-populate the buffer?In other words: the documentation should be amended to note that, right?
iSazonov commentedon Nov 12, 2020
Michael Klement (@mklement0) Please look our
internal static string ReadConsole()method and how it utilizes InitialChars.mklement0 commentedon Nov 12, 2020
Thanks, Ilya (@iSazonov). I see that you can specify an offset into the buffer, so that
ReadConsolecopies input starting there, but does that mean that the function is still capable of modifying the content before that offset based on user actions (which is crucial for the functionality I'm looking for)?(P.S.: There's a grammatical error in one of the variable names:
charsReadedshould becharsRead).iSazonov commentedon Nov 12, 2020
It is my understanding how the code works: we always set the pre-populated buffer.
Also we can edit an input line on Windows :-)
eabase commentedon Jun 1, 2023
Ilya (@iSazonov)
So does this mean that this issue is redundant, fixed, or something else?
mklement0 commentedon Jun 1, 2023
eabase, whatever lower-level features may or may not be available to implement this feature request (I'm still unclear on that part), it hasn't been implemented.
The first step toward that would be for the cmdlets working group to decide on whether the feature is worth implementing.
The issue has been labeled accordingly ("WG-Cmdlets-Utility"), but, unfortunately, there's no telling when this decision will be made.
I presume that the level of community interest helps with prioritizing issues - though I don't know if there's a tool-assisted process for that (such as sorting by the number of thumbs-up votes).
As of this writing, there are 31 feature requests awaiting triage by the cmdlets working group, the oldest dating back to Feb 2021:
https://github.com/PowerShell/PowerShell/issues?q=is%3Aopen+label%3AWG-Cmdlets-Utility+label%3Aneeds-triage+label%3Aissue-enhancement+-label%3Aup-for-grabs+
Note:
The query explicitly excludes issues that also have an "Up-for-Grabs" label, given that this label implies that an issue has been triaged; such issues should no longer have the "Needs-Triage" label, but I guess there's no automated process to remove the latter.
The "In-PR" label by itself does not imply that the issue has been triaged, given that it is automatically assigned when an issue is referenced from a PR and given that a PR may be a user's unilateral initiative.
mklement0 commentedon Jun 1, 2023
Come to think of it, Ilya (@iSazonov):
There are many feature requests - this one among them - that do NOT have the "Needs-Triage" label, yet clearly haven't been triaged.
As of this writing, there are 62 such issues (with certain labels that do imply triage having taking place excluded):
https://github.com/PowerShell/PowerShell/issues?page=3&q=is%3Aopen+label%3AWG-Cmdlets-Utility+label%3Aissue-enhancement+-label%3Aneeds-triage+-label%3Aup-for-grabs+-label%3A%22waiting+-+dotnetcore%22++-label%3A%22hacktoberfest-accepted%22
Does this mean that the working groups will not pay attention to untriaged items that lack the "Neeeds-Triage" label, or is the "WG-*" label alone enough (in the absence of additional labels that imply completed triage)?
If the "Needs-Triage" label is required for the working groups to pay attention to and triage items, then all the issues returned by the query above should be labeled with it.
hdave127 commentedon Oct 31, 2023
I did a workaround by using Set-Clipboard, maybe this solution works for somebody else too.
$defaultConnString = "Server=$hostname\$sqlInstance;Database=Demo; User Id=######;Password=######;"Set-Clipboard -Value $defaultConnString$connString = Read-Host "ConnectionString is copied to Clipboard, paste and edit"7 remaining items
iSazonov commentedon Sep 5, 2024
How could we input empty value?
0x0309 commentedon Sep 5, 2024
I thought the whole point was to be able to edit the default without having to re-type the entire value just to change one character...
eabase commentedon Sep 6, 2024
That's a good point, and perhaps adding a switch like
-SpaceIsEmpty?eabase commentedon Mar 9, 2025
Let's bump again in Sept. 2025?
phosjlusky commentedon Sep 4, 2025
What are people using as a workaround since Read-Host doesn't handle prefilling?
I'm sure there's something better than this:
eabase commentedon Sep 4, 2025
BUMP!
phosjlusky commentedon Mar 4, 2026
Has to be a better way than
$Value = bash.exe -c "read -e -p 'Enter a value: ' -i 'defaultvalue' ; echo \`$REPLY"