Travis Swicegood | b524bb6 | 2012-03-26 11:19:38 -0500 | [diff] [blame] | 1 | # Helper function loading various enable-able files |
| 2 | function _load_bash_it_files() { |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 3 | subdirectory="$1" |
| 4 | if [ ! -d "${BASH_IT}/${subdirectory}/enabled" ] |
Travis Swicegood | b524bb6 | 2012-03-26 11:19:38 -0500 | [diff] [blame] | 5 | then |
| 6 | continue |
| 7 | fi |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 8 | FILES="${BASH_IT}/${subdirectory}/enabled/*.bash" |
Travis Swicegood | b524bb6 | 2012-03-26 11:19:38 -0500 | [diff] [blame] | 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 |
| 18 | function reload_aliases() { |
| 19 | _load_bash_it_files "aliases" |
| 20 | } |
| 21 | |
| 22 | # Function for reloading auto-completion |
| 23 | function reload_completion() { |
| 24 | _load_bash_it_files "completion" |
| 25 | } |
| 26 | |
| 27 | # Function for reloading plugins |
| 28 | function reload_plugins() { |
| 29 | _load_bash_it_files "plugins" |
| 30 | } |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 31 | |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 32 | bash-it-aliases () |
| 33 | { |
| 34 | about 'summarizes available bash_it aliases' |
| 35 | group 'lib' |
Erich Smith | 961c914 | 2012-05-21 23:55:31 -0400 | [diff] [blame^] | 36 | |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 37 | _bash-it-describe "aliases" "an" "alias" "Alias" |
| 38 | } |
| 39 | |
| 40 | bash-it-completions () |
| 41 | { |
| 42 | about 'summarizes available bash_it completions' |
| 43 | group 'lib' |
Erich Smith | 961c914 | 2012-05-21 23:55:31 -0400 | [diff] [blame^] | 44 | |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 45 | _bash-it-describe "completion" "a" "completion" "Completion" |
| 46 | } |
| 47 | |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 48 | bash-it-plugins () |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 49 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 50 | about 'summarizes available bash_it plugins' |
| 51 | group 'lib' |
Erich Smith | 961c914 | 2012-05-21 23:55:31 -0400 | [diff] [blame^] | 52 | |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 53 | _bash-it-describe "plugins" "a" "plugin" "Plugin" |
| 54 | } |
| 55 | |
| 56 | _bash-it-describe () |
| 57 | { |
Erich Smith | 961c914 | 2012-05-21 23:55:31 -0400 | [diff] [blame^] | 58 | cite _about _param _example |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 59 | _about 'summarizes available bash_it components' |
| 60 | _param '1: subdirectory' |
| 61 | _param '2: preposition' |
| 62 | _param '3: file_type' |
| 63 | _param '4: column_header' |
| 64 | _example '$ _bash-it-describe "plugins" "a" "plugin" "Plugin"' |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 65 | |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 66 | subdirectory="$1" |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 67 | preposition="$2" |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 68 | file_type="$3" |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 69 | column_header="$4" |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 70 | |
| 71 | typeset f |
| 72 | typeset enabled |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 73 | printf "%-20s%-10s%s\n" "$column_header" 'Enabled?' 'Description' |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 74 | for f in $BASH_IT/$subdirectory/available/*.bash |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 75 | do |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 76 | if [ -e $BASH_IT/$subdirectory/enabled/$(basename $f) ]; then |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 77 | enabled='x' |
| 78 | else |
| 79 | enabled=' ' |
| 80 | fi |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 81 | printf "%-20s%-10s%s\n" "$(basename $f | cut -d'.' -f1)" " [$enabled]" "$(cat $f | metafor about-$file_type)" |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 82 | done |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 83 | printf '\n%s\n' "to enable $preposition $file_type, do:" |
| 84 | printf '%s\n' "$ enable-$file_type <$file_type name> -or- $ enable-$file_type all" |
| 85 | printf '\n%s\n' "to disable $preposition $file_type, do:" |
| 86 | printf '%s\n' "$ disable-$file_type <$file_type name> -or- $ disable-$file_type all" |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 87 | } |
| 88 | |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 89 | disable-plugin () |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 90 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 91 | about 'disables bash_it plugin' |
| 92 | param '1: plugin name' |
Erich Smith | 70e1cd3 | 2012-05-14 14:12:09 -0400 | [diff] [blame] | 93 | example '$ disable-plugin rvm' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 94 | group 'lib' |
Erich Smith | 961c914 | 2012-05-21 23:55:31 -0400 | [diff] [blame^] | 95 | |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 96 | _disable-thing "plugins" "plugin" $1 |
| 97 | } |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 98 | |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 99 | disable-alias () |
| 100 | { |
| 101 | about 'disables bash_it alias' |
| 102 | param '1: alias name' |
| 103 | example '$ disable-alias git' |
| 104 | group 'lib' |
Erich Smith | 961c914 | 2012-05-21 23:55:31 -0400 | [diff] [blame^] | 105 | |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 106 | _disable-thing "aliases" "alias" $1 |
| 107 | } |
| 108 | |
| 109 | disable-completion () |
| 110 | { |
| 111 | about 'disables bash_it completion' |
| 112 | param '1: completion name' |
| 113 | example '$ disable-completion git' |
| 114 | group 'lib' |
Erich Smith | 961c914 | 2012-05-21 23:55:31 -0400 | [diff] [blame^] | 115 | |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 116 | _disable-thing "completion" "completion" $1 |
| 117 | } |
| 118 | |
| 119 | _disable-thing () |
| 120 | { |
Erich Smith | 961c914 | 2012-05-21 23:55:31 -0400 | [diff] [blame^] | 121 | cite _about _param _example |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 122 | _about 'disables a bash_it component' |
| 123 | _param '1: subdirectory' |
| 124 | _param '2: file_type' |
| 125 | _param '3: file_entity' |
| 126 | _example '$ _disable-thing "plugins" "plugin" "ssh"' |
| 127 | |
Erich Smith | 961c914 | 2012-05-21 23:55:31 -0400 | [diff] [blame^] | 128 | subdirectory="$1" |
| 129 | file_type="$2" |
| 130 | file_entity="$3" |
| 131 | |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 132 | if [ -z "$file_entity" ]; then |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 133 | reference "disable-$file_type" |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 134 | return |
| 135 | fi |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 136 | |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 137 | if [ "$file_entity" = "all" ]; then |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 138 | typeset f $file_type |
| 139 | for f in $BASH_IT/$subdirectory/available/*.bash |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 140 | do |
| 141 | plugin=$(basename $f) |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 142 | if [ -e $BASH_IT/$subdirectory/enabled/$plugin ]; then |
| 143 | rm $BASH_IT/$subdirectory/enabled/$(basename $plugin) |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 144 | fi |
| 145 | done |
| 146 | else |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 147 | typeset plugin=$(command ls $BASH_IT/$subdirectory/enabled/$file_entity.*bash 2>/dev/null | head -1) |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 148 | if [ -z "$plugin" ]; then |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 149 | printf '%s\n' "sorry, that does not appear to be an enabled $file_type." |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 150 | return |
| 151 | fi |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 152 | rm $BASH_IT/$subdirectory/enabled/$(basename $plugin) |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 153 | fi |
| 154 | |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 155 | printf '%s\n' "$file_entity disabled." |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | enable-plugin () |
| 159 | { |
| 160 | about 'enables bash_it plugin' |
| 161 | param '1: plugin name' |
Erich Smith | 70e1cd3 | 2012-05-14 14:12:09 -0400 | [diff] [blame] | 162 | example '$ enable-plugin rvm' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 163 | group 'lib' |
Erich Smith | 961c914 | 2012-05-21 23:55:31 -0400 | [diff] [blame^] | 164 | |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 165 | _enable-thing "plugins" "plugin" $1 |
| 166 | } |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 167 | |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 168 | enable-alias () |
| 169 | { |
| 170 | about 'enables bash_it alias' |
| 171 | param '1: alias name' |
| 172 | example '$ enable-alias git' |
| 173 | group 'lib' |
Erich Smith | 961c914 | 2012-05-21 23:55:31 -0400 | [diff] [blame^] | 174 | |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 175 | _enable-thing "aliases" "alias" $1 |
| 176 | } |
| 177 | |
| 178 | enable-completion () |
| 179 | { |
| 180 | about 'enables bash_it completion' |
| 181 | param '1: completion name' |
| 182 | example '$ enable-completion git' |
| 183 | group 'lib' |
Erich Smith | 961c914 | 2012-05-21 23:55:31 -0400 | [diff] [blame^] | 184 | |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 185 | _enable-thing "completion" "completion" $1 |
| 186 | } |
| 187 | |
| 188 | _enable-thing () |
| 189 | { |
Erich Smith | 961c914 | 2012-05-21 23:55:31 -0400 | [diff] [blame^] | 190 | cite _about _param _example |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 191 | _about 'enables a bash_it component' |
| 192 | _param '1: subdirectory' |
| 193 | _param '2: file_type' |
| 194 | _param '3: file_entity' |
| 195 | _example '$ _enable-thing "plugins" "plugin" "ssh"' |
| 196 | |
Erich Smith | 961c914 | 2012-05-21 23:55:31 -0400 | [diff] [blame^] | 197 | subdirectory="$1" |
| 198 | file_type="$2" |
| 199 | file_entity="$3" |
| 200 | |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 201 | if [ -z "$file_entity" ]; then |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 202 | reference "enable-$file_type" |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 203 | return |
| 204 | fi |
| 205 | |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 206 | if [ "$file_entity" = "all" ]; then |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 207 | typeset f $file_type |
| 208 | for f in $BASH_IT/$subdirectory/available/*.bash |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 209 | do |
| 210 | plugin=$(basename $f) |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 211 | if [ ! -h $BASH_IT/$subdirectory/enabled/$plugin ]; then |
| 212 | ln -s $BASH_IT/$subdirectory/available/$plugin $BASH_IT/$subdirectory/enabled/$plugin |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 213 | fi |
| 214 | done |
| 215 | else |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 216 | typeset plugin=$(command ls $BASH_IT/$subdirectory/available/$file_entity.*bash 2>/dev/null | head -1) |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 217 | if [ -z "$plugin" ]; then |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 218 | printf '%s\n' "sorry, that does not appear to be an available $file_type." |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 219 | return |
| 220 | fi |
| 221 | |
| 222 | plugin=$(basename $plugin) |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 223 | if [ -e $BASH_IT/$subdirectory/enabled/$plugin ]; then |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 224 | printf '%s\n' "$file_entity is already enabled." |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 225 | return |
| 226 | fi |
| 227 | |
Nils Winkler | 95ce548 | 2012-05-22 09:33:59 +0200 | [diff] [blame] | 228 | ln -s $BASH_IT/$subdirectory/available/$plugin $BASH_IT/$subdirectory/enabled/$plugin |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 229 | fi |
| 230 | |
Nils Winkler | 1f558e2 | 2012-05-21 13:24:49 +0200 | [diff] [blame] | 231 | printf '%s\n' "$file_entity enabled." |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 232 | } |
| 233 | |
Erich Smith | 961c914 | 2012-05-21 23:55:31 -0400 | [diff] [blame^] | 234 | alias-help () |
| 235 | { |
| 236 | about 'shows help for all aliases, or a specific alias group' |
| 237 | param '1: optional alias group' |
| 238 | example '$ alias-help' |
| 239 | example '$ alias-help git' |
| 240 | |
| 241 | if [ -n "$1" ]; then |
| 242 | cat $BASH_IT/aliases/enabled/$1.aliases.bash | metafor alias | sed "s/$/'/" |
| 243 | else |
| 244 | typeset f |
| 245 | for f in $BASH_IT/aliases/enabled/* |
| 246 | do |
| 247 | typeset file=$(basename $f) |
| 248 | printf '\n\n%s:\n' "${file%%.*}" |
| 249 | # metafor() strips trailing quotes, restore them with sed.. |
| 250 | cat $f | metafor alias | sed "s/$/'/" |
| 251 | done |
| 252 | fi |
| 253 | } |
| 254 | |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 255 | plugins-help () |
| 256 | { |
Erich Smith | a825c5f | 2012-05-15 14:25:42 -0400 | [diff] [blame] | 257 | about 'summarize all functions defined by enabled bash-it plugins' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 258 | group 'lib' |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 259 | |
Erich Smith | a825c5f | 2012-05-15 14:25:42 -0400 | [diff] [blame] | 260 | # display a brief progress message... |
| 261 | printf '%s' 'please wait, building help...' |
| 262 | typeset grouplist=$(mktemp /tmp/grouplist.XXXX) |
| 263 | typeset func |
| 264 | for func in $(typeset_functions) |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 265 | do |
Erich Smith | a825c5f | 2012-05-15 14:25:42 -0400 | [diff] [blame] | 266 | typeset group="$(typeset -f $func | metafor group)" |
| 267 | if [ -z "$group" ]; then |
| 268 | group='misc' |
| 269 | fi |
| 270 | typeset about="$(typeset -f $func | metafor about)" |
| 271 | letterpress "$about" $func >> $grouplist.$group |
| 272 | echo $grouplist.$group >> $grouplist |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 273 | done |
Erich Smith | a825c5f | 2012-05-15 14:25:42 -0400 | [diff] [blame] | 274 | # clear progress message |
| 275 | printf '\r%s\n' ' ' |
| 276 | typeset group |
| 277 | typeset gfile |
| 278 | for gfile in $(cat $grouplist | sort | uniq) |
| 279 | do |
| 280 | printf '%s\n' "${gfile##*.}:" |
| 281 | cat $gfile |
| 282 | printf '\n' |
| 283 | rm $gfile 2> /dev/null |
| 284 | done | less |
| 285 | rm $grouplist 2> /dev/null |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | all_groups () |
| 289 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 290 | about 'displays all unique metadata groups' |
| 291 | group 'lib' |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 292 | |
| 293 | typeset func |
| 294 | typeset file=$(mktemp /tmp/composure.XXXX) |
| 295 | for func in $(typeset_functions) |
| 296 | do |
| 297 | typeset -f $func | metafor group >> $file |
| 298 | done |
| 299 | cat $file | sort | uniq |
| 300 | rm $file |
| 301 | } |