blob: 7f94174b9931b97c38a35a5145844c82a9e78e5b [file] [log] [blame]
Travis Swicegoodb524bb62012-03-26 11:19:38 -05001# Helper function loading various enable-able files
2function _load_bash_it_files() {
3 file_type="$1"
4 if [ ! -d "${BASH_IT}/${file_type}/enabled" ]
5 then
6 continue
7 fi
8 FILES="${BASH_IT}/${file_type}/enabled/*.bash"
9 for config_file in $FILES
10 do
11 if [ -e "${config_file}" ]; then
12 source $config_file
13 fi
14 done
15}
16
17# Function for reloading aliases
18function reload_aliases() {
19 _load_bash_it_files "aliases"
20}
21
22# Function for reloading auto-completion
23function reload_completion() {
24 _load_bash_it_files "completion"
25}
26
27# Function for reloading plugins
28function reload_plugins() {
29 _load_bash_it_files "plugins"
30}
Erich Smith254d4452012-05-11 14:25:24 -040031
Nils Winkler1f558e22012-05-21 13:24:49 +020032bash-it-aliases ()
33{
34 about 'summarizes available bash_it aliases'
35 group 'lib'
36
37 _bash-it-describe "aliases" "an" "alias" "Alias"
38}
39
40bash-it-completions ()
41{
42 about 'summarizes available bash_it completions'
43 group 'lib'
44
45 _bash-it-describe "completion" "a" "completion" "Completion"
46}
47
Erich Smith08e439c2012-05-13 08:37:31 -040048bash-it-plugins ()
Erich Smith254d4452012-05-11 14:25:24 -040049{
Erich Smith08e439c2012-05-13 08:37:31 -040050 about 'summarizes available bash_it plugins'
51 group 'lib'
Nils Winkler1f558e22012-05-21 13:24:49 +020052
53 _bash-it-describe "plugins" "a" "plugin" "Plugin"
54}
55
56_bash-it-describe ()
57{
58 about 'summarizes available bash_it plugins'
59 group 'lib'
60
61 file_type="$1"
62 preposition="$2"
63 command_suffix="$3"
64 column_header="$4"
Erich Smith254d4452012-05-11 14:25:24 -040065
66 typeset f
67 typeset enabled
Nils Winkler1f558e22012-05-21 13:24:49 +020068 printf "%-20s%-10s%s\n" "$column_header" 'Enabled?' 'Description'
69 for f in $BASH_IT/$file_type/available/*.bash
Erich Smith254d4452012-05-11 14:25:24 -040070 do
Nils Winkler1f558e22012-05-21 13:24:49 +020071 if [ -e $BASH_IT/$file_type/enabled/$(basename $f) ]; then
Erich Smith254d4452012-05-11 14:25:24 -040072 enabled='x'
73 else
74 enabled=' '
75 fi
Nils Winklerf71be202012-05-21 15:52:03 +020076 printf "%-20s%-10s%s\n" "$(basename $f | cut -d'.' -f1)" " [$enabled]" "$(cat $f | metafor about-$command_suffix)"
Erich Smith254d4452012-05-11 14:25:24 -040077 done
Nils Winkler1f558e22012-05-21 13:24:49 +020078 printf '\n%s\n' "to enable $preposition $command_suffix, do:"
79 printf '%s\n' "$ enable-$command_suffix <$command_suffix name> -or- $ enable-$command_suffix all"
80 printf '\n%s\n' "to disable $preposition $command_suffix, do:"
81 printf '%s\n' "$ disable-$command_suffix <$command_suffix name> -or- $ disable-$command_suffix all"
Erich Smith254d4452012-05-11 14:25:24 -040082}
83
Erich Smith08e439c2012-05-13 08:37:31 -040084disable-plugin ()
Erich Smith254d4452012-05-11 14:25:24 -040085{
Erich Smith08e439c2012-05-13 08:37:31 -040086 about 'disables bash_it plugin'
87 param '1: plugin name'
Erich Smith70e1cd32012-05-14 14:12:09 -040088 example '$ disable-plugin rvm'
Erich Smith08e439c2012-05-13 08:37:31 -040089 group 'lib'
Nils Winkler1f558e22012-05-21 13:24:49 +020090
91 _disable-thing "plugins" "plugin" $1
92}
Erich Smith254d4452012-05-11 14:25:24 -040093
Nils Winkler1f558e22012-05-21 13:24:49 +020094disable-alias ()
95{
96 about 'disables bash_it alias'
97 param '1: alias name'
98 example '$ disable-alias git'
99 group 'lib'
100
101 _disable-thing "aliases" "alias" $1
102}
103
104disable-completion ()
105{
106 about 'disables bash_it completion'
107 param '1: completion name'
108 example '$ disable-completion git'
109 group 'lib'
110
111 _disable-thing "completion" "completion" $1
112}
113
114_disable-thing ()
115{
116 file_type="$1"
117 command_suffix="$2"
118 file_entity="$3"
119
120 if [ -z "$file_entity" ]; then
121 reference "disable-$command_suffix"
Erich Smith254d4452012-05-11 14:25:24 -0400122 return
123 fi
Erich Smith08e439c2012-05-13 08:37:31 -0400124
Nils Winkler1f558e22012-05-21 13:24:49 +0200125 if [ "$file_entity" = "all" ]; then
126 typeset f $command_suffix
127 for f in $BASH_IT/$file_type/available/*.bash
Erich Smith08e439c2012-05-13 08:37:31 -0400128 do
129 plugin=$(basename $f)
Nils Winkler1f558e22012-05-21 13:24:49 +0200130 if [ -e $BASH_IT/$file_type/enabled/$plugin ]; then
131 rm $BASH_IT/$file_type/enabled/$(basename $plugin)
Erich Smith08e439c2012-05-13 08:37:31 -0400132 fi
133 done
134 else
Nils Winkler1f558e22012-05-21 13:24:49 +0200135 typeset plugin=$(command ls $BASH_IT/$file_type/enabled/$file_entity.*bash 2>/dev/null | head -1)
136 if [ -z "$plugin" ]; then
137 printf '%s\n' "sorry, that does not appear to be an enabled $command_suffix."
Erich Smith08e439c2012-05-13 08:37:31 -0400138 return
139 fi
Nils Winkler1f558e22012-05-21 13:24:49 +0200140 rm $BASH_IT/$file_type/enabled/$(basename $plugin)
Erich Smith08e439c2012-05-13 08:37:31 -0400141 fi
142
Nils Winkler1f558e22012-05-21 13:24:49 +0200143 printf '%s\n' "$file_entity disabled."
Erich Smith08e439c2012-05-13 08:37:31 -0400144}
145
146enable-plugin ()
147{
148 about 'enables bash_it plugin'
149 param '1: plugin name'
Erich Smith70e1cd32012-05-14 14:12:09 -0400150 example '$ enable-plugin rvm'
Erich Smith08e439c2012-05-13 08:37:31 -0400151 group 'lib'
Nils Winkler1f558e22012-05-21 13:24:49 +0200152
153 _enable-thing "plugins" "plugin" $1
154}
Erich Smith08e439c2012-05-13 08:37:31 -0400155
Nils Winkler1f558e22012-05-21 13:24:49 +0200156enable-alias ()
157{
158 about 'enables bash_it alias'
159 param '1: alias name'
160 example '$ enable-alias git'
161 group 'lib'
162
163 _enable-thing "aliases" "alias" $1
164}
165
166enable-completion ()
167{
168 about 'enables bash_it completion'
169 param '1: completion name'
170 example '$ enable-completion git'
171 group 'lib'
172
173 _enable-thing "completion" "completion" $1
174}
175
176_enable-thing ()
177{
178 file_type="$1"
179 command_suffix="$2"
180 file_entity="$3"
181
182 if [ -z "$file_entity" ]; then
183 reference "enable-$command_suffix"
Erich Smith08e439c2012-05-13 08:37:31 -0400184 return
185 fi
186
Nils Winkler1f558e22012-05-21 13:24:49 +0200187 if [ "$file_entity" = "all" ]; then
188 typeset f $command_suffix
189 for f in $BASH_IT/$file_type/available/*.bash
Erich Smith08e439c2012-05-13 08:37:31 -0400190 do
191 plugin=$(basename $f)
Nils Winkler1f558e22012-05-21 13:24:49 +0200192 if [ ! -h $BASH_IT/$file_type/enabled/$plugin ]; then
193 ln -s $BASH_IT/$file_type/available/$plugin $BASH_IT/$file_type/enabled/$plugin
Erich Smith08e439c2012-05-13 08:37:31 -0400194 fi
195 done
196 else
Nils Winkler1f558e22012-05-21 13:24:49 +0200197 typeset plugin=$(command ls $BASH_IT/$file_type/available/$file_entity.*bash 2>/dev/null | head -1)
Erich Smith08e439c2012-05-13 08:37:31 -0400198 if [ -z "$plugin" ]; then
Nils Winkler1f558e22012-05-21 13:24:49 +0200199 printf '%s\n' "sorry, that does not appear to be an available $command_suffix."
Erich Smith08e439c2012-05-13 08:37:31 -0400200 return
201 fi
202
203 plugin=$(basename $plugin)
Nils Winkler1f558e22012-05-21 13:24:49 +0200204 if [ -e $BASH_IT/$file_type/enabled/$plugin ]; then
205 printf '%s\n' "$file_entity is already enabled."
Erich Smith08e439c2012-05-13 08:37:31 -0400206 return
207 fi
208
Nils Winkler1f558e22012-05-21 13:24:49 +0200209 ln -s $BASH_IT/$file_type/available/$plugin $BASH_IT/$file_type/enabled/$plugin
Erich Smith08e439c2012-05-13 08:37:31 -0400210 fi
211
Nils Winkler1f558e22012-05-21 13:24:49 +0200212 printf '%s\n' "$file_entity enabled."
Erich Smith254d4452012-05-11 14:25:24 -0400213}
214
215plugins-help ()
216{
Erich Smitha825c5f2012-05-15 14:25:42 -0400217 about 'summarize all functions defined by enabled bash-it plugins'
Erich Smith08e439c2012-05-13 08:37:31 -0400218 group 'lib'
Erich Smith254d4452012-05-11 14:25:24 -0400219
Erich Smitha825c5f2012-05-15 14:25:42 -0400220 # display a brief progress message...
221 printf '%s' 'please wait, building help...'
222 typeset grouplist=$(mktemp /tmp/grouplist.XXXX)
223 typeset func
224 for func in $(typeset_functions)
Erich Smith254d4452012-05-11 14:25:24 -0400225 do
Erich Smitha825c5f2012-05-15 14:25:42 -0400226 typeset group="$(typeset -f $func | metafor group)"
227 if [ -z "$group" ]; then
228 group='misc'
229 fi
230 typeset about="$(typeset -f $func | metafor about)"
231 letterpress "$about" $func >> $grouplist.$group
232 echo $grouplist.$group >> $grouplist
Erich Smith254d4452012-05-11 14:25:24 -0400233 done
Erich Smitha825c5f2012-05-15 14:25:42 -0400234 # clear progress message
235 printf '\r%s\n' ' '
236 typeset group
237 typeset gfile
238 for gfile in $(cat $grouplist | sort | uniq)
239 do
240 printf '%s\n' "${gfile##*.}:"
241 cat $gfile
242 printf '\n'
243 rm $gfile 2> /dev/null
244 done | less
245 rm $grouplist 2> /dev/null
Erich Smith254d4452012-05-11 14:25:24 -0400246}
247
248all_groups ()
249{
Erich Smith08e439c2012-05-13 08:37:31 -0400250 about 'displays all unique metadata groups'
251 group 'lib'
Erich Smith254d4452012-05-11 14:25:24 -0400252
253 typeset func
254 typeset file=$(mktemp /tmp/composure.XXXX)
255 for func in $(typeset_functions)
256 do
257 typeset -f $func | metafor group >> $file
258 done
259 cat $file | sort | uniq
260 rm $file
261}