Press Esc Esc to instantly prepend sudo to your current command line — no retyping, no copy-paste.
$ apt update ← you type this
$ sudo apt update ← after pressing Esc Esc
- bash 3.0+ (the script does not support
sh,zsh,fish, or other shells) - A Unix-like system (Linux, macOS, WSL)
The installer will:
- Verify you are running bash.
- Create
~/.bashrcif it does not exist. - Back up your existing
~/.bashrcto~/.bashrc.autosudo.bak. - Append the AutoSudo block, clearly delimited by markers, to
~/.bashrc.
curl -sSL https://raw.githubusercontent.com/insanerask77/bash_sudo_funtion/main/install.sh | bashwget -qO- https://raw.githubusercontent.com/insanerask77/bash_sudo_funtion/main/install.sh | bashgit clone https://github.com/insanerask77/bash_sudo_funtion.git
cd bash_sudo_funtion
bash install.shAfter installation, reload your shell configuration:
source ~/.bashrcOr simply open a new terminal.
- Type any command in your terminal.
- Press Esc twice.
sudois prepended and your cursor is repositioned after it.
| Before | After Esc Esc |
|---|---|
apt update |
sudo apt update |
systemctl restart nginx |
sudo systemctl restart nginx |
nano /etc/hosts |
sudo nano /etc/hosts |
If the command already starts with
sudo, pressing Esc Esc has no effect.
The installer appends the following block to ~/.bashrc:
# BEGIN AUTOSUDO - DO NOT EDIT THIS BLOCK
_autosudo() {
if [[ "$READLINE_LINE" != sudo\ * ]]; then
READLINE_LINE="sudo $READLINE_LINE"
READLINE_POINT=$(( READLINE_POINT + 5 ))
fi
}
bind -x '"\e\e": _autosudo'
# END AUTOSUDO - DO NOT EDIT THIS BLOCKbind -x maps the double-Escape sequence (\e\e) to the _autosudo shell function. The function modifies READLINE_LINE (the current input buffer) and advances READLINE_POINT (the cursor) by 5 characters — the length of "sudo ".
The uninstaller removes the AutoSudo block from ~/.bashrc using the delimiters written at install time.
curl -sSL https://raw.githubusercontent.com/insanerask77/bash_sudo_funtion/main/uninstall.sh | bashwget -qO- https://raw.githubusercontent.com/insanerask77/bash_sudo_funtion/main/uninstall.sh | bashbash uninstall.shThen reload your shell:
source ~/.bashrcOpen ~/.bashrc in any editor and delete the block between:
# BEGIN AUTOSUDO - DO NOT EDIT THIS BLOCK
and:
# END AUTOSUDO - DO NOT EDIT THIS BLOCK
including both marker lines. To restore the backup created at install time:
cp ~/.bashrc.autosudo.bak ~/.bashrc
source ~/.bashrcContributions, bug reports, and feature requests are welcome.
- Fork the repository.
- Create a feature branch:
git checkout -b feature/my-improvement - Commit your changes:
git commit -m "feat: describe change" - Push and open a Pull Request.
Please run ShellCheck on any modified scripts before submitting.
This project is licensed under the MIT License.
Copyright (c) 2024 insanerask77.