Permalink
Browse files
Use Kernel.exec for editing files
- Loading branch information...
Showing
with
10 additions
and
6 deletions.
-
+1
−1
bin/sheet
-
+7
−3
lib/sheet.rb
-
+1
−1
lib/sheet/write.rb
-
+1
−1
spec/sheet/write_spec.rb
|
@@ -2,4 +2,4 @@ |
|
|
|
|
|
require File.join(File.dirname(__FILE__), '../lib/sheet')
|
|
|
|
|
|
-Sheet.new(ARGV)
|
|
|
+Sheet.new(ARGV).process
|
|
@@ -17,8 +17,12 @@ def write(message) |
|
|
end
|
|
|
|
|
|
# Utility to execute system commands
|
|
|
- def exec(cmd)
|
|
|
- %x!#{cmd}!
|
|
|
+ def exec(cmd, replace_current_process=false)
|
|
|
+ if replace_current_process
|
|
|
+ Kernel.exec cmd
|
|
|
+ else
|
|
|
+ %x!#{cmd}!
|
|
|
+ end
|
|
|
end
|
|
|
|
|
|
# @param [String] name the sheet name
|
|
@@ -64,7 +68,7 @@ def open_command |
|
|
# Creates a new instance of Sheet, usually followed by a call to {#process}
|
|
|
# @param [Array] args command line options
|
|
|
def initialize(*args)
|
|
|
- @args = args
|
|
|
+ @args = args.flatten
|
|
|
end
|
|
|
|
|
|
# Where the dispatching really happens. We check to see what the user
|
|
|
|
@@ -10,7 +10,7 @@ def initialize(name) |
|
|
def write
|
|
|
create_dir_if_doesnt_exist
|
|
|
if editor_is_set?
|
|
|
- Sheet.exec("#{Sheet.editor} #{Sheet.sheet_path(name)}")
|
|
|
+ Sheet.exec("#{Sheet.editor} #{Sheet.sheet_path(name)}", true)
|
|
|
else
|
|
|
Sheet.write "Please set the $EDITOR variable to write files"
|
|
|
end
|
|
|
|
@@ -6,7 +6,7 @@ |
|
|
|
|
|
it 'opens a new file for writing' do
|
|
|
cmd = "#{editor} #{Sheet.sheet_path('tmux')}"
|
|
|
- Sheet.should_receive(:exec).with(cmd)
|
|
|
+ Sheet.should_receive(:exec).with(cmd, true)
|
|
|
|
|
|
Sheet.stub(:editor) { editor }
|
|
|
|
|
|
0 comments on commit
bda8d3d