do_stuff 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,6 +15,9 @@ module DoStuff
15
15
  # This will be set by options if we are to change the text of a task.
16
16
  edit_target = nil
17
17
 
18
+ # This will be set by options if we are to renumber the tasks.
19
+ renumber_tasks = false
20
+
18
21
  taskfile = File.expand_path(File.read(dostuffrc).chomp)
19
22
  unless File.exists?(taskfile)
20
23
  FileUtils.mkdir_p(File.dirname(taskfile))
@@ -31,6 +34,10 @@ module DoStuff
31
34
  end
32
35
  end
33
36
 
37
+ opts.on('-r') do
38
+ renumber_tasks = true
39
+ end
40
+
34
41
  opts.on('--standalone FILE') do |file|
35
42
  if defined?(::DoStuff::Standalone)
36
43
  Standalone.save(file)
@@ -62,7 +69,6 @@ module DoStuff
62
69
  if edit_target
63
70
  before_text = tasklist[edit_target]
64
71
  tasklist[edit_target] = argv.join(' ')
65
- tasklist.write!
66
72
 
67
73
  if !before_text
68
74
  puts "Added ##{edit_target}: #{tasklist[edit_target]}"
@@ -72,27 +78,45 @@ module DoStuff
72
78
  puts "#{GREEN}+#{tasklist[edit_target]}#{RESET}"
73
79
  end
74
80
 
81
+ write! tasklist, renumber_tasks
75
82
  exit
76
83
  end
77
84
 
78
85
  if argv.length == 0
79
- tasklist.tasks.sort.each do |num, task|
80
- puts "#{num}. #{task}"
86
+ if renumber_tasks
87
+ write! tasklist, true
88
+ else
89
+ tasklist.tasks.sort.each do |num, task|
90
+ puts "#{num}. #{task}"
91
+ end
81
92
  end
82
93
  elsif argv.length == 1 && argv[0] =~ /^\d+$/
83
94
  task_num = argv[0].to_i
84
95
  abort "There is no task ##{task_num}." unless tasklist.tasks.key?(task_num)
85
96
  task = tasklist[task_num]
86
97
  tasklist.delete(task_num)
87
- tasklist.write!
88
98
  puts "Erased ##{task_num}: #{task}"
99
+ write! tasklist, renumber_tasks
89
100
  else
90
101
  # If nothing else matches, treat the arguments as a task description.
91
102
  task = argv.join(' ')
92
103
  task_num = tasklist.add(task)
93
- tasklist.write!
94
104
  puts "Added ##{task_num}: #{task}"
105
+ write! tasklist, renumber_tasks
106
+ end
107
+ end
108
+
109
+ def self.write!(tasklist, renumber = false)
110
+ if renumber
111
+ tasklist.renumber!
112
+
113
+ puts "Renumbered tasks:"
114
+ tasklist.tasks.sort.each do |num, task|
115
+ puts "#{num}. #{task}"
116
+ end
95
117
  end
118
+
119
+ tasklist.write!
96
120
  end
97
121
 
98
122
  def self.edit(file, task_num=nil)
@@ -152,22 +176,15 @@ module DoStuff
152
176
  end
153
177
 
154
178
  def self.run_editor(file, task_num=nil)
155
- editor = ENV['EDITOR']
156
-
157
- unless editor
158
- $stderr.puts "The EDITOR environment variable isn't set (defaulting to vim)."
159
- editor = 'vim'
160
- end
161
-
162
179
  if task_num
163
180
  target = File.readlines(file).find_index do |line|
164
181
  line.start_with?("#{task_num}. ")
165
182
  end
166
183
 
167
184
  abort "Could not find task ##{task_num}." unless target
168
- system(editor, file, "+#{target + 1}")
185
+ system(ENV['EDITOR'], file, "+#{target + 1}")
169
186
  else
170
- system(editor, file)
187
+ system(ENV['EDITOR'], file)
171
188
  end
172
189
  end
173
190
 
@@ -180,6 +197,7 @@ usage: #{program} list unfinished tasks
180
197
  #{program} <task num> erase task
181
198
  #{program} -e [task num] edit task file [and jump to given task]
182
199
  #{program} -e<task num> <text> replace task with given text
200
+ #{program} -r renumber tasks, removing gaps
183
201
  #{program} -h, --help show this message
184
202
  EOS
185
203
 
@@ -30,6 +30,19 @@ module DoStuff
30
30
  @tasks.delete(task_num.to_i)
31
31
  end
32
32
 
33
+ def renumber!
34
+ old_tasks = @tasks
35
+ @tasks = {}
36
+
37
+ i = 1
38
+ old_tasks.sort.each do |_, task|
39
+ @tasks[i] = task
40
+ i += 1
41
+ end
42
+
43
+ @tasks
44
+ end
45
+
33
46
  def write!
34
47
  File.open(@file, 'w') do |f|
35
48
  tasks.sort.each{|num, task| f.puts("#{num}. #{task}") }
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: do_stuff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Scott Olson
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-06-13 00:00:00.000000000 Z
12
+ date: 2012-08-28 00:00:00.000000000 Z
12
13
  dependencies: []
13
14
  description: A minimalistic command-line todo list
14
15
  email: scott@scott-olson.org
@@ -17,36 +18,35 @@ executables:
17
18
  extensions: []
18
19
  extra_rdoc_files: []
19
20
  files:
20
- - lib/do_stuff/runner.rb
21
21
  - lib/do_stuff/standalone.rb
22
+ - lib/do_stuff/runner.rb
22
23
  - lib/do_stuff/tasklist.rb
23
24
  - lib/do_stuff.rb
24
25
  - bin/do_stuff
25
26
  - README.md
26
27
  - LICENSE
27
28
  homepage: https://github.com/tsion/do_stuff
28
- licenses:
29
- - ISC
30
- metadata: {}
29
+ licenses: []
31
30
  post_install_message:
32
31
  rdoc_options: []
33
32
  require_paths:
34
33
  - lib
35
34
  required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
36
  requirements:
37
- - - '>='
37
+ - - ! '>='
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
40
  required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
41
42
  requirements:
42
- - - '>='
43
+ - - ! '>='
43
44
  - !ruby/object:Gem::Version
44
45
  version: '0'
45
46
  requirements: []
46
47
  rubyforge_project:
47
- rubygems_version: 2.0.2
48
+ rubygems_version: 1.8.17
48
49
  signing_key:
49
- specification_version: 4
50
+ specification_version: 3
50
51
  summary: A minimalistic command-line todo list
51
52
  test_files: []
52
- has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 85af10253b4970cc931c5cd870e5e922e2480df0
4
- data.tar.gz: a538411c071a7c98cf0922ae983828a6b1818ce9
5
- SHA512:
6
- metadata.gz: 2336514b9aef27392c46c6cd7910522af37cf46a37a336c40f8064433bfd9b58ee6ea39df42ce1b0443790a638c8c1a6ccedfff83fcaf3c40b64c4cf055ce4cb
7
- data.tar.gz: 068df5a79c1e51e87cbc33f4baa8f237d0831266befc9a0b65a599ac23b9912a858af3165e64f4c8ff57b7858a5b1346bd8d69e826e46502b7f0aa633f3dfbe8