diff --git a/lib/homesick.rb b/lib/homesick.rb index d043feb..c0ebe64 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -11,6 +11,7 @@ class Homesick < Thor add_runtime_options! GITHUB_NAME_REPO_PATTERN = /\A([A-Za-z_-]+\/[A-Za-z_-]+)\Z/ + SUBDIR_FILENAME = ".homesick_subdir" def initialize(args=[], options={}, config={}) super @@ -97,7 +98,17 @@ class Homesick < Thor check_castle_existance(name, "symlink") inside castle_dir(name) do - files = Pathname.glob('{.*,*}').reject{|a| [".",".."].include?(a.to_s)} + # prepare subdir information + subdir_file = Pathname.new(".").join(SUBDIR_FILENAME) + subdirs = [] + if subdir_file.exist? then + subdir_file.readlines.each do |subdir| + subdirs.push(subdir.chomp) + end + end + + # link files + files = Pathname.glob('{.*,*}').reject{|a| [".", "..", SUBDIR_FILENAME, subdirs].flatten.include?(a.to_s)} files.each do |path| absolute_path = path.expand_path @@ -107,6 +118,22 @@ class Homesick < Thor ln_s absolute_path, adjusted_path end end + + # link files in subdirs + subdirs.each do |subdir| + inside subdir do + files = Pathname.glob('{.*,*}').reject{|a| [".", ".."].include?(a.to_s)} + files.each do |path| + absolute_path = path.expand_path + + inside home_dir.join(subdir) do + adjusted_path = (home_dir + path).basename + + ln_s absolute_path, adjusted_path + end + end + end + end end end diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index 99dc6cc..3e68559 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -121,6 +121,21 @@ describe "homesick" do existing_dotdir_link.readlink.should == dotdir end end + + context "when .homesick_subdir exists" do + let(:castle) { given_castle("glencairn", "glencairn", [".config"]) } + + it "can symlink in sub directory" do + dotdir = castle.directory(".config") + dotfile = dotdir.file(".some_dotfile") + + homesick.symlink("glencairn") + + home_dotdir = home.join(".config") + home_dotdir.symlink?.should == false + home_dotdir.join(".some_dotfile").readlink.should == dotfile + end + end end describe "list" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 498bbab..26225f4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,12 +16,19 @@ RSpec.configure do |config| homesick.stub(:say_status) end - def given_castle(name, path=name) + def given_castle(name, path=name, subdirs=[]) castles.directory(path) do |castle| Dir.chdir(castle) do system "git init >/dev/null 2>&1" system "git remote add origin git://github.com/technicalpickles/#{name}.git >/dev/null 2>&1" - return castle.directory("home") + castle_home = castle.directory("home") + if subdirs then + subdir_file = castle_home.join(Homesick::SUBDIR_FILENAME) + subdirs.each do |subdir| + system "echo #{subdir} >> #{subdir_file}" + end + end + return castle_home end end end