Skip to content

Instantly share code, notes, and snippets.

@abhibeckert
Last active August 29, 2015 14:08
Show Gist options
  • Save abhibeckert/6503790a8735979751ff to your computer and use it in GitHub Desktop.
Save abhibeckert/6503790a8735979751ff to your computer and use it in GitHub Desktop.
open/create file in ruby
#!/usr/bin/ruby
require 'io/console'
for arg in ARGV
# expand the full path
file_path = File.expand_path(arg)
# if file doesn't exist, create it
if !File.exists?(file_path)
print "File doesn't exist: #{file_path}\n Create it now? [y/N] "
unless (STDIN.getch.downcase == 'y')
puts "n\n"
exit
end
puts "y\n"
File.open(file_path, 'a') {}
puts "Created #{file_path}\n";
end
# open it in dux
system "open -a /Applications/Dux.app '#{file_path}'"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment