From ccddbb13168c6d9873cf48332aed256528f74775 Mon Sep 17 00:00:00 2001 From: Eric West Date: Mon, 20 May 2013 19:11:48 -0500 Subject: [PATCH] Track now properly traverses folder structure --- .gitignore | 4 ++++ lib/homesick.rb | 14 ++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 88cf2e9..e605e1e 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,7 @@ pkg # # For vim: *.swp +# +# For IDEA: +.idea/ +*.iml diff --git a/lib/homesick.rb b/lib/homesick.rb index d37d451..340ac87 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -113,16 +113,22 @@ class Homesick < Thor desc "track FILE CASTLE", "add a file to a castle" def track(file, castle) castle = Pathname.new(castle) - file = Pathname.new(file) + file = Pathname.new(file.chomp('/')) check_castle_existance(castle, 'track') absolute_path = file.expand_path - castle_path = castle_dir(castle) + relative_dir = absolute_path.relative_path_from(home_dir).dirname + castle_path = Pathname.new(castle_dir(castle)).join(relative_dir) + + unless castle_path.exist? + FileUtils.mkdir_p castle_path + end + mv absolute_path, castle_path inside home_dir do - absolute_path = castle_dir(castle) + file.basename - home_path = home_dir + file + absolute_path = castle_path + file.basename + home_path = home_dir + relative_dir + file.basename ln_s absolute_path, home_path end