Skip to content

Commit

Permalink
Added command for file modification through yaml file
Browse files Browse the repository at this point in the history
  • Loading branch information
Bubujka committed Dec 27, 2011
1 parent 08268f9 commit 492ea88
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ default_dir: ~/gtd/unsorted
# gem install backports
# gem install colored
# gem install naturalsort
# gem install ya2yaml

-------------------------------------

Expand Down
4 changes: 3 additions & 1 deletion cards
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ require user_commands_file if File.exist? user_commands_file

require "rubygems"
require "backports"
require 'colored'
require "colored"
$KCODE = 'UTF8'
require "ya2yaml"
require "natural_sort_kernel"

require "highline/system_extensions"
Expand Down
6 changes: 6 additions & 0 deletions cards_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ def r_file pth
`cat #{pth}`.chomp
end

def w_file pth, content
File.open(pth, "w") do |f|
f.write(content)
end
end

def rc what
cfg = YAML::load(r_file(File.dirname(ex_pth(__FILE__)) + "/rc.yaml"))
if rc_exists?
Expand Down
32 changes: 31 additions & 1 deletion commands/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@
end
end


doc "Создать новый файл из содержимого буфера обмена"
global_cmd :from_clipboard_to_new_file do |pth, mode|
title "Создать новый файл из содержимого буфера обмена"
dir = pth
dir = dirname(pth) if mode == :file

Expand All @@ -64,3 +65,32 @@
goto_file_mode pth
end

global_cmd :show_all_files_as_yaml do |pth, mode|
clear
dir = pth
dir = dirname(pth) if mode == :file
arr = []
(files = files_in_pth(dir)).each do |file|
arr.push({"file"=>file, "data" => r_file(fjoin(dir, file))})
end

FileUtils.touch(f = `mktemp --suffix=.yaml`.chomp)

w_file(f, arr.ya2yaml(:syck_compatible => true))

system("vim #{f}")

t = YAML::load(r_file(f))

new_files = t.map {|v| v["file"]}

(files - new_files).each do |v|
FileUtils.rm(fjoin(dir, v))
end

t.each do |v|
w_file(fjoin(dir, v["file"]), v["data"])
end

FileUtils.rm(f)
end
2 changes: 1 addition & 1 deletion dir_mode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def default_dir_action dir
t = pp_list(colored_dirs, 'Dirs', true).gsub(/\([0-9]+\)/){|v| v.blue}.chomp
puts t

t = pp_list(files_in_pth(dir), "Files", true).chomp
puts pp_list(files_in_pth(dir), "Files", true).chomp
end

def do_what_i_say_in_dir dir
Expand Down
2 changes: 2 additions & 0 deletions rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bind:
m: move_and_return_to_rnd
M: move_edit_and_return_to_rnd
q: quit
"": rnd_file_in_dir
r: rnd_file_in_dir
R: goto_random_in_default_dir
u: go_upper_dir
Expand All @@ -32,3 +33,4 @@ bind:
b: run_file_in_browser
B: run_content_in_browser
|: pipe_file
y: show_all_files_as_yaml

0 comments on commit 492ea88

Please sign in to comment.