A tiny shell script that resets your terminal to a sane state.
Your terminal is broken if you see any of these:
- Cursor has disappeared
- Clicking or scrolling produces garbage like
^[[Mor^[[<35;12;5M - Mouse movement floods the terminal with escape sequences
- Pasting text produces garbled output or doubled characters
- Typing feels wrong or input is invisible
less,vim,top, or another program exited uncleanly and left things messy
Just run scrollfix and it goes back to normal.
-
Put the
scrollfixfile somewhere in your home directory (e.g.~/scrollfix) -
Make it executable:
chmod u+x ~/scrollfix- Run it whenever your terminal is messed up:
~/scrollfixThat's it. No flags, no options.
It fixes the terminal non-destructively — your screen contents and
scrollback are left untouched. (It deliberately avoids reset, which sends a
hard RIS that wipes the screen and scrollback.)
- Bails out if not run on a real terminal (safe to call from scripts/pipes)
stty sane— restores line discipline (echo, canonical mode, flow control)DECSTRsoft reset (\e[!p) — restores cursor, wrap, origin, insert mode, etc. to defaults without clearing anything- Ensures you're back on the main screen if a crashed TUI left you on the alternate buffer (restores it — does not clear it)
- Clears the modes a soft reset misses: bracketed paste, focus reporting, synchronized output, all mouse tracking, autowrap, keypad, charset (line-drawing → ASCII), scroll region, colors, cursor shape
- Drains any stale queued input (mouse/focus byte floods) until empty
bash (the input-flush loop uses read -t/-n, which POSIX sh/dash lack).
The #!/usr/bin/env bash shebang handles this on Linux and macOS alike.