diff --git a/cards b/cards index 6032b07..79b1fb8 100755 --- a/cards +++ b/cards @@ -53,9 +53,9 @@ def main exit end dir = if have_args? - ex_pth ARGV[0] + ARGV[0].ex else - ex_pth(rc("default_dir")) + rc("default_dir").ex end goto_dir_mode dir diff --git a/cards_helper.rb b/cards_helper.rb index 702ad0b..e3ed2d8 100644 --- a/cards_helper.rb +++ b/cards_helper.rb @@ -4,16 +4,13 @@ def have_args? end def config_file - ex_pth @@options[:config] + @@options[:config].ex end def rc_exists? File.exists?(config_file) end -def ex_pth pth - File.expand_path(pth) -end def r_file pth `cat #{pth}`.chomp @@ -26,7 +23,7 @@ def w_file pth, content end def rc what - cfg = YAML::load(r_file(File.dirname(ex_pth(__FILE__)) + "/rc.yaml")) + cfg = YAML::load(r_file(File.dirname(__FILE__.ex) + "/rc.yaml")) if rc_exists? cfg.deep_merge!(YAML::load(r_file(config_file))) end @@ -133,7 +130,7 @@ def get_char end def dbg wtf - open(ex_pth('~/.bucardslog'), 'a') { |f| f.puts ("\n[#{Time.now}]#{wtf}")} + open('~/.bucardslog'.ex, 'a') { |f| f.puts ("\n[#{Time.now}]#{wtf}")} end @@ -228,6 +225,10 @@ def esc str.gsub!(/\n/, "'\n'") str end + + def ex + File.expand_path(self) + end end def ob diff --git a/commands/dir.rb b/commands/dir.rb index b92a889..59ca108 100644 --- a/commands/dir.rb +++ b/commands/dir.rb @@ -6,7 +6,7 @@ doc "Начать редактировать .prj файл" dir_cmd :goto_prj_file do |dir| - edit_file ex_pth(fjoin(dir, '.prj')) + edit_file fjoin(dir, '.prj').ex end dir_cmd :select_and_goto_dir do |dir| @@ -82,7 +82,7 @@ doc "Перейти на каталог выше" dir_cmd :go_upper_dir do |dir| - goto_dir_mode ex_pth(fjoin(dir, '..')) + goto_dir_mode fjoin(dir, '..').ex end doc "Перейти к случайному файлу в текущем каталоге" diff --git a/commands/file.rb b/commands/file.rb index f3615bf..e9c0b26 100644 --- a/commands/file.rb +++ b/commands/file.rb @@ -5,7 +5,7 @@ print "Enter dest directory: " name = gets.chomp # todo: если путь начинается с ~ - надо не джоинить его с директорией - pth = ex_pth(fjoin(dirname(file), name)) + pth = fjoin(dirname(file), name).ex dir = dirname(pth) FileUtils::mkdir_p(dir) FileUtils::cp(file, pth) @@ -20,7 +20,7 @@ print "Enter dest directory: " name = gets.chomp # todo: если путь начинается с ~ - надо не джоинить его с директорией - dest_dir = ex_pth(fjoin(dir, name)) + dest_dir = fjoin(dir, name).ex dest_pth = fjoin(dest_dir, find_next_num_in_dir(dest_dir).to_s) FileUtils::mkdir_p(dest_dir) safe_mv(file, dest_pth) @@ -35,7 +35,7 @@ print "Enter dest directory: " name = gets.chomp # todo: если путь начинается с ~ - надо не джоинить его с директорией - dest_dir = ex_pth(fjoin(dir, name)) + dest_dir = fjoin(dir, name).ex dest_pth = fjoin(dest_dir, find_next_num_in_dir(dest_dir).to_s) FileUtils::mkdir_p(dest_dir) safe_mv(file, dest_pth) @@ -81,7 +81,7 @@ file_cmd :move_file_upsubdir do |file| title "Перенос файла в соседний-родительский каталог" - dir = ex_pth(fjoin(dirname(file), '..')) + dir = fjoin(dirname(file), '..').ex clear if dest = dmenu(dirs_in_pth(dir)) safe_mv(file, fjoin(dir, dest)) diff --git a/commands/git.rb b/commands/git.rb index abd2842..53148eb 100644 --- a/commands/git.rb +++ b/commands/git.rb @@ -1,48 +1,48 @@ dir_cmd :git_add do |dir| clear - system "cd #{dir}; git add ." + system "cd #{dir.esc}; git add ." end dir_cmd :git_status do |dir| clear - system "cd #{dir}; git status" + system "cd #{dir.esc}; git status" char_gets end dir_cmd :git_log do |dir| clear - system "cd #{dir}; git log" + system "cd #{dir.esc}; git log" end dir_cmd :git_commit do |dir| clear - system "cd #{dir}; git commit" + system "cd #{dir.esc}; git commit" char_gets end dir_cmd :git_pull do |dir| clear - system "cd #{dir}; git pull" + system "cd #{dir.esc}; git pull" char_gets end dir_cmd :git_push do |dir| clear - system "cd #{dir}; git push" + system "cd #{dir.esc}; git push" char_gets end dir_cmd :git_clear do |dir| clear - system "cd #{dir}; git ls-files --deleted | xargs git rm" # thx to http://snippets.dzone.com/posts/show/5669 + system "cd #{dir.esc}; git ls-files --deleted | xargs git rm" # thx to http://snippets.dzone.com/posts/show/5669 end dir_cmd :git_add_clear_commit_push do |dir| clear - system "cd #{dir}; git add ." - system "cd #{dir}; git ls-files --deleted | xargs git rm" - system "cd #{dir}; git commit" - system "cd #{dir}; git push" + system "cd #{dir.esc}; git add ." + system "cd #{dir.esc}; git ls-files --deleted | xargs git rm" + system "cd #{dir.esc}; git commit" + system "cd #{dir.esc}; git push" puts puts "Finished".green char_gets diff --git a/commands/global.rb b/commands/global.rb index 8b616a9..6f49b7a 100644 --- a/commands/global.rb +++ b/commands/global.rb @@ -9,7 +9,7 @@ end global_cmd :go_home do - goto_dir_mode ex_pth(rc("default_dir")) + goto_dir_mode rc("default_dir").ex end global_cmd :show_help do |pth, mode| @@ -25,12 +25,12 @@ filename = basename(pth) files.each_cons(2) do |element, next_element| if(element == filename) - goto_file_mode ex_pth(fjoin(dir, next_element)) + goto_file_mode fjoin(dir, next_element).ex end end elsif mode == :dir files = files_in_pth(pth) - goto_file_mode ex_pth(fjoin(pth, files.first)) + goto_file_mode fjoin(pth, files.first).ex end end @@ -41,12 +41,12 @@ filename = basename(pth) files.each_cons(2) do |element, next_element| if(next_element == filename) - goto_file_mode ex_pth(fjoin(dir, element)) + goto_file_mode fjoin(dir, element).ex end end elsif mode == :dir files = files_in_pth(pth) - goto_file_mode ex_pth(fjoin(pth, files.last)) + goto_file_mode fjoin(pth, files.last).ex end end