首页 > 解决方案 > 如何使 bash 的“绑定”命令完全不可见?

问题描述

我的 中有以下几行.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"'

这样做的目的是使绑定C-Z更好地挂起 Vim(正如它在 Vim 中已经默认所做的那样),然后C-Z在 bash 命令行界面中使用以立即返回到 Vim。

这似乎工作得很好,除了一件事:

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每次都出现。有没有办法让这个绑定“静默”,这样就根本不显示输出?许多指南使用 zsh 或 fish 来实现这种行为,但我希望坚持使用 bash。

标签: bashvimsuspend

解决方案


这应该适合你:

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

请记住,这可能不是一个好主意,因为它会阻止您暂停大多数其他程序。


推荐阅读