How to make bash's "bind" commands completely invisible?

Viewed 173

I have the following lines in my .bashrc:

# C-Z shortcut can be used to take a suspended job to fg
stty susp undef
bind '"\C-z":" fg >/dev/null 2>&1 \015"'

The purpose of this was to make the binding C-Z better suspend Vim (as it already does as default within Vim), and then use C-Z in the bash command line interface to get back to Vim immediately.

This seems to be working perfectly except for one thing:

me:~$ vim ~/.bashrc

[1]+  Stopped                 vim ~/.bashrc
me:~$  fg >/dev/null 2>&1
me:~$  fg >/dev/null 2>&1
me:~$  fg >/dev/null 2>&1
me:~$  fg >/dev/null 2>&1
me:~$  fg >/dev/null 2>&1
me:~$

fg >/dev/null 2>&1 shows up every time. Is there any way to make this binding "silent" so that no output is shown at all? Many guides use zsh or fish to achieve this kind of behaviour, but I wish to stick to bash.

1 Answers

This should work for you:

stty susp undef
bind -x '"\C-z":"fg >/dev/null 2>&1"'

Keep in mind though that this might not be such a good idea, since it'll prevent you from suspending most other programs.

Related