Detect the presence of Bash completion in bash
Asked Answered
S

2

14

What is the way to detect if bash completion package is loaded in my bash shell? As of version 2.1 of bash-completion (included in Debian 8), there is no shell variable to indicate this except BASH_COMPLETION_COMPAT_DIR, which is not a reliable indicator.

Strongroom answered 10/3, 2016 at 16:14 Comment(1)
You have received several answers to your questions, yet have never accepted an answer as correct or helpful. You might want to evaluate them and where possible accept them as correct or helpful.Lani
L
11

You can use the complete command with the -p option to get a list of all or specific completions. I'm not sure how reliable this would be either, given that you can load and unload them at will.

complete -p

One other option is to check for one of the more unique function names with the type command and see if it's a function.

type -t _get_comp_words_by_ref

This question and answer may also provide some insight.

Lani answered 10/3, 2016 at 17:33 Comment(0)
S
2
  1. Go to a directory that has both files and subdirectories.

  2. Type cd <TAB><TAB> and look at the list of autocomplete results.

If the autocomplete results contain directories only (no files), then Bash Completion is installed.

If the autocomplete results include files, then Bash Completion is not installed. (An example is if you try this in a Docker Ubuntu container).

Saintmihiel answered 8/7, 2019 at 18:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.