Last active
August 29, 2015 14:08
-
-
Save abhibeckert/6503790a8735979751ff to your computer and use it in GitHub Desktop.
open/create file in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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