symlink subdirs with .homesick_subdir
This commit is contained in:
@@ -10,6 +10,7 @@ class Homesick < Thor
|
|||||||
add_runtime_options!
|
add_runtime_options!
|
||||||
|
|
||||||
GITHUB_NAME_REPO_PATTERN = /\A([A-Za-z_-]+\/[A-Za-z_-]+)\Z/
|
GITHUB_NAME_REPO_PATTERN = /\A([A-Za-z_-]+\/[A-Za-z_-]+)\Z/
|
||||||
|
SUBDIR_FILENAME = ".homesick_subdir"
|
||||||
|
|
||||||
def initialize(args=[], options={}, config={})
|
def initialize(args=[], options={}, config={})
|
||||||
super
|
super
|
||||||
@@ -96,7 +97,17 @@ class Homesick < Thor
|
|||||||
check_castle_existance(name, "symlink")
|
check_castle_existance(name, "symlink")
|
||||||
|
|
||||||
inside castle_dir(name) do
|
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|
|
files.each do |path|
|
||||||
absolute_path = path.expand_path
|
absolute_path = path.expand_path
|
||||||
|
|
||||||
@@ -106,6 +117,22 @@ class Homesick < Thor
|
|||||||
ln_s absolute_path, adjusted_path
|
ln_s absolute_path, adjusted_path
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -120,6 +120,21 @@ describe "homesick" do
|
|||||||
existing_dotdir_link.readlink.should == dotdir
|
existing_dotdir_link.readlink.should == dotdir
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
describe "list" do
|
describe "list" do
|
||||||
|
|||||||
@@ -16,12 +16,19 @@ RSpec.configure do |config|
|
|||||||
homesick.stub(:say_status)
|
homesick.stub(:say_status)
|
||||||
end
|
end
|
||||||
|
|
||||||
def given_castle(name, path=name)
|
def given_castle(name, path=name, subdirs=[])
|
||||||
castles.directory(path) do |castle|
|
castles.directory(path) do |castle|
|
||||||
Dir.chdir(castle) do
|
Dir.chdir(castle) do
|
||||||
system "git init >/dev/null 2>&1"
|
system "git init >/dev/null 2>&1"
|
||||||
system "git remote add origin git://github.com/technicalpickles/#{name}.git >/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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user