2

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.

6

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.

  • 1
    Setting LESS to -Q worked like a charm; thanks! – villapx Apr 9 '18 at 14:36
  • Note for others: you'll probably also want to add the -R option in there (e.g. export LESS="$LESS -Q -R") or you'll experience the symptoms seen in this question when trying to view git diff – villapx Apr 9 '18 at 14:58
1

xterm has a visual bell option, to flash the terminal instead of ringing the bell. Use option -vb or set in your ~/.Xdefaults

XTerm*visualBell:true

or echo the same into xrdb -merge

  • For the text editor VIM, the canonical way to turn off the bell is to first tell VIM to use the visual bell instead of the audible bell (set visualbell, similar to doing XTerm*visualBell: true), then to turn off the visual bell (set t_vb=). As far as I can tell, there's nothing like the latter in XTerm...is there? – villapx Apr 9 '18 at 20:10
  • 1
    No, I don't think so. You can reduce the flash to a single line with XTerm*visualBellLine:true. – meuh Apr 9 '18 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.