Skip to content

Commit

Permalink
Use Kernel.exec for editing files
Browse files Browse the repository at this point in the history
  • Loading branch information
oscardelben committed Apr 8, 2012
1 parent b6595ba commit bda8d3d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bin/sheet 100644 → 100755
Expand Up @@ -2,4 +2,4 @@

require File.join(File.dirname(__FILE__), '../lib/sheet')

Sheet.new(ARGV)
Sheet.new(ARGV).process
10 changes: 7 additions & 3 deletions lib/sheet.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/sheet/write.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/sheet/write_spec.rb
Expand Up @@ -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 }

Expand Down

0 comments on commit bda8d3d

Please sign in to comment.