Turn off terminal bell in man pages and less

belllessmanxterm

I'm wondering if there's a way to turn off the terminal bell for terminal applications such as man and less, e.g. when you're already at the top of the file/man page and press "k" to attempt to scroll up. Normally, I'd just turn off the bell on my terminal emulator altogether, but the popular xset b off command doesn't seem to be working for my setup: I'm running XTerm from Ubuntu 16.04 (specifically, in WSL) over X11 forwarding to Xming. So I'd also appreciate any notes on how to turn off XTerm's bell, too, if that's available.

I'm aware of how to turn off readline's bell by putting set bell-style none in ~/.inputrc, but unfortunately that only helps for input (e.g. multiple available tab completions), not for when scrolling man/less pages.

I'm also aware of the -Q command line arg to less which turns off the bell, but I guess I'm hoping that there's a more general setting/command that will apply to both man and less (and possibly others).

I figure if I can't turn off XTerm's bell altogether, I'll try and learn how to turn off each application's bell, one by one, until I get at least all of the annoying ones.

Best Answer

man uses your default pager, which on Ubuntu (and most other systems) is less. You can change this, but you would likely know you did. That's why the interface in which you page through man's formatted output looks and feels like less: it is. After man formats the manpage, it uses less to display it. So what you probably want is to make less always behave as though the -Q option had been passed to it, including when it is used by man and other programs.

When less runs, it examines the LESS environment variable for options to use in addition to those passed to it in command-line arguments. So you can put this in one of the scripts that gets sourced when you open a WSL command prompt:

export LESS=-Q

Or you might prefer this, which preserves any options already present in the LESS variable. Usually this is unnecessary because that variable is not usually defined already anyway, but this still works even if it isn't:

export LESS="$LESS -Q"

Most Ubuntu users will want to set this and and other environment variables in their ~/.profile file. (There is also a way with ~/.pam_environment that some people prefer, which uses a different syntax.) This is what I would recommend for you, too, if the shell WSL gives you is a login shell, which on recent builds (or if you have configured it to be) it should be.

You can check this by running shopt login_shell in the shell provided when you open a WSL command prompt window. If it's not a login shell and you don't want to add -l or --login to the Windows shortcut, then put one of those export commands in .bashrc instead of .profile.