erikw/tmux-powerline — pull request #92 by jfelchner (2012-12-03 08:29:14+00:00)
Title: Modularize files and functions

This pull request cleans up the code quite a bit.

* Readability improved
* Whitespace is normalized. There were tabs mixed with spaces and trailing whitespace all over the place.
* Blank lines added where it's important to break the (small) methods up into logical chunks
* Indention level was set at 2 spaces
* Tabs were removed and replaced with 2 spaces consistently throughout the `lib` and `config` directories
* A lot of code has been rewritten such that
* Almost all conditionals have been removed
* Almost all calls to subshells (which are very slow) have been removed
* A lot of duplicate code has been removed
* Methods which were doing a bunch of things have been rewritten to do only one thing
* There are only one set of methods for either side of the bar (with one exception) so there is no need to have `status-left.sh` and `status-right.sh`. Instead there is one `powerbar.sh` file which, when called with the proper side (eg `powerbar.sh left`) just does the right thing
* Platform detection is now performed automatically using the `$OSTYPE` environment variable and functions provided to use in conditionals (eg `shell_is_osx` `shell_is_linux`)
* Removed comments and instead made the code self-explanatory via named functions and variables
* Made all variables and method naming consistent:
* All configuration/global variables are in `ALL_CAPS` and start with `TMUX_POWERBAR`
* All private methods begin with double underscores `__` (this was already the case but I continued with it)
* Files have been reorganized into more logical components (still some work to do here)
* `lib.sh` especially was becoming a junk drawer with methods for everything from formatting to Tmux to muting the bar
* Configuration of Powerbar has been rewritten to be able to be configured completely from environment variables and therefore the Powerbar files do not need to be touched
* Moved from using associative arrays (which are very verbose in Bash) to indexed arrays which have their components in a set order. This takes the configuration which was 146 lines down to 26.

There's still some work I want to do here but I wanted to start getting feedback from everyone. Specifically:

* If the bar is in the progress of being written and Tmux fires a refresh, the Powerbar process kicks off again, there needs to be a pid file that's checked for. If it exists, the subsequent process should quit silently.

* The checks that were previously in the config file for 'if this platform then do this' or 'only enable this segment if on this platform' need to be removed. If there's something that needs to check the platform to determine _which_ segment to load (eg the battery segment) that should be done inside a common 'battery' segment, which would load the proper sub-segment from there.

* The proper segment files need to be sourced in and each segment should have a single method `___run` which returns the text to display in the segment. This will eliminate all of the subshelling that's currently happening to execute all of the scripts and should give a noticeable speed improvement.

A few other things.

Comments are welcome.

Thanks!