So, I am having a problem with some cli programs. Sometimes, when I kill the current process with Ctrl+ C, it leaves the terminal in a strange state (for example, the echo is off). Now this can be expected in many cases, since killing the process does not allow it to restore the state of the terminal. But I found that for many other cases, shutting down bash is the culprit. As an example, try the following:
- Start a new bash session as follows:
bash --norcto ensure that no terminations are downloaded. - Determine completion of the function:
_completion_test() { grep -q foo /dev/null; return 1; }. - Determine the execution, using the above functions:
complete -F _completion_test rlwrap. - Enter exactly the following: r l w r a p Space C a t Tab Enter(i.e.
rlwrap catafter on a Taband then on Enter). - Wait a second, and then start the process with Ctrl+ C.
- Terminal echo should not be disabled. Therefore, if you type any character, it will not be displayed by the echo terminal.
What is really strange is that if I remove the seemingly harmless grep -q foo /dev/nullfrom the completion function, everything will work correctly. In fact, adding grep -q foo /dev/null(or even something even simpler, such as cat /dev/null) to any completion function that was installed on my system causes the same problem. I also reproduced the problem with programs that do not use readlinewithout Ctrl+ C(for example find /var Tab | head, and the above termination is defined for find).
Why is this happening?
Change . To clarify, the above example. Actually, what I'm trying to do is more like this:
_completion_test() {
if grep -q "$1" /some/file; then
else
fi
}
For a more specific example, try the following:
_completion_test() {
if grep -q foo /dev/null; then
COMPREPLY=(cats)
else
return 1
fi
}
, grep, . , grep .