akinomyoga / ble.sh

Bash Line Editor―a line editor written in pure Bash with syntax highlighting, auto suggestions, vim modes, etc. for Bash interactive sessions.
BSD 3-Clause "New" or "Revised" License
2.58k stars 82 forks source link

Don't automatically trigger completions for certain directories #410

Closed dgudim closed 7 months ago

dgudim commented 7 months ago

How to turn off automatic completions for some directories (/bin, /usr/bin, /lib) because it takes A LOT of time. I want to only trigger the completions when I press tab

akinomyoga commented 7 months ago

Depending on the situation, there are several options. I'm not sure which would be the best one in your environment because the bottleneck would be different in different environments, so you probably need to try them to see if it works for you.

Option 1: limit the number of candidates in the background processing

One option is to limit the number of candidates by the complete_limit_auto option. If the generated number surpasses the configured value, the processing of auto-complete is canceled in the middle. The default value is 2000, so you can specify a less number. For example, if you want to limit it under 100, you can put the following setting:

# blerc

bleopt complete_limit_auto=2000

However, this might not work, if the generation stage is the bottleneck.

Option 2: add a delay

Another option is to add a delay for starting auto-complete in the background using the config complete_auto_delay. This is actually not what you requested, but it might solve the problem. For example, if you want to set the delay of 300 milliseconds, you can put the following setting:

# blerc

bleopt complete_auto_delay=300

Option 3: completely turn off auto-complete

Or maybe you don't want auto-complete in any directories? In that case, you can just turn off the feature using the complete_auto_complete option:

# blerc

bleopt complete_auto_complete=

Option 4: blehook CHPWD

Or, the most flexible option would be to dynamically change the setting in blehook CHPWD. CHPWD is the hook that is called when the current working directory is changed after the execution of a user command.

# blerc

blehook CHPWD!='my/blerc/update-settings'
function my/blerc/update-settings {
  if [[ $PWD == /usr/bin || $PWD == /lib || $PWD == /bin ]]; then
    # turn off auto-complete
    bleopt complete_auto_complete=
  else
    # turn on auto-complete
    bleopt complete_auto_complete=1
  fi
}
dgudim commented 7 months ago

I already tried the delay and limiting the candidates. The CHPWD is the perfect solution! Thanks :) works like a charm