To reset your terminal, you can call reset
from your shell, which is generally included with the target operating systems.
If you want to reset when you are not at a shell prompt (i.e., inside some other application), we can send an escape sequence in another way.
As an example, we can send a special escape sequence to the Nth tty:
echo -e "\ec" > /dev/pts/$N
Since Alacritty supports keybindings to execute arbitrary scripts, it is possible to map this reset action to some key combination.
This can be 1️⃣ wrapped into a script, which 2️⃣ Alacritty can be configured to execute.
You can use the script below to send the desired escape code.
ℹ️ First, the script extracts the PID of Alacritty from a known environment variable, ALACRITTY_LOG
.
ℹ️ ALACRITTY_LOG
has the form /tmp/Alacritty-1234.log
, where 1234
corresponds to the process ID of Alacritty.
Copy the script to some well known location, for example bin
in your home directory.
#!/bin/sh
if [ -z "${ALACRITTY_LOG}" ]; then exit 1; fi
TERM_PID="${ALACRITTY_LOG//[^0-9]/}"
tty=$(ps o tty= --ppid $TERM_PID)
echo -e "\ec" > /dev/$tty
In your alacritty.yml
config, add a keybind to the script. For example, to bind CTRL+K
to the reset action, add the following to the key_bindings
section:
- { key: K, mods: Ctrl, command: path/to/reset-alacritty }
🎉 And you're all set. The rest of this doc just contains some info for the curious.
The config can be just the name of the script if your PATH
is set load your expected binaries correctly.
- { key: K, mods: Ctrl, command: reset-alacritty }
If you are on Linux and using X11, this alternative script using xdotool
should be compatible with any given terminal emulator.
#!/bin/sh
focus_pid=$(xdotool getactivewindow getwindowpid)
tty=$(ps o tty= --ppid $focus_pid)
echo -e "\ec" > /dev/$tty
- 0.1: Initial document made for the Alacritty wiki
- Destroyed (i.e., rejected) from there
the script does not work on mac. is there any mac version or alternative?