vimrecover 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2008-06-08
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,9 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/vimrecover
6
+ lib/vimrecover.rb
7
+ lib/vim-swap.rb
8
+ lib/vim-version.rb
9
+ test/test_vimrecover.rb
@@ -0,0 +1,41 @@
1
+ = vimrecover
2
+
3
+ * http://www.lesismore.co.za
4
+ * http://www.freewebs.com/lesliev
5
+
6
+ == DESCRIPTION:
7
+
8
+ This package provides a handy command to help you recover from Vim recovery files.
9
+
10
+ Vim makes .swp files as you edit your files so that if an edit session crashes you
11
+ can recover the latest changes you haven't saved. Unfortunately though, there's no
12
+ easy way to compare a saved file with the recovery file, so if a session does crash
13
+ you are often left with many .swp files that you have to save under new names one
14
+ by one and compare to the original files.
15
+
16
+ vimrecover searches for swap files in the current directory, converts them to
17
+ files that can be compared to the original files, lets you compare them with
18
+ meld, deletes them if they are the same as the original files and generally
19
+ helps you clean up the mess.
20
+
21
+ vimrecover is an interactive command-line program.
22
+
23
+ == SYNOPSIS:
24
+
25
+ vimrecover
26
+
27
+ == REQUIREMENTS:
28
+
29
+ * Vim 7.1, may work with others but you'd need to test.
30
+ * meld, if you want to use it.
31
+
32
+ == INSTALL:
33
+
34
+ * sudo gem install vimrecover
35
+
36
+ == LICENSE:
37
+
38
+ The latest version of the GNU General Public License.
39
+
40
+ Copyright (c) 2008 Leslie Viljoen
41
+
@@ -0,0 +1,11 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/vimrecover.rb'
6
+
7
+ Hoe.new('vimrecover', VimRecover::VERSION) do |p|
8
+ p.developer('lesliev', 'leslieviljoen@gmail.com')
9
+ end
10
+
11
+ # vim: syntax=Ruby
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'vimrecover'
4
+ require 'vim-swap'
5
+ require 'vim-version'
6
+ require 'fileutils'
7
+ include FileUtils
8
+
9
+ swp_dir = "swp"
10
+
11
+ if !VimVersion.matches("7.1")
12
+ puts
13
+ puts "My VIM version check returned '#{vim_version}', I was expecting '#{vim_version_needed}'."
14
+ puts "This script relies on the format of the output of 'vim -r' and is unlikely"
15
+ puts "to work if that has changed. You will need to get a different version of"
16
+ puts "this script or do some hacking."
17
+ puts
18
+ exit
19
+ end
20
+
21
+ if !File.directory?(swp_dir)
22
+ begin
23
+ mkdir swp_dir
24
+ rescue => e
25
+ puts
26
+ puts "Error creating 'swp' directory to store processed swap files:"
27
+ puts e.message
28
+ exit
29
+ end
30
+ end
31
+
32
+ VimSwap.new.each_not_running do |f| #ARGV.each do |f| # for file-by-file
33
+ next if f.filename == "[No Name]"
34
+
35
+ puts
36
+ puts "Attempting to recover #{f.filename.inspect} using #{f.swapname.inspect}"
37
+
38
+ recovered_file = "#{File.expand_path(f.filename)}.recover"
39
+
40
+ if !File.exist?(f.swapname)
41
+ puts "Swap file #{f.swapname.inspect} not found - skipping"
42
+ exit
43
+ end
44
+
45
+ `vim -r #{f.filename} -c 'w #{recovered_file}' -c 'q'`
46
+
47
+ if `diff #{f.filename} #{recovered_file}`.empty?
48
+ puts " recovered file identical to existing file: removing"
49
+
50
+ rm recovered_file
51
+ end
52
+
53
+ mv(f.swapname, swp_dir)
54
+ end
55
+
56
+ recovered_files = Dir.glob("*.recover")
57
+ if !recovered_files.empty?
58
+ puts
59
+ puts "Recovery files in this directory:"
60
+
61
+ puts recovered_files.join("\n")
62
+
63
+ recovered_files.each do |f|
64
+ puts "\nFile: '#{f}'"
65
+ print "(n)ext, (m)eld, (d)elete or (q)uit? "
66
+
67
+ begin
68
+ `stty raw -echo`
69
+ while(!"nmdq".include?(resp = STDIN.getc))
70
+ end
71
+ ensure
72
+ `stty -raw echo`
73
+ end
74
+
75
+ puts
76
+ case resp.chr
77
+ when "n": next
78
+ when "m": `meld #{f} #{f[0, f.length-8]}`
79
+ when "d": rm f; next
80
+ when "q": puts; exit
81
+ end
82
+
83
+ redo
84
+ end
85
+ end
86
+
87
+ swap_files = Dir.glob("swp/.*.sw?")
88
+ if swap_files.length > 0
89
+ puts "\nSwap files now in swp directory:"
90
+ puts swap_files.join("\n")
91
+ puts
92
+ print "They should be converted to recovery files now, delete them? (y/n)"
93
+
94
+ begin
95
+ `stty raw -echo`
96
+ while(!"yn".include?(resp = STDIN.getc))
97
+ end
98
+ ensure
99
+ `stty -raw echo`
100
+ end
101
+
102
+ if(resp.chr == "y")
103
+ swap_files.each do |sf|
104
+ rm sf
105
+ end
106
+ end
107
+ end
108
+
109
+ puts
110
+
111
+
112
+
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'vim-version'
4
+ require 'open3'
5
+
6
+ class VimSwapFile
7
+ attr_reader :id, :swapname, :filename, :pid
8
+
9
+ def initialize(swapname, body)
10
+ if !VimVersion.matches("7.1")
11
+ raise("This class requires Vim 7.1")
12
+ end
13
+
14
+ swapname =~ /^(\d+)\. +(.*)$/
15
+ @id = $1
16
+ @swapname = $2.strip
17
+ get_body(body)
18
+ end
19
+
20
+ def get_body(body)
21
+ fields = {}
22
+ body.split(/\r/).each do |line|
23
+ line =~ /^ +(.+): (.+)$/
24
+ fields[$1] = $2
25
+ end
26
+ @filename = fields["file name"]
27
+ @pid = fields["process ID"]
28
+ @running = false
29
+ if @pid =~ /\(still running\)$/
30
+ @pid = @pid.split(" ")[0]
31
+ @running = true
32
+ end
33
+ end
34
+
35
+ def running?
36
+ @running
37
+ end
38
+
39
+ def to_s
40
+ "id: #{@id}\nswapname: #{@swapname}\nfilename: #{@filename}\npid: #{@pid}\nrunning: #{@running}"
41
+ end
42
+ end
43
+
44
+ class VimSwap
45
+ attr_reader :files
46
+
47
+ def initialize
48
+ Open3.popen3("vim -r") do |stdin, stdout, stderr|
49
+ line = stderr.gets
50
+ line = stderr.gets
51
+ current = ""
52
+ while (line = stderr.gets) && line !~ /^ +In directory.*$/
53
+ current += line.to_s
54
+ end
55
+
56
+ names = current.scan(/^\d+\..*$/)
57
+ bodies = current.split(/^\d+\..*$/)
58
+ bodies.shift
59
+
60
+ @files = []
61
+ names.each_with_index do |swapname, index|
62
+ @files << VimSwapFile.new(swapname, bodies[index])
63
+ end
64
+ end
65
+ end
66
+
67
+ def each
68
+ @files.each do |f|
69
+ yield f
70
+ end
71
+ end
72
+
73
+ def each_running
74
+ @files.each do |f|
75
+ yield f if f.running?
76
+ end
77
+ end
78
+
79
+ def each_not_running
80
+ @files.each do |f|
81
+ yield f if !f.running?
82
+ end
83
+ end
84
+ end
85
+
86
+ if __FILE__ == $0
87
+ puts
88
+ VimSwap.new.files.each do |file|
89
+ puts file
90
+ puts
91
+ end
92
+ end
93
+
94
+
95
+
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ class VimVersion
4
+ @matches_cached = nil
5
+ def self.matches(version_string = "7.1")
6
+ return @matches_cached if @matches_cached
7
+ vim_version = `vim --version`.split("\n")[0].split(" ")[4]
8
+ @matches_cached = (vim_version == version_string)
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+
2
+ class VimRecover
3
+ VERSION='1.0.0'
4
+ end
5
+
File without changes
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vimrecover
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - lesliev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-10 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.5.3
23
+ version:
24
+ description: This package provides a handy command to help you recover from Vim recovery files. Vim makes .swp files as you edit your files so that if an edit session crashes you can recover the latest changes you haven't saved. Unfortunately though, there's no easy way to compare a saved file with the recovery file, so if a session does crash you are often left with many .swp files that you have to save under new names one by one and compare to the original files. vimrecover searches for swap files in the current directory, converts them to files that can be compared to the original files, lets you compare them with meld, deletes them if they are the same as the original files and generally helps you clean up the mess. vimrecover is an interactive command-line program.
25
+ email:
26
+ - leslieviljoen@gmail.com
27
+ executables:
28
+ - vimrecover
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ files:
36
+ - History.txt
37
+ - Manifest.txt
38
+ - README.txt
39
+ - Rakefile
40
+ - bin/vimrecover
41
+ - lib/vimrecover.rb
42
+ - lib/vim-swap.rb
43
+ - lib/vim-version.rb
44
+ - test/test_vimrecover.rb
45
+ has_rdoc: true
46
+ homepage: http://www.lesismore.co.za
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --main
50
+ - README.txt
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project: vimrecover
68
+ rubygems_version: 1.1.1
69
+ signing_key:
70
+ specification_version: 2
71
+ summary: This package provides a handy command to help you recover from Vim recovery files
72
+ test_files:
73
+ - test/test_vimrecover.rb