Permalink
Browse files

Merged @erichs changes for the bash-it function.

  • Loading branch information...
1 parent e82991b commit be20972cf0de26e6cf2e09e75f14c5667ffad83c @nwinkler nwinkler committed May 23, 2012
Showing with 105 additions and 70 deletions.
  1. +3 −20 bash_it.sh
  2. +102 −50 lib/helpers.bash
View
@@ -24,6 +24,9 @@ fi
# Load composure first, so we support function metadata
source "${BASH_IT}/lib/composure.sh"
+# support 'plumbing' metadata
+cite _about _param _example _group _author _version
+
# Load colors first so they can be use in base theme
source "${BASH_IT}/themes/colors.theme.bash"
source "${BASH_IT}/themes/base.theme.bash"
@@ -72,23 +75,3 @@ if [ -e $HOME/.jekyllconfig ]
then
. $HOME/.jekyllconfig
fi
-
-
-#
-# Custom Help
-
-function bash-it() {
- echo "Welcome to Bash It!"
- echo
- echo "Here is a list of commands you can use to get help screens for specific pieces of Bash it:"
- echo
- echo " rails-help list out all aliases you can use with rails."
- echo " git-help list out all aliases you can use with git."
- echo " todo-help list out all aliases you can use with todo.txt-cli"
- echo " brew-help list out all aliases you can use with Homebrew"
- echo " aliases-help generic list of aliases."
- echo " plugins-help list out all functions you have installed with bash-it"
- echo " bash-it-plugins summarize bash-it plugins, and their installation status"
- echo " reference <function name> detailed help for a specific function"
- echo
-}
View
@@ -29,33 +29,86 @@ function reload_plugins() {
_load_bash_it_files "plugins"
}
-bash-it-aliases ()
+bash-it ()
{
- about 'summarizes available bash_it aliases'
- group 'lib'
+ about 'bash-it help and maintenance'
+ param '1: verb [one of: help | show | enable | disable ]'
+ param '2: component type [one of: alias(es) | completion(s) | plugin(s) ]'
+ param '3: specific component [optional]'
+ example '$ bash-it show plugins'
+ example '$ bash-it help aliases'
+ example '$ bash-it enable plugin git'
+ example '$ bash-it disable alias hg'
+ typeset verb=${1:-}
+ shift
+ typeset component=${1:-}
+ shift
+ typeset func
+ case $verb in
+ show)
+ func=_bash-it-$component;;
+ enable)
+ func=_enable-$component;;
+ disable)
+ func=_disable-$component;;
+ help)
+ func=_help-$component;;
+ *)
+ reference bash-it
+ return;;
+ esac
+
+ # pluralize component if necessary
+ if ! _is_function $func; then
+ if _is_function ${func}s; then
+ func=${func}s
+ else
+ if _is_function ${func}es; then
+ func=${func}es
+ else
+ echo "oops! $component is not a valid option!"
+ reference bash-it
+ return
+ fi
+ fi
+ fi
+ $func $*
+}
+
+_is_function ()
+{
+ _about 'sets $? to true if parameter is the name of a function'
+ _param '1: name of alleged function'
+ _group 'lib'
+ [ -n "$(type -a $1 2>/dev/null | grep 'is a function')" ]
+}
+
+_bash-it-aliases ()
+{
+ _about 'summarizes available bash_it aliases'
+ _group 'lib'
_bash-it-describe "aliases" "an" "alias" "Alias"
}
-bash-it-completions ()
+_bash-it-completions ()
{
- about 'summarizes available bash_it completions'
- group 'lib'
+ _about 'summarizes available bash_it completions'
+ _group 'lib'
_bash-it-describe "completion" "a" "completion" "Completion"
}
-bash-it-plugins ()
+_bash-it-plugins ()
{
- about 'summarizes available bash_it plugins'
- group 'lib'
+ _about 'summarizes available bash_it plugins'
+ _group 'lib'
_bash-it-describe "plugins" "a" "plugin" "Plugin"
}
_bash-it-describe ()
{
- cite _about _param _example
_about 'summarizes available bash_it components'
_param '1: subdirectory'
_param '2: preposition'
@@ -86,39 +139,38 @@ _bash-it-describe ()
printf '%s\n' "$ bash-it disable $file_type <$file_type name> -or- $ bash-it disable $file_type all"
}
-disable-plugin ()
+_disable-plugin ()
{
- about 'disables bash_it plugin'
- param '1: plugin name'
- example '$ disable-plugin rvm'
- group 'lib'
+ _about 'disables bash_it plugin'
+ _param '1: plugin name'
+ _example '$ disable-plugin rvm'
+ _group 'lib'
_disable-thing "plugins" "plugin" $1
}
-disable-alias ()
+_disable-alias ()
{
- about 'disables bash_it alias'
- param '1: alias name'
- example '$ disable-alias git'
- group 'lib'
+ _about 'disables bash_it alias'
+ _param '1: alias name'
+ _example '$ disable-alias git'
+ _group 'lib'
_disable-thing "aliases" "alias" $1
}
-disable-completion ()
+_disable-completion ()
{
- about 'disables bash_it completion'
- param '1: completion name'
- example '$ disable-completion git'
- group 'lib'
+ _about 'disables bash_it completion'
+ _param '1: completion name'
+ _example '$ disable-completion git'
+ _group 'lib'
_disable-thing "completion" "completion" $1
}
_disable-thing ()
{
- cite _about _param _example
_about 'disables a bash_it component'
_param '1: subdirectory'
_param '2: file_type'
@@ -155,32 +207,32 @@ _disable-thing ()
printf '%s\n' "$file_entity disabled."
}
-enable-plugin ()
+_enable-plugin ()
{
- about 'enables bash_it plugin'
- param '1: plugin name'
- example '$ enable-plugin rvm'
- group 'lib'
+ _about 'enables bash_it plugin'
+ _param '1: plugin name'
+ _example '$ enable-plugin rvm'
+ _group 'lib'
_enable-thing "plugins" "plugin" $1
}
-enable-alias ()
+_enable-alias ()
{
- about 'enables bash_it alias'
- param '1: alias name'
- example '$ enable-alias git'
- group 'lib'
+ _about 'enables bash_it alias'
+ _param '1: alias name'
+ _example '$ enable-alias git'
+ _group 'lib'
_enable-thing "aliases" "alias" $1
}
-enable-completion ()
+_enable-completion ()
{
- about 'enables bash_it completion'
- param '1: completion name'
- example '$ enable-completion git'
- group 'lib'
+ _about 'enables bash_it completion'
+ _param '1: completion name'
+ _example '$ enable-completion git'
+ _group 'lib'
_enable-thing "completion" "completion" $1
}
@@ -231,15 +283,15 @@ _enable-thing ()
printf '%s\n' "$file_entity enabled."
}
-alias-help ()
+_help-aliases()
{
- about 'shows help for all aliases, or a specific alias group'
- param '1: optional alias group'
- example '$ alias-help'
- example '$ alias-help git'
+ _about 'shows help for all aliases, or a specific alias group'
+ _param '1: optional alias group'
+ _example '$ alias-help'
+ _example '$ alias-help git'
if [ -n "$1" ]; then
- cat $BASH_IT/aliases/enabled/$1.aliases.bash | metafor alias | sed "s/$/'/"
+ cat $BASH_IT/aliases/available/$1.aliases.bash | metafor alias | sed "s/$/'/"
else
typeset f
for f in $BASH_IT/aliases/enabled/*
@@ -252,10 +304,10 @@ alias-help ()
fi
}
-plugins-help ()
+_help-plugins()
{
- about 'summarize all functions defined by enabled bash-it plugins'
- group 'lib'
+ _about 'summarize all functions defined by enabled bash-it plugins'
+ _group 'lib'
# display a brief progress message...
printf '%s' 'please wait, building help...'

0 comments on commit be20972

Please sign in to comment.