blob: 287e4da43d8c21ec8a95ca12648123d12cb85bba (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#!/bin/env ruby
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 ]
)
QUICKNOTE_PATH = '/home/lemon/Documents/Notes/quicknote.md'
comment = nil
opts.each do |opt, arg|
case opt
when '--help'
puts <<-EOF
quicknote grabs whatever URL you have in the clipboard, 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(QUICKNOTE_PATH, 'a') do |f|
if comment
f << "- #{comment}: [#{title_out}](#{url})" + "\n"
else
f << "- [#{title_out}](#{url})" + "\n"
end
end
|