Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

bash

vim

suspend

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.

like image 588
herophant Avatar asked Dec 01 '25 10:12

herophant


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.

like image 78
ruohola Avatar answered Dec 04 '25 04:12

ruohola