blob: 83ddfbc45749dad804dc7611dcb9caeb29fd8423 [file] [log] [blame]
Nils Winkler4261f3d2012-11-13 14:16:21 +01001#!/usr/bin/env bash
2
3_bash-it-comp-enable-disable()
4{
5 local enable_disable_args="alias plugin completion"
6 COMPREPLY=( $(compgen -W "${enable_disable_args}" -- ${cur}) )
7}
8
9_bash-it-comp-list-available-not-enabled()
10{
11 subdirectory="$1"
12
13 local available_things=$(for f in `ls -1 $BASH_IT/$subdirectory/available/*.bash`;
14 do
15 if [ ! -e $BASH_IT/$subdirectory/enabled/$(basename $f) ]
16 then
17 basename $f | cut -d'.' -f1
18 fi
19 done)
20
21 COMPREPLY=( $(compgen -W "all ${available_things}" -- ${cur}) )
22}
23
24_bash-it-comp-list-enabled()
25{
26 subdirectory="$1"
27
28 local enabled_things=$(for f in `ls -1 $BASH_IT/$subdirectory/enabled/*.bash`;
29 do
30 basename $f | cut -d'.' -f1
31 done)
32
33 COMPREPLY=( $(compgen -W "all ${enabled_things}" -- ${cur}) )
34}
35
36_bash-it-comp-list-available()
37{
38 subdirectory="$1"
39
40 local enabled_things=$(for f in `ls -1 $BASH_IT/$subdirectory/available/*.bash`;
41 do
42 basename $f | cut -d'.' -f1
43 done)
44
45 COMPREPLY=( $(compgen -W "${enabled_things}" -- ${cur}) )
46}
47
48_bash-it-comp()
49{
50 local cur prev opts prevprev
51 COMPREPLY=()
52 cur="${COMP_WORDS[COMP_CWORD]}"
53 prev="${COMP_WORDS[COMP_CWORD-1]}"
54
55 opts="help show enable disable"
56
57 case "${prev}" in
58 show)
59 local show_args="plugins aliases completions"
60 COMPREPLY=( $(compgen -W "${show_args}" -- ${cur}) )
61 return 0
62 ;;
63 help)
64 local help_args="plugins aliases"
65 COMPREPLY=( $(compgen -W "${help_args}" -- ${cur}) )
66 return 0
67 ;;
68 enable)
69 _bash-it-comp-enable-disable
70 return 0
71 ;;
72 disable)
73 _bash-it-comp-enable-disable
74 return 0
75 ;;
76 aliases)
77 prevprev="${COMP_WORDS[COMP_CWORD-2]}"
78
79 case "${prevprev}" in
80 help)
81 _bash-it-comp-list-available aliases
82 return 0
83 ;;
84 esac
85 ;;
86 alias)
87 prevprev="${COMP_WORDS[COMP_CWORD-2]}"
88
89 case "${prevprev}" in
90 enable)
91 _bash-it-comp-list-available-not-enabled aliases
92 return 0
93 ;;
94 disable)
95 _bash-it-comp-list-enabled aliases
96 return 0
97 ;;
98 esac
99 ;;
100 plugin)
101 prevprev="${COMP_WORDS[COMP_CWORD-2]}"
102
103 case "${prevprev}" in
104 enable)
105 _bash-it-comp-list-available-not-enabled plugins
106 return 0
107 ;;
108 disable)
109 _bash-it-comp-list-enabled plugins
110 return 0
111 ;;
112 esac
113 ;;
114 completion)
115 prevprev="${COMP_WORDS[COMP_CWORD-2]}"
116
117 case "${prevprev}" in
118 enable)
119 _bash-it-comp-list-available-not-enabled completion
120 return 0
121 ;;
122 disable)
123 _bash-it-comp-list-enabled completion
124 return 0
125 ;;
126 esac
127 ;;
128 esac
129
130 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
131
132 return 0
133}
134
135complete -F _bash-it-comp bash-it