symlink subdirs with .homesick_subdir
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user