Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support sudo !! to run the last command #6

Open
Tracked by #5
zadjii-msft opened this issue Feb 6, 2024 · 4 comments
Open
Tracked by #5

support sudo !! to run the last command #6

zadjii-msft opened this issue Feb 6, 2024 · 4 comments
Labels
Issue-Feature New feature or request. Complex enough to require planning and actual budgeted, scheduled work.

Comments

@zadjii-msft
Copy link
Member

This is shockingly trivial for CMD.exe. CMD uses the built-in console line-editing, which means that commands run in CMD will use the console's own history buffer. That means sudo can just get the console history with GetConsoleCommandHistory1, to find the last run command.

PowerShell, on the other hand, uses PsReadline in the default configuration. That means we'll need the sudo powershell module (#6) to support sudo !! from powershell.

Footnotes

  1. Is this actually a private API or just an undocumented one? That's not super clear to me looking at https://github.com/microsoft/terminal/blob/ef96e225da6b0df496390eed9fe31dc7e434a939/src/server/ApiSorter.cpp#L109

@zadjii-msft zadjii-msft added the Issue-Feature New feature or request. Complex enough to require planning and actual budgeted, scheduled work. label Feb 6, 2024
@jantari
Copy link

jantari commented Feb 8, 2024

PowerShell already has $^ to access the last command, so sudo $^ should work too.

@joshtriplett
Copy link

I think it'd be a bad idea to support that directly in sudo, rather than supporting it in cmd (so that it works on any command line).

@zarlo
Copy link

zarlo commented Feb 9, 2024

$^ takes more work to type

@dongle-the-gadget
Copy link

Is this actually a private API or just an undocumented one?

GetConsoleCommandHistory is public, in the consoleapi3.h header in the Windows SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Feature New feature or request. Complex enough to require planning and actual budgeted, scheduled work.
Projects
None yet
Development

No branches or pull requests

5 participants