βββββββββββββββββββ βββ βββββββββββ ββββββββββ βββββββ
βββββββββββββββββββ βββ βββββββββββ ββββββββββββββββββββ
βββββ βββββββββββββββββββββββββββββββββ ββββββ ββββββ βββ
βββββ βββββββββββββββββββββββββββββββββ ββββββ ββββββ βββ
βββββββββββββββββββ βββ ββββββββββββββββββββββββββββββββββ
βββββββββββββββββββ βββ ββββββββ βββββββ βββββββ βββββββ
"One keypress β your last command, with sudo."
strykelang Β· zshrs Β· MenkeTechnologiesMeta Β· zsh-sed-sub Β· zsh-git-acp Β· zsh-more-completions Β· zpwr
A ZSH widget that toggles sudo on your current command line with a single keybind. No retyping. No arrow keys. Just pure privilege escalation at the speed of thought.
sudonot on the line? β it gets prependedsudoalready there? β it gets stripped (along withbuiltin,command,env, and all their args)- Empty line? β pulls your last command back from history and slaps
sudoon it
"The street finds its own uses for things." β William Gibson
zinit light MenkeTechnologies/zsh-sudogit clone https://github.com/MenkeTechnologies/zsh-sudo \
${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-sudoThen add zsh-sudo to your plugins array in ~/.zshrc.
source /path/to/sudo.plugin.zshWire up the ZLE widget to whatever key combo jacks you in fastest:
bindkey '^N' sudo-command-lineOverride the default sudo string by exporting these before the plugin loads:
export ZPWR_SUDO_REGEX='doas'
export ZPWR_SUDO_CMD='doas'Set both to the same string for a single tool; ZPWR_SUDO_REGEX may be an alternation (e.g.
sudo|doas) while ZPWR_SUDO_CMD stays one command.ZPWR_SUDO_CMDis what gets prepended;ZPWR_SUDO_REGEXis what the parser hunts for when stripping.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β INPUT STATE ACTION OUTPUT β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β $ apt update βββΊ prepend sudo βββΊ $ sudo apt update β
β $ sudo apt update βββΊ strip sudo βββΊ $ apt update β
β $ (empty) βββΊ recall + sudo βββΊ $ sudo <last cmd> β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
The regex engine handles edge cases like quoted commands, builtin/command prefixes, env with flags, variable assignments before sudo, and stacked sudo options (-u root -E, etc).