Skip to content

Commit

Permalink
Cleared code from ex_pth function
Browse files Browse the repository at this point in the history
  • Loading branch information
Bubujka committed Jan 9, 2012
1 parent 72e3ae4 commit a598f85
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 30 deletions.
4 changes: 2 additions & 2 deletions cards
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions cards_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -228,6 +225,10 @@ def esc
str.gsub!(/\n/, "'\n'")
str
end

def ex
File.expand_path(self)
end
end

def ob
Expand Down
4 changes: 2 additions & 2 deletions commands/dir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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 "Перейти к случайному файлу в текущем каталоге"
Expand Down
8 changes: 4 additions & 4 deletions commands/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
22 changes: 11 additions & 11 deletions commands/git.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions commands/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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

Expand All @@ -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

Expand Down

0 comments on commit a598f85

Please sign in to comment.