From 8ab709a43e1f1838d14f5d546b52bfb329e053eb Mon Sep 17 00:00:00 2001 From: rkiel Date: Thu, 9 Nov 2017 09:43:22 -0500 Subject: [PATCH] installer: refactor install --- README.md | 35 ++----------- install/bin/setup | 10 ++++ install/lib/setup/commander.rb | 91 ++++++++++++++++++++++++++++++++++ install => setup | 0 4 files changed, 104 insertions(+), 32 deletions(-) create mode 100755 install/bin/setup create mode 100644 install/lib/setup/commander.rb rename install => setup (100%) diff --git a/README.md b/README.md index ac7c499..02d4daa 100644 --- a/README.md +++ b/README.md @@ -26,42 +26,13 @@ cd ~/GitHub/rkiel git clone https://github.com/rkiel/git-utilities.git ``` -To add the scripts to your path, add the following to `.bash_profile` +To update your `.bash_profile` and `.bashrc`. ``` -export GIT_UTILITIES_BIN="~/GitHub/rkiel/git-utilities/bin" - -export PATH=${GIT_UTILITIES_BIN}:$PATH +cd ~/GitHub/rkiel/git-utilities +./install/bin/setup --user rkiel ``` -To enable `bash` tab completion for `git` commands, add the following to `.bash_profile` (OS X) or `.bashrc` (Linux) - -``` -source ~/GitHub/rkiel/git-utilities/dotfiles/git-completion.bash -``` - -To enable your `bash` prompt to display repository status, add the following to `.bash_profile` (OS X) or `.bashrc` (Linux). -``` -source ~/GitHub/rkiel/git-utilities/dotfiles/git-prompt.sh -``` - -Here's a sample prompt that includes the current branch (i.e. `$(__git_ps1 " %s")`) - -``` -export PS1='[\[\e[0;35m\]\u@\h\[\e[0m\] \[\e[1;34m\]\W\[\e[0;32m\]$(__git_ps1 " %s")\[\e[0m\]]\$ ' -``` - -To include the `bash` aliases and enable tab completion for the `feature` script, add the following to `.bashrc`. - -``` -source ~/GitHub/rkiel/git-utilities/dotfiles/bashrc -``` - -If your user id (i.e. `env|grep USER`) is generic, such as `ec2-user` or `centos` or `ubuntu`, set a `FEATURE_USER` environment variable in your `.bash_profile`. Either your `USER` or `FEATURE_USER` should be unique relative to all the users who will be creating feature branches in your git repository. - -``` -export FEATURE_USER=rkiel -``` ## Documention * [See feature](FEATURE.md) diff --git a/install/bin/setup b/install/bin/setup new file mode 100755 index 0000000..8b9603e --- /dev/null +++ b/install/bin/setup @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby + +require_relative '../lib/setup/commander' + +commander = Setup::Commander.new(ARGV) +if commander.valid? + commander.execute +else + commander.help +end diff --git a/install/lib/setup/commander.rb b/install/lib/setup/commander.rb new file mode 100644 index 0000000..9c069b5 --- /dev/null +++ b/install/lib/setup/commander.rb @@ -0,0 +1,91 @@ +require 'ostruct' +require 'optparse' +require 'json' + +module Setup + + class Commander + + attr_accessor :options + + def initialize (argv) + @options = OpenStruct.new + + @option_parser = OptionParser.new do |op| + op.banner = "Usage: setup options" + + op.on('-u','--user USER') do |argument| + options.user = argument + end + + op.on_tail('-h','--help') do |argument| + puts op + exit + end + end + + @option_parser.parse!(argv) + options.terms = argv # must be after parse! + end + + def valid? + options.user + end + + def help + puts @option_parser + exit + end + + def execute + action = options.action + + + File.open("#{ENV['HOME']}/.bash_profile", "a") do |f| + f.puts + f.puts '#############################################################' + f.puts "# added by ~/GitHub/rkiel/git-utilities/install/bin/setup" + f.puts '#############################################################' + f.puts 'export GIT_UTILITIES_BIN="~/GitHub/rkiel/git-utilities/bin"' + f.puts 'export PATH=${GIT_UTILITIES_BIN}:$PATH' + f.puts 'source ~/GitHub/rkiel/git-utilities/dotfiles/git-completion.bash' + f.puts 'source ~/GitHub/rkiel/git-utilities/dotfiles/git-prompt.sh' + f.puts "export FEATURE_USER=#{options.user}" if options.user + f.puts '#############################################################' + f.puts + end + + File.open("#{ENV['HOME']}/.bashrc", "a") do |f| + f.puts + f.puts '#############################################################' + f.puts "# added by ~/GitHub/rkiel/git-utilities/install/bin/setup" + f.puts '#############################################################' + f.puts 'source ~/GitHub/rkiel/git-utilities/dotfiles/bashrc' + f.puts '#############################################################' + f.puts + end + + end + + private + + def run_cmd ( cmd ) + puts + puts cmd + success = system cmd + unless success + error "(see above)" + end + puts + end + + def error ( msg ) + puts + puts "ERROR: #{msg}" + puts + exit + end + + end + +end diff --git a/install b/setup similarity index 100% rename from install rename to setup