doas-zsh-plugin

July 21, 2026 ยท View on GitHub

Easily prefix your current or previous commands with doas (or other privilege escalation tool) by pressing esc twice

This is fork of OMZ's sudo plugin.

Installation

Plain zsh

Clone this repository to any location on your PC, then add to your .zshrc:

source /path/to/repo/doas-zsh-plugin.plugin.zsh

With Antidote

Add the following line to your plugins file:

Senderman/doas-zsh-plugin

Configuration

By default, this plugin uses to add/remove doas command. If you need different command (e.g. sudo), set this command in SUDOBIN environment variable, e.g.

export SUDOBIN=sudo

Usage

Currently typed commands

Say you have typed a long command and forgot to add doas in the beginning:

$ apt-get install build-essential

By pressing the esc key twice, you will have the same command with doas prefixed:

$ doas apt-get install build-essential

Previously executed commands

Say you wanted to see the contents of a system file:

$ cat some-system-file.txt
cat: some-system-file.txt: Permission denied

By pressing the esc key twice, you will have the latest command from the history with doas prefixed:

$ cat some-system-file.txt
cat: some-system-file.txt: Permission denied
# press ESC twice
$ doas cat some-system-file.txt

doas is already in the beginning of the line

Say you already have doas in the beginning of the line:

$ doas ls

To remove it, press esc key twice:

$ ls