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() { |
| 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 |
| 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 | |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 32 | bash-it-plugins () |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 33 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 34 | about 'summarizes available bash_it plugins' |
| 35 | group 'lib' |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 36 | |
| 37 | typeset f |
| 38 | typeset enabled |
| 39 | printf "%-20s%-10s%s\n" 'Plugin' 'Enabled?' 'Description' |
| 40 | for f in $BASH_IT/plugins/available/*.bash |
| 41 | do |
Erich Smith | 758c4f3 | 2012-05-16 13:00:22 -0400 | [diff] [blame] | 42 | if [ -e $BASH_IT/plugins/enabled/$(basename $f) ]; then |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 43 | enabled='x' |
| 44 | else |
| 45 | enabled=' ' |
| 46 | fi |
| 47 | printf "%-20s%-10s%s\n" "$(basename $f | cut -d'.' -f1)" " [$enabled]" "$(cat $f | metafor about-plugin)" |
| 48 | done |
| 49 | printf '\n%s\n' 'to enable a plugin, do:' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 50 | printf '%s\n' '$ enable-plugin <plugin name> -or- $ enable-plugin all' |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 51 | printf '\n%s\n' 'to disable a plugin, do:' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 52 | printf '%s\n' '$ disable-plugin <plugin name> -or- $ disable-plugin all' |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 53 | } |
| 54 | |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 55 | disable-plugin () |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 56 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 57 | about 'disables bash_it plugin' |
| 58 | param '1: plugin name' |
Erich Smith | 70e1cd3 | 2012-05-14 14:12:09 -0400 | [diff] [blame] | 59 | example '$ disable-plugin rvm' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 60 | group 'lib' |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 61 | |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 62 | if [ -z "$1" ]; then |
Erich Smith | 70e1cd3 | 2012-05-14 14:12:09 -0400 | [diff] [blame] | 63 | reference disable-plugin |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 64 | return |
| 65 | fi |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 66 | |
| 67 | if [ "$1" = "all" ]; then |
| 68 | typeset f plugin |
| 69 | for f in $BASH_IT/plugins/available/*.bash |
| 70 | do |
| 71 | plugin=$(basename $f) |
Erich Smith | 758c4f3 | 2012-05-16 13:00:22 -0400 | [diff] [blame] | 72 | if [ -e $BASH_IT/plugins/enabled/$plugin ]; then |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 73 | rm $BASH_IT/plugins/enabled/$(basename $plugin) |
| 74 | fi |
| 75 | done |
| 76 | else |
Erich Smith | bffae2a | 2012-05-20 13:18:04 -0400 | [diff] [blame] | 77 | typeset plugin=$(command ls $BASH_IT/plugins/enabled/$1.*bash 2>/dev/null | head -1) |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 78 | if [ ! -h $plugin ]; then |
| 79 | printf '%s\n' 'sorry, that does not appear to be an enabled plugin.' |
| 80 | return |
| 81 | fi |
| 82 | rm $BASH_IT/plugins/enabled/$(basename $plugin) |
| 83 | fi |
| 84 | |
| 85 | printf '%s\n' "$1 disabled." |
| 86 | } |
| 87 | |
| 88 | enable-plugin () |
| 89 | { |
| 90 | about 'enables bash_it plugin' |
| 91 | param '1: plugin name' |
Erich Smith | 70e1cd3 | 2012-05-14 14:12:09 -0400 | [diff] [blame] | 92 | example '$ enable-plugin rvm' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 93 | group 'lib' |
| 94 | |
| 95 | if [ -z "$1" ]; then |
Erich Smith | 70e1cd3 | 2012-05-14 14:12:09 -0400 | [diff] [blame] | 96 | reference enable-plugin |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 97 | return |
| 98 | fi |
| 99 | |
| 100 | if [ "$1" = "all" ]; then |
| 101 | typeset f plugin |
| 102 | for f in $BASH_IT/plugins/available/*.bash |
| 103 | do |
| 104 | plugin=$(basename $f) |
| 105 | if [ ! -h $BASH_IT/plugins/enabled/$plugin ]; then |
| 106 | ln -s $BASH_IT/plugins/available/$plugin $BASH_IT/plugins/enabled/$plugin |
| 107 | fi |
| 108 | done |
| 109 | else |
Erich Smith | bffae2a | 2012-05-20 13:18:04 -0400 | [diff] [blame] | 110 | typeset plugin=$(command ls $BASH_IT/plugins/available/$1.*bash 2>/dev/null | head -1) |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 111 | if [ -z "$plugin" ]; then |
| 112 | printf '%s\n' 'sorry, that does not appear to be an available plugin.' |
| 113 | return |
| 114 | fi |
| 115 | |
| 116 | plugin=$(basename $plugin) |
Erich Smith | 758c4f3 | 2012-05-16 13:00:22 -0400 | [diff] [blame] | 117 | if [ -e $BASH_IT/plugins/enabled/$plugin ]; then |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 118 | printf '%s\n' "$1 is already enabled." |
| 119 | return |
| 120 | fi |
| 121 | |
| 122 | ln -s $BASH_IT/plugins/available/$plugin $BASH_IT/plugins/enabled/$plugin |
| 123 | fi |
| 124 | |
| 125 | printf '%s\n' "$1 enabled." |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | plugins-help () |
| 129 | { |
Erich Smith | a825c5f | 2012-05-15 14:25:42 -0400 | [diff] [blame] | 130 | about 'summarize all functions defined by enabled bash-it plugins' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 131 | group 'lib' |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 132 | |
Erich Smith | a825c5f | 2012-05-15 14:25:42 -0400 | [diff] [blame] | 133 | # display a brief progress message... |
| 134 | printf '%s' 'please wait, building help...' |
| 135 | typeset grouplist=$(mktemp /tmp/grouplist.XXXX) |
| 136 | typeset func |
| 137 | for func in $(typeset_functions) |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 138 | do |
Erich Smith | a825c5f | 2012-05-15 14:25:42 -0400 | [diff] [blame] | 139 | typeset group="$(typeset -f $func | metafor group)" |
| 140 | if [ -z "$group" ]; then |
| 141 | group='misc' |
| 142 | fi |
| 143 | typeset about="$(typeset -f $func | metafor about)" |
| 144 | letterpress "$about" $func >> $grouplist.$group |
| 145 | echo $grouplist.$group >> $grouplist |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 146 | done |
Erich Smith | a825c5f | 2012-05-15 14:25:42 -0400 | [diff] [blame] | 147 | # clear progress message |
| 148 | printf '\r%s\n' ' ' |
| 149 | typeset group |
| 150 | typeset gfile |
| 151 | for gfile in $(cat $grouplist | sort | uniq) |
| 152 | do |
| 153 | printf '%s\n' "${gfile##*.}:" |
| 154 | cat $gfile |
| 155 | printf '\n' |
| 156 | rm $gfile 2> /dev/null |
| 157 | done | less |
| 158 | rm $grouplist 2> /dev/null |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | all_groups () |
| 162 | { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 163 | about 'displays all unique metadata groups' |
| 164 | group 'lib' |
Erich Smith | 254d445 | 2012-05-11 14:25:24 -0400 | [diff] [blame] | 165 | |
| 166 | typeset func |
| 167 | typeset file=$(mktemp /tmp/composure.XXXX) |
| 168 | for func in $(typeset_functions) |
| 169 | do |
| 170 | typeset -f $func | metafor group >> $file |
| 171 | done |
| 172 | cat $file | sort | uniq |
| 173 | rm $file |
| 174 | } |