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.
io-load-limit
mean its value is not important? 2. In my case, the hang only occurs in home directory, not in the subfolders. Is it possible to disable tab completion in home directory only? – wsdzbm Jul 19 '17 at 13:08io_load
is11
, then you assign the10
(or less) to theio-load-limit
. That is, it need be regulated depending on the tab completion behavior. I just picked10
, for testing. 2. Sure, change the if statement to something like this:if [[ "$io_load" > "$io_load_limit" && "$PWD" == "$HOME" ]]; then
. It will be checking the I/O load and the current working directory. – MiniMax Jul 19 '17 at 16:31