aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/completion.bash
blob: 1246ba3157d04fec85ab9413d9f892933e7f1609 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Various easy completions for Bash builtins; more specific stuff goes in
# ~/.bash_completion.d

# Bash builtins
complete -A builtin builtin

# Bash options
complete -A setopt set

# Commands
complete -A command command complete coproc exec hash type

# Directories
complete -A directory cd pushd mkdir rmdir

# Functions
complete -A function function

# Help topics
complete -A helptopic help

# Jobspecs
complete -A job disown fg jobs
complete -A stopped bg

# Readline bindings
complete -A binding bind

# Shell options
complete -A shopt shopt

# Signal names
complete -A signal trap

# Variables
complete -A variable declare export readonly typeset

# Both functions and variables
complete -A function -A variable unset

# If we have dynamic completion loading (Bash>=4.0), use it
if ((BASH_VERSINFO[0] >= 4)) ; then

    # Handler tries to load appropriate completion for commands
    _completion_loader() {
        [[ -n $1 ]] || return
        local compspec
        compspec=$HOME/.bash_completion.d/$1.bash
        [[ -f $compspec ]] || return
        source "$compspec" >/dev/null 2>&1 && return 124
    }
    complete -D -F _completion_loader -o bashdefault -o default

# If not, load all of the completions up now
else
    for sh in "$HOME"/.bash_completion.d/*.bash ; do
        [[ -e $sh ]] && source "$sh"
    done
    unset -v sh
fi