From 57157b5c6b4e8eba5fe967413be47987ba857c76 Mon Sep 17 00:00:00 2001 From: Adam Sanderson Date: Sun, 14 Nov 2010 15:42:06 -0800 Subject: [PATCH] added a customize command to generate a template in the home directory --- bin/qw | 14 ++++++++++++-- lib/qwandry.rb | 1 + lib/qwandry/launcher.rb | 6 ++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/bin/qw b/bin/qw index 6813fa4..d341e60 100755 --- a/bin/qw +++ b/bin/qw @@ -33,8 +33,18 @@ opts = OptionParser.new do |opts| exit(0) end - opts.on("--customize", "Create files for customizing Qwandry") do - + opts.on("--customize", "Create and edit files for customizing Qwandry") do + dir = ENV['HOME'] && ENV['HOME'] + '/.qwandry/' + if !dir + puts "Home directory must be defined." + exit(1) + else + FileUtils.mkdir(dir, :verbose=>true) unless File.exist?(dir) + Dir[File.dirname(__FILE__) + '/../templates/*'].each do |path| + FileUtils.cp(path, dir, :verbose=>true, :preserve=>true) + end + @qwandry.launch dir + end exit(0) end diff --git a/lib/qwandry.rb b/lib/qwandry.rb index 19e795b..7108127 100644 --- a/lib/qwandry.rb +++ b/lib/qwandry.rb @@ -1,6 +1,7 @@ #!/usr/bin/env ruby require 'optparse' require 'set' +require 'fileutils' # Informal Spec: # diff --git a/lib/qwandry/launcher.rb b/lib/qwandry/launcher.rb index 93b32a7..989e65d 100644 --- a/lib/qwandry/launcher.rb +++ b/lib/qwandry/launcher.rb @@ -49,10 +49,12 @@ module Qwandry packages end - # Launches a `package`. Unless `editor` will check against the environment by default. + # Launches a Package or path represented by a String. Unless `editor` will + # check against the environment by default. def launch(package, editor=nil) editor ||= @editor || ENV['VISUAL'] || ENV['EDITOR'] - system editor, *package.paths + paths = package.is_a?(String) ? [package] : package.paths + system editor, *paths end private