microsoft / microsoft/sudo

support `sudo !!` to run the last command

Open
#6 4 comments 12 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue-Feature
Dominant language
Rust
Stars
5.9k
Forks
180
Avg merge
1d 7h
Merged PRs (30d)
2

Description

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 GetConsoleCommandHistory[^1], 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.

[^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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining how the Rust project handles command execution on Windows, then investigate CMD.exe's GetConsoleCommandHistory and the PsReadline history path described in the issue. Check issue #6 for the PowerShell module dependency. Done means sudo !! can rerun the last command in the supported CMD and PowerShell environments, with behavior verified for each shell.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell, rust
Domain
cli, operating-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.