diff options
Diffstat (limited to 'main.rb')
-rw-r--r-- | main.rb | 52 |
1 files changed, 52 insertions, 0 deletions
@@ -0,0 +1,52 @@ +require 'nokogiri' +require 'open-uri' +require 'getoptlong' +require 'clipboard' + +# Following https://ruby-doc.org/stdlib-3.0.0/libdoc/getoptlong/rdoc/GetoptLong.html + +opts = GetoptLong.new( + [ '--help', '-h', GetoptLong::NO_ARGUMENT ], + [ '--comment', '-c', GetoptLong::OPTIONAL_ARGUMENT ] +) + +comment = nil + +opts.each do |opt, arg| + case opt + when '--help' + puts <<-EOF + quicknote grabs whatever URL you give it, parses out the title of the web page, and save it somewhere nice. + + That is all. + EOF + when '--comment' + comment = arg + end +end + +# if ARGV.length != 1 +# puts "Missing dir argument (try --help)" +# exit 0 +# end + +# url = ARGV.shift +# puts url + +url = Clipboard.paste +title_out = nil + +URI.open(url) do |f| + doc = Nokogiri::HTML(f) + title = doc.at_css('title').text + title_out = title +end + +open('/tmp/toss.txt', 'a') do |f| + if comment + f << "#{comment}: [#{title_out}](#{url})" + "\n" + else + f << "- [#{title_out}](#{url})" + "\n" + end +end + |