Plugin management system #134

Merged
merged 14 commits into from May 17, 2012

Conversation

Projects
None yet
5 participants
@erichs
Contributor

erichs commented May 14, 2012

This admittedly large pull request does the following:

o updates to the latest version of composure.sh
o composure metadata is added to all plugin.bash files
o metadata is used to implement a plugin management and help system
o standardizes plugin names, file modes, and shebang lines
o updates bash-it() help text
o moves a few helper functions to lib/helpers.bash
o disables z() if fasd plugin is enabled (they are incompatible)

Plugin Management

type: bash-it-plugins

$ bash-it-plugins
Plugin              Enabled?  Description
_xterm                [ ]     automatically set your xterm title with host and location info
base                  [x]     miscellaneous tools
battery               [ ]     display info about your battery charge level
browser               [x]     render commandline output in your browser
dirs                  [x]     directory stack navigation
extract               [x]     one command to extract them all...
fasd                  [x]     navigate "frecently" used files and directories
git                   [x]     git helper functions
hg                    [ ]     hg helper functions
javascript            [x]     download jquery files into current project
jekyll                [x]     manage your jekyll site
latex                 [ ]     use mactex
nginx                 [ ]     manage your nginx service
nvm                   [x]     node version manager, as a bash function
osx                   [x]     osx-specific functions
python                [x]     alias "http" to SimpleHTTPServer
rbenv                 [x]     load rbenv, if you are using it
ruby                  [x]     adds "remove_gem" function
rvm                   [ ]     load rvm, if you are using it
ssh                   [x]     ssh helper functions
subversion            [ ]     svn helper functions
tmux                  [x]     make sure that tmux is launched in 256 color mode
tmuxinator            [ ]     sources tmuxinator script if available
vagrant               [ ]     set up vagrant autocompletion
virtualenv            [ ]     virtualenvwrapper helper functions
z                     [ ]     maintains a jump-list of the directories you actually use
                              z is DEPRECATED, use fasd instead
z_autoenv             [ ]     source into environment when cding to directories

to enable a plugin, do:
$ enable-plugin  <plugin name> -or- $ enable-plugin all

to disable a plugin, do:
$ disable-plugin <plugin name> -or- $ disable-plugin all

enable-plugin and disable-plugin do just what you'd expect.

Similar metadata niceties can also be achieved in this fashion for the completion, themes, and aliases.

erichs added some commits May 9, 2012

plugin-specific metadata
cite about-plugin metadata.  This could be retrieved later, say by an
install script or other helper function, with:

cat ~/.bash_it/plugins/enabled/base.plugin.bash | metafor about-plugin

In this way, summaries of each plugin may be provided to give newcomers
(like me!) an overview.

also, rewrote plugins-help(), which didn't work very well on my system.
It now dynamically queries composure metadata.
@erichs

This comment has been minimized.

Show comment Hide comment
@erichs

erichs May 11, 2012

Owner

The basic technique here is that functions can call 'reference()' on themselves when invalid input is given.

This could be generalized with a bashism to:

reference $FUNCNAME
Owner

erichs commented on 3f8fe61 May 11, 2012

The basic technique here is that functions can call 'reference()' on themselves when invalid input is given.

This could be generalized with a bashism to:

reference $FUNCNAME
@erichs

This comment has been minimized.

Show comment Hide comment
@erichs

erichs May 11, 2012

Owner

this bit is functionality cribbed from composure's c_extras.sh

this bit is functionality cribbed from composure's c_extras.sh

erichs added some commits May 11, 2012

update to latest version of composure.sh
this fixes a bug in draft() and improves performance in metafor()
and glossary()
basic plugin management
move plugin management functions into 'lib' group in helpers.bash
standardize plugins, update metadata
add about-plugin metadata
chmod -x plugins
cleanup filenames to standardize on x.plugin.bash format
only plugin files intended to be executable from the command line should
contain a shebang line, and should be a+x.
disable z() if fasd is enabled
loading fasd clobbers z(), and results in a cryptic syntax error
message, since 'z' is already an alias when z.plugin.bash is being
sourced.

this conditional detects this situation and returns early.
@noqqe

This comment has been minimized.

Show comment Hide comment
@noqqe

noqqe May 14, 2012

Contributor

awesome!

Contributor

noqqe commented May 14, 2012

awesome!

@tswicegood

This comment has been minimized.

Show comment Hide comment
@tswicegood

tswicegood May 14, 2012

Member

This looks awesome -- let me double check that it merges cleanly and keeps working for me and I think we can get this in.

Member

tswicegood commented May 14, 2012

This looks awesome -- let me double check that it merges cleanly and keeps working for me and I think we can get this in.

@ghost ghost assigned tswicegood May 14, 2012

lib/helpers.bash
+{
+ about 'enables bash_it plugin'
+ param '1: plugin name'
+ example '$ enable_plugin rvm'

This comment has been minimized.

Show comment Hide comment
@tswicegood

tswicegood May 14, 2012

Member

This is example is off. Should be enable-plugin. Same for disable-plugin above.

@tswicegood

tswicegood May 14, 2012

Member

This is example is off. Should be enable-plugin. Same for disable-plugin above.

This comment has been minimized.

Show comment Hide comment
@erichs

erichs May 14, 2012

Contributor

Good catch! will fix.

@erichs

erichs May 14, 2012

Contributor

Good catch! will fix.

+ typeset file=$(mktemp /tmp/composure.XXXX)
+ for func in $(typeset_functions)
+ do
+ typeset -f $func | metafor group >> $file

This comment has been minimized.

Show comment Hide comment
@tswicegood

tswicegood May 14, 2012

Member

typeset -f fails pretty spectacularly on OS X.

bash: typeset: cannot use `-f' to make functions

Any ideas?

@tswicegood

tswicegood May 14, 2012

Member

typeset -f fails pretty spectacularly on OS X.

bash: typeset: cannot use `-f' to make functions

Any ideas?

This comment has been minimized.

Show comment Hide comment
@tswicegood

tswicegood May 14, 2012

Member

This is weird. If I run this line and replace $func with a regular function, everything seems to work just fine. When I run all_groups I end up with hundreds if lines of the error above.

@tswicegood

tswicegood May 14, 2012

Member

This is weird. If I run this line and replace $func with a regular function, everything seems to work just fine. When I run all_groups I end up with hundreds if lines of the error above.

This comment has been minimized.

Show comment Hide comment
@erichs

erichs May 14, 2012

Contributor

interesting! typeset -f is just about the only 'stable' behavior I've seen across platforms for the typeset command.

might be an interaction with a shell option you have set...

I'm running:
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)
Copyright (C) 2007 Free Software Foundation, Inc.

could you do the following for me?

bash --version
shopt
@erichs

erichs May 14, 2012

Contributor

interesting! typeset -f is just about the only 'stable' behavior I've seen across platforms for the typeset command.

might be an interaction with a shell option you have set...

I'm running:
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)
Copyright (C) 2007 Free Software Foundation, Inc.

could you do the following for me?

bash --version
shopt

This comment has been minimized.

Show comment Hide comment
@erichs

erichs May 14, 2012

Contributor

also, does typeset_functions appear to work correctly for you?

@erichs

erichs May 14, 2012

Contributor

also, does typeset_functions appear to work correctly for you?

This comment has been minimized.

Show comment Hide comment
@erichs

erichs May 14, 2012

Contributor

If typeset_functions is not working correctly, this could fail.

One last thing to check might be to see if there are any aliases on your system that override/conflict with function names. This has suprising and buggy behavior with function declarations.

@erichs

erichs May 14, 2012

Contributor

If typeset_functions is not working correctly, this could fail.

One last thing to check might be to see if there are any aliases on your system that override/conflict with function names. This has suprising and buggy behavior with function declarations.

This comment has been minimized.

Show comment Hide comment
@tswicegood

tswicegood May 15, 2012

Member

I was able to get this working without modification on my laptop, so the problem is clearly something on this iMac.

@tswicegood

tswicegood May 15, 2012

Member

I was able to get this working without modification on my laptop, so the problem is clearly something on this iMac.

@tswicegood

This comment has been minimized.

Show comment Hide comment
@tswicegood

tswicegood May 15, 2012

Member

With a little detective work, I found out that shell wasn't being set properly inside typeset_functions. I've created the change and opened a PR: erichs#1

With that, we can get this merged in. Looks amazing.

Member

tswicegood commented May 15, 2012

With a little detective work, I found out that shell wasn't being set properly inside typeset_functions. I've created the change and opened a PR: erichs#1

With that, we can get this merged in. Looks amazing.

tswicegood and others added some commits May 15, 2012

fix typeset_functions
typeset_functions relies on a hack to determine the shell it is running
under. this hack fails on some versions of bash. if the $SHELL variable
is set, prefer that instead.

fix bug in draft()
plugins-help is much faster
this replaces the naive implementation that called glossary() on each
group, and is an order of magnitude faster.

fix grouping in javascript.plugin.bash
lib/helpers.bash
+ printf "%-20s%-10s%s\n" 'Plugin' 'Enabled?' 'Description'
+ for f in $BASH_IT/plugins/available/*.bash
+ do
+ if [ -h $BASH_IT/plugins/enabled/$(basename $f) ]; then

This comment has been minimized.

Show comment Hide comment
@tswicegood

tswicegood May 16, 2012

Member

Thoughts on making this an if [ -e ...] check instead? Dropbox constantly mucks with my plugins and such since it converts symlinks to actual files. Right now it looks like all of my plugins are disabled since they're all real files.

@tswicegood

tswicegood May 16, 2012

Member

Thoughts on making this an if [ -e ...] check instead? Dropbox constantly mucks with my plugins and such since it converts symlinks to actual files. Right now it looks like all of my plugins are disabled since they're all real files.

This comment has been minimized.

Show comment Hide comment
@erichs

erichs May 16, 2012

Contributor

Right-o! Project-wide, the following lines would need to be altered:

lib/helpers.bash
42:        if [ -h $BASH_IT/plugins/enabled/$(basename $f) ]; then
72:            if [ -h $BASH_IT/plugins/enabled/$plugin ]; then
117:        if [ -h $BASH_IT/plugins/enabled/$plugin ]; then

plugins/available/z.plugin.bash
18:if [ -h $BASH_IT/plugins/enabled/fasd.plugin.bash ]; then

If it is easier, I can make those edits.

@erichs

erichs May 16, 2012

Contributor

Right-o! Project-wide, the following lines would need to be altered:

lib/helpers.bash
42:        if [ -h $BASH_IT/plugins/enabled/$(basename $f) ]; then
72:            if [ -h $BASH_IT/plugins/enabled/$plugin ]; then
117:        if [ -h $BASH_IT/plugins/enabled/$plugin ]; then

plugins/available/z.plugin.bash
18:if [ -h $BASH_IT/plugins/enabled/fasd.plugin.bash ]; then

If it is easier, I can make those edits.

test existence, not symlink
it isn't safe to assume that symlinks created in the enabled/* dirs will
be symlinks later...

some users use tools like Dropbox to sync their files across systems,
and these may transform symlinks into regular files.  explicitly
checking for symlinks with tests like [ -h $file ] will break on these
systems.  these tests have been replaced with [ -e $file ] instead.
@tswicegood

This comment has been minimized.

Show comment Hide comment
@tswicegood

tswicegood May 17, 2012

Member

Thanks for all the work on this. Looks awesome!

Member

tswicegood commented May 17, 2012

Thanks for all the work on this. Looks awesome!

tswicegood added a commit that referenced this pull request May 17, 2012

Merge pull request #134 from erichs/plugin_metadata
Plugin management system (big thanks to @erichs)

@tswicegood tswicegood merged commit 3bde23a into Bash-it:master May 17, 2012

@trusktr

This comment has been minimized.

Show comment Hide comment
@trusktr

trusktr Apr 13, 2013

Just out of curiosity, why would you prefer this over zsh? What do you like about bash more than zsh? Just trying to get some insight.

trusktr commented Apr 13, 2013

Just out of curiosity, why would you prefer this over zsh? What do you like about bash more than zsh? Just trying to get some insight.

@seefood

This comment has been minimized.

Show comment Hide comment
@seefood

seefood Apr 18, 2013

Contributor

Because BASH is ubiquitous on all Linux distributions, it's the default shell in most cases or at least installed, zsh is usually an optional addition, therefore it's more widely used and known. it's also the standard shell for writing most system scripts in those distributions, etc, etc.

plus, many people prefer to stick to FSF's GNU package as the standard base, and non-GPL-compatible (or other widely used licences) software makes people in enterprise settings nervous for having to cover their asses against one more software licence. I'm sure there are other reasons.

That said, you are most welcome to fork the project, call it zsh-it and port it to anything you want.

Contributor

seefood commented Apr 18, 2013

Because BASH is ubiquitous on all Linux distributions, it's the default shell in most cases or at least installed, zsh is usually an optional addition, therefore it's more widely used and known. it's also the standard shell for writing most system scripts in those distributions, etc, etc.

plus, many people prefer to stick to FSF's GNU package as the standard base, and non-GPL-compatible (or other widely used licences) software makes people in enterprise settings nervous for having to cover their asses against one more software licence. I'm sure there are other reasons.

That said, you are most welcome to fork the project, call it zsh-it and port it to anything you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment