summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2023-12-21 20:06:53 +0000
committerMatthew Lemon <y@yulqen.org>2023-12-21 20:06:53 +0000
commite512c58cbd5373dc17b4cb65671a7aa38afa3240 (patch)
treeeb2ed62008fc828af974005974acaefdfe8372a8
Initial
-rw-r--r--Gemfile2
-rw-r--r--Gemfile.lock13
-rw-r--r--main.rb52
3 files changed, 67 insertions, 0 deletions
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..2dcdba6
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,2 @@
+source "https://rubygems.org"
+gem "clipboard"
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 0000000..63bff7c
--- /dev/null
+++ b/Gemfile.lock
@@ -0,0 +1,13 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ clipboard (1.3.6)
+
+PLATFORMS
+ x86_64-linux
+
+DEPENDENCIES
+ clipboard
+
+BUNDLED WITH
+ 2.4.22
diff --git a/main.rb b/main.rb
new file mode 100644
index 0000000..9ef710f
--- /dev/null
+++ b/main.rb
@@ -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
+