bpinto/oh-my-fish — pull request #280 by bucaran (2014-12-16 23:23:01+00:00)
Title: + Add `prepend tree` command to `functions/`. Traverse a directory and add tree of dependencies to a path.

Hi!

I've been writing a plugin for the past week or so and it has grown from just a couple of files to a few small utility libraries and several files that conform the API the plugin talks to. It is 99% written in Fish, with a little Python to parse a JSON request. I will be making another PR with it soon, hopefully before the weekend.

This PR exists however, to address a little architectural issue I encountered when separating concerns and trying to better design a general purpose API, handle errors more consistently, etc. Basically, I needed to add some additional directories to the `$fish_function_path`, but didn't want to just _hard code_ them. This simple function had to loop through my directory and add sub directories, but also had to be smart enough to not clutter the path with directories without `.fish ` files. I decided to implement a general purpose command to address my use case, but with flexible options catering for future scenarios.

`_prepend_tree` helps me solve the issue elegantly with a single line of code in my `plugin.load`, traversing the directory tree of the specified _source_ path and adding all the directories with files that match an optional list of glob patterns (defaults to `.fish` files) to a _destination_ path (defaults to `$fish_function_path`).

Other features are connecting multiple glob patterns using logical NOT / AND / OR operators and a `-P --preview` that prints what paths will be added to the _destination_ path, useful when debugging / testing.

For more information please refer to the documentation in the source code.

**BUGS**
I will be periodically test and update if or when errors are found. If you use the function and find anything strange, please let me know by posting it on this issue.

Cheers.