From bba0e3ed7dd1694120c73e13a5e20c9888c4dbed Mon Sep 17 00:00:00 2001 From: muratayusuke Date: Sun, 26 May 2013 17:12:28 +0000 Subject: [PATCH] support nested dir in .homesick_subdir --- lib/homesick.rb | 13 +++++++++++-- spec/homesick_spec.rb | 17 +++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/homesick.rb b/lib/homesick.rb index 6b28ef5..242bec3 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -106,9 +106,18 @@ class Homesick < Thor subdirs.push(subdir.chomp) end end + ignore_dirs = [] + subdirs.each do |subdir| + splited_subdir = Pathname.new(subdir).split + ignore_dir = splited_subdir[0].to_s + if ignore_dir == "." then + ignore_dir = splited_subdir[1].to_s + end + ignore_dirs.push(ignore_dir) + end # link files - files = Pathname.glob('{.*,*}').reject{|a| [".", "..", SUBDIR_FILENAME, subdirs].flatten.include?(a.to_s)} + files = Pathname.glob('{.*,*}').reject{|a| [".", "..", SUBDIR_FILENAME, ignore_dirs].flatten.include?(a.to_s)} files.each do |path| absolute_path = path.expand_path @@ -127,7 +136,7 @@ class Homesick < Thor absolute_path = path.expand_path inside home_dir.join(subdir) do - adjusted_path = (home_dir + path).basename + adjusted_path = (home_dir + subdir + path).basename ln_s absolute_path, adjusted_path end diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index fed4a2c..6596df1 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -122,9 +122,8 @@ describe "homesick" do end end - context "when .homesick_subdir exists" do + context "with '.config' in .homesick_subdir" do let(:castle) { given_castle("glencairn", "glencairn", [".config"]) } - it "can symlink in sub directory" do dotdir = castle.directory(".config") dotfile = dotdir.file(".some_dotfile") @@ -136,6 +135,20 @@ describe "homesick" do home_dotdir.join(".some_dotfile").readlink.should == dotfile end end + + context "with '.config/appA' in .homesick_subdir" do + let(:castle) { given_castle("glencairn", "glencairn", [".config/appA"]) } + it "can symlink in nested sub directory" do + dotdir = castle.directory(".config").directory("appA") + dotfile = dotdir.file(".some_dotfile") + + homesick.symlink("glencairn") + + home_dotdir = home.join(".config").join("appA") + home_dotdir.symlink?.should == false + home_dotdir.join(".some_dotfile").readlink.should == dotfile + end + end end describe "list" do