scp/rsync autocomplete can hang if command-not-found enabled
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
command-not-found |
New
|
Undecided
|
Unassigned |
Bug Description
Referencing my post at http://
AlexO'Neill wrote:
>Here is my scenario:
>
>I want to transfer ~/foo.txt to a server aoneill@bar.
>
>I start typing in my command line:
>
>aoneill@
>
>At this point I hit <tab> to complete the file name, and my terminal just freezes up. It won't change based on any keystroke, and the cursor is just stuck right next to the fo, unless I <ctrl-C> out.
>
Using set -x shows that the autocomplete was hanging on ruptime.
$ set -x
$ scp fo local cur prev words cword
+ _init_completion -n :
...
+ COMPREPLY+=($( compgen -W "$( ruptime 2>/dev/null | awk '!/^ruptime:/ { print $1 }' )" -- "$cur" ))
+++ ruptime
+++ awk '!/^ruptime:/ { print $1 }'
When I tried to run ruptime myself I found that it wasn't installed. After installing the rwho package the hang was fixed.
sudo apt-get install rwho
The COMPREPLY line calls ruptime without checking to see if it exists. And since I have 'COMMAND_
So the bug happens because command-not-found doesn't check if its being used in a pipe.
The simplest reproduction of this bug was running the following command "wdf 2>/dev/null | grep asdf" assuming wdf isn't installed and is a valid command.
I've attached an example patch that checks whether the command is attached to a real terminal before continuing.