Permalink
Browse files

Feature for editing file in favorite editor

  • Loading branch information...
1 parent 25f3f0c commit 37ac42b2ec3699a3badaebe10132b98ffe0e982e Bèr Kessels committed Feb 5, 2013
Showing with 44 additions and 3 deletions.
  1. +1 −1 conf/todotxt.cfg
  2. +31 −0 features/edit.feature
  3. +7 −0 features/step_definitions/environment_steps.rb
  4. +5 −2 lib/todotxt/cli.rb
View
@@ -10,4 +10,4 @@ done = ""
deferred = ""
# set editor for todotxt, defaults to $EDITOR.
-# todo_txt_editor = "vim"
+# editor = "vim"
View
@@ -0,0 +1,31 @@
+Feature: Edit
+
+ So that I can modify my entire todolist
+ As a user
+ I want to open the todofile in my editor
+
+
+ Background:
+ Given a todofile with the following items exists:
+ | todo |
+ | 2013-01-01 Install todotxt @cli +todotxt |
+ | Read documentation +todotxt |
+ | 2012-12-12 Buy GTD book @amazon +wishlist |
+
+ Scenario: Open the file in the systems editor
+ Given the enviromnent variable "EDITOR" is set to "echo"
+ And a default config exists
+ When I run `todotxt edit`
+ Then it should pass with:
+ """
+ todo.txt
+ """
+
+ Scenario: Open the file in the configured editor
+ Given a default config exists with the editor set to "echo"
+ When I run `todotxt edit`
+ Then it should pass with:
+ """
+ todo.txt
+ """
+
@@ -17,6 +17,10 @@
write_file(".todotxt.cfg", files_directive)
end
+Given /^a default config exists with the editor set to "(.*?)"$/ do |editor|
+ write_file(".todotxt.cfg", "editor=#{editor}\n[files]\ntodo = todo.txt")
+end
+
Given /^a todofile exists$/ do
write_file("todo.txt", "Read documentation for todotxt\nWrite cucumber steps for todotxt")
end
@@ -34,3 +38,6 @@
write_file(filename, "")
end
+Given /^the enviromnent variable "(.*?)" is set to "(.*?)"$/ do |name, value|
+ ENV[name] = value
+end
View
@@ -206,10 +206,10 @@ def del line1, *lines
end
end
map "rm" => :del
-
+
desc "edit", "Open todo.txt file in your default editor"
def edit
- system "#{@editor} #{@txt_path}"
+ system "#{@editor} #{@file.path}"
end
desc "move | mv ITEM#[, ITEM#, ITEM#, ...] file", "Move ITEM# to another file"
@@ -344,6 +344,9 @@ def parse_conf
else
@file = @files[:todo]
end
+
+ # Determine the editor
+ @editor = @config["editor"] || ENV["EDITOR"]
end
def validate

0 comments on commit 37ac42b

Please sign in to comment.