tms 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,6 +6,46 @@ View avaliable Time Machine backups and show changes
6
6
 
7
7
  Name from [fernlightning.com](http://www.fernlightning.com/doku.php?id=software:misc:tms)
8
8
 
9
+ ## INSTALL:
10
+
11
+ gem install progress # use sudo if you need
12
+
13
+ ## USAGE:
14
+
15
+ List backups:
16
+
17
+ tms
18
+
19
+ Show changes for last backup (same as `tms -2 -1`):
20
+
21
+ tms -1
22
+
23
+ Show changes between first and last backups:
24
+
25
+ tms 1 -1
26
+
27
+ Show changes for last backup only under your user dir:
28
+
29
+ tms -1 -f ~
30
+
31
+ List backups from another Time Machine:
32
+
33
+ tms -d `/Volumes/Time Machine/Backups.backupdb/user name`
34
+
35
+ Show backups in progress:
36
+
37
+ tms -i
38
+
39
+ Other options:
40
+
41
+ tms -h
42
+
43
+ ## REQUIREMENTS:
44
+
45
+ * OS X
46
+ * ruby
47
+ * Time Machine
48
+
9
49
  ## Copyright
10
50
 
11
51
  Copyright (c) 2010 Boba Fat. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 1.3.1
data/bin/tms CHANGED
@@ -3,22 +3,34 @@
3
3
  require 'tms'
4
4
  require 'optparse'
5
5
 
6
- def option_parser
7
- @option_parser ||= OptionParser.new do |op|
8
- op.banner = <<-BANNER
9
- #{op.program_name}, version #{Tms.version}
6
+ def option_parser(type = nil)
7
+ @option_parser ||= {}
8
+ @option_parser[type] ||= OptionParser.new do |op|
9
+ op.banner = <<-TEXT
10
+ #{op.program_name}, version #{Tms.version}
10
11
 
11
- Usege:
12
- List: #{op.program_name} [options]
13
- Diff: #{op.program_name} [options] id|nXXX [id|nXXX]
14
- BANNER
12
+ Usege:
13
+ List: #{op.program_name} [options]
14
+ Diff: #{op.program_name} [options] id|nXXX [id|nXXX]
15
+
16
+ TEXT
17
+
18
+ if type
19
+ op.banner << <<-TEXT
20
+ Options for #{type} (-h to view all options):
21
+
22
+ TEXT
23
+ end
15
24
 
16
25
  op.on('-d', '--directory DIRECTORY', 'Use backup directory') do |backups_dir|
17
26
  Tms::Backup.backups_dir = backups_dir
18
27
  end
19
28
 
20
- op.on('-f', '--filter DIRECTORY', 'Show diff starting from directory', ' (can be used multiple times)') do |filter_dir|
21
- Tms::Backup.add_filter_dir(filter_dir)
29
+ unless type == :list
30
+ op.on('-f', '--filter DIRECTORY', 'Show diff starting from directory',
31
+ ' (can be used multiple times)') do |filter_dir|
32
+ Tms::Backup.add_filter_dir(filter_dir)
33
+ end
22
34
  end
23
35
 
24
36
  op.on('-i', '--[no-]in-progress', 'Show backups in progress',
@@ -27,20 +39,28 @@ def option_parser
27
39
  Tms::Backup.show_in_progress = show_in_progress
28
40
  end
29
41
 
30
- op.on('-l', '--[no-]long', 'Show more info about backup in list') do |show_all_columns|
31
- Tms::Backup.show_all_columns = show_all_columns
42
+ unless type == :diff
43
+ op.on('-l', '--[no-]long', 'Show more info about backup in list') do |show_all_columns|
44
+ Tms::Backup.show_all_columns = show_all_columns
45
+ end
32
46
  end
33
47
 
34
- op.on('--[no-]color', 'Use color', ' (true by default if stdout is a tty)') do |colorize|
48
+ op.on('--[no-]color', 'Use color',
49
+ ' (true by default if stdout is a tty)') do |colorize|
35
50
  Tms::Backup.colorize = colorize
36
51
  end
37
52
 
38
- op.on('--[no-]progress', 'Show progress when counting folder size', ' (true by default if stderr is a tty)') do |show_progress|
39
- Tms::Backup.show_progress = show_progress
53
+ unless type == :list
54
+ op.on('--[no-]progress', 'Show progress when counting folder size',
55
+ ' (true by default if stderr is a tty)') do |show_progress|
56
+ Tms::Backup.show_progress = show_progress
57
+ end
40
58
  end
41
59
 
42
- op.on('--[no-]decimal', 'Use base 10 size') do |use_decimal|
43
- Tms::Space.base10 = use_decimal
60
+ unless type == :list
61
+ op.on('--[no-]decimal', 'Use base 10 size') do |use_decimal|
62
+ Tms::Space.base10 = use_decimal
63
+ end
44
64
  end
45
65
 
46
66
  op.on_tail('-h', '--help', 'Show this message') do
@@ -48,7 +68,7 @@ def option_parser
48
68
  exit
49
69
  end
50
70
 
51
- op.on_tail('--version', 'Show version') do
71
+ op.on_tail('-v', '--version', 'Show version') do
52
72
  puts Tms.version
53
73
  exit
54
74
  end
@@ -57,9 +77,14 @@ end
57
77
 
58
78
  ids, options = ARGV.partition{ |arg| arg =~ /^[\-n]?\d+$/ }
59
79
  begin
60
- option_parser.parse!(options)
80
+ option_parser.parse(options) # exits on -h or -v
81
+ rescue OptionParser::ParseError => e
82
+ end
83
+ type = ids.empty? ? :list : :diff
84
+ begin
85
+ option_parser(type).parse!(options)
61
86
  rescue OptionParser::ParseError => e
62
- abort "#{e.to_s}\n#{option_parser.help}"
87
+ abort "#{e.to_s}\n#{option_parser(type).help}"
63
88
  end
64
89
  unless options.empty?
65
90
  abort "Unknown arguments: #{options.join(' ')}"
@@ -67,11 +67,42 @@ module Tms
67
67
  $stdout.puts "#{s}#{CLEAR_LINE}"
68
68
  end
69
69
 
70
+ def trim_right_colored(s, length)
71
+ length = 0 if length < 0
72
+ colorizers = []
73
+ s.gsub(/\e\[\d+(;\d+)*m/) do
74
+ if $`.length < length
75
+ length += $&.length
76
+ else
77
+ colorizers << $&
78
+ end
79
+ end
80
+ s[0, length] << colorizers.join('')
81
+ end
82
+
83
+ def trim_left_colored(s, length)
84
+ length = 0 if length < 0
85
+ colorizers = []
86
+ s.reverse.gsub(/m(\d+;)*\d+\[\e/) do
87
+ if $`.length < length
88
+ length += $&.length
89
+ else
90
+ colorizers << $&.reverse
91
+ end
92
+ end
93
+ length = s.length if length > s.length
94
+ colorizers.reverse.join('') << s[-length, length]
95
+ end
96
+
70
97
  def progress
71
98
  if Tms::Backup.show_progress?
72
99
  @last_progress ||= Time.now
73
100
  if (now = Time.now) > @last_progress + 0.1
74
- $stderr.print "#{yield}#{CLEAR_LINE}\r"
101
+ line = yield.to_s
102
+ if width = terminal_width
103
+ line = trim_left_colored(line, terminal_width - 1)
104
+ end
105
+ $stderr.print "#{line}#{CLEAR_LINE}\r"
75
106
  @last_progress = now
76
107
  end
77
108
  end
@@ -106,5 +137,33 @@ module Tms
106
137
  @total += sub_total
107
138
  end
108
139
  end
140
+
141
+ def command_exists?(command)
142
+ `which #{command}`
143
+ $?.success?
144
+ end
145
+
146
+ # method from hirb: https://github.com/cldwalker/hirb
147
+ # Returns [width, height] of terminal when detected, nil if not detected.
148
+ # Think of this as a simpler version of Highline's Highline::SystemExtensions.terminal_size()
149
+ def terminal_size
150
+ if (ENV['COLUMNS'] =~ /^\d+$/) && (ENV['LINES'] =~ /^\d+$/)
151
+ [ENV['COLUMNS'].to_i, ENV['LINES'].to_i]
152
+ elsif (RUBY_PLATFORM =~ /java/ || (!STDIN.tty? && ENV['TERM'])) && command_exists?('tput')
153
+ [`tput cols`.to_i, `tput lines`.to_i]
154
+ elsif STDIN.tty? && command_exists?('stty')
155
+ `stty size`.scan(/\d+/).map{ |s| s.to_i }.reverse
156
+ else
157
+ nil
158
+ end
159
+ rescue
160
+ nil
161
+ end
162
+
163
+ def terminal_width
164
+ if size = terminal_size
165
+ size[0]
166
+ end
167
+ end
109
168
  end
110
169
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tms}
8
- s.version = "1.3.0"
8
+ s.version = "1.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Boba Fat"]
12
- s.date = %q{2010-12-11}
12
+ s.date = %q{2010-12-12}
13
13
  s.default_executable = %q{tms}
14
14
  s.description = %q{View avaliable Time Machine backups and show their diff}
15
15
  s.executables = ["tms"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tms
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 0
10
- version: 1.3.0
9
+ - 1
10
+ version: 1.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Boba Fat
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-11 00:00:00 +03:00
18
+ date: 2010-12-12 00:00:00 +03:00
19
19
  default_executable: tms
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency