bpinto/oh-my-fish — pull request #164 by gabeos (2014-05-20 03:56:28+00:00)
Title: Modified install.fish to handle user-specified install directories, and choice of appending or replacing config.fish

Hey there. Thanks for your work on this project. I had a little bit of time while something else was running and figured I'd play around a bit with some fish scripting.

Note that i'm submitting the pull request to master since it seems like a lot more has changed on install_testing_sh, although i merged in relevant changes from that branch. I'm happy to submit a different request if you'd prefer it be on that branch.

Changes:
:In tools/install.fish
* Argument parsing with getopt -- I adopted some code from the internet (source listed in comment in install.fish) to parse command line arguments a little bit better using getopt. Arguments allowed are [-m|--modify] signalling to append the template configuration to the current config.fish, [-r|--remove] to backup and replace the fish configuration (maybe --replace would be a better long option, but i left it as specified in the testing_install_sh branch), and a final positional argument specifying a directory to install in.
* If directory already exists, tests that directory is empty before installing to it. Exits if directory is not empty.
* Queries user if neither -m or -r are given as arguments. Previous version of this code on install_testing_sh branch read into local variable, which was not available when it was tested. It now reads into global variable and works in my tests.
* If user response to query is not 'M' or 'm', defaults to original option (-r). If the user input was not 'r' or 'R', prints a message letting them know that the input was not understood, but program defaults to 'r' option.

:In template/config.fish
* Replaced hard coded install path ('~/.oh-my-fish') with template that is replaced when template replaces or appends to config.fish from install.fish. The template I used is "" which was chosen to be understandable, should the user be installing manually.

Small changes:
* Added exit code 1 to all points where script exits before completing installation

TODO:
* If you choose to merge this code, the README should be updated, but I have not done that, since I figured I'd get your opinion first.
* There is no explicit handling of the user giving both -m and -r options. Whichever comes last will be chosen, i believe.

Testing: I believe I tested all combinations of options, and it seems to work well.

Anyway, thanks for looking. I hope you like the code, but obviously modify it as you see fit. If you are interested, or would prefer a different method of handling things, please comment or email, and I'm happy to discuss it anything at all :smile:

Gabe Schubiner
gabeos@cs.washington.edu