First idea - disable file name completions, while the disk is high loaded. It is affect only filenames, other completions stay working. Because, I think they doesn't cause hang.
Create file .bash_completion
in the home directory and put this code to there.
#!/bin/bash
### We are needed redefine original _filedir function
### and add new functionality to it
#
# for this, output the original function code and add the word 'original'
# in the beginning of it - now we are have _filedir renamed to
# 'original_filedir'
eval "original$(declare -f _filedir)"
# Define our own _filedir function, which will check disk load
# and:
# if load are low - call original function.
# if load are high - stop further execution.
_filedir() {
io_load_limit=10
io_load=$(awk '/sda /{print $12}' /proc/diskstats)
if ((io_load > io_load_limit)); then
echo -n "completion disabled - a lot i/o"
return
fi
original_filedir
}
Also, the same trick can be done with _completion-loader
function. It sets up dynamic completion loading.
In the Ubuntu, the main completion code resides in the /usr/share/bash-completion/bash_completion
file and others, customized for specific program, reside in the /usr/share/bash-completion/completions/
directory.
When bash
starts, it reads /usr/share/bash-completion/bash_completion
file, and then, if you are typing apt-get
, for example, _completion-loader
runs and loads apt-get
completion rules from the /usr/share/bash-completion/completions/apt-get
. It is also affect to I/O and can be cause of hanging.
I decided use /proc/diskstats for evaluating disk activity. You can use another way. Limit value was chosen randomly.
Second idea - setup limit for i/o usage, like this.