lib/snibbets.rb in snibbets-2.0.23 vs lib/snibbets.rb in snibbets-2.0.24
- old
+ new
@@ -1,17 +1,18 @@
# frozen_string_literal: true
+require 'cgi'
+require 'erb'
+require 'fileutils'
+require 'json'
+require 'open3'
require 'optparse'
require 'readline'
-require 'json'
-require 'cgi'
require 'shellwords'
-require 'yaml'
-require 'fileutils'
-require 'tty-which'
require 'tty-reader'
-require 'open3'
+require 'tty-which'
+require 'yaml'
require_relative 'snibbets/version'
require_relative 'snibbets/config'
require_relative 'snibbets/which'
require_relative 'snibbets/string'
require_relative 'snibbets/hash'
@@ -109,10 +110,18 @@
# if no results on the first try, try again searching all text
search(try: try + 1) if matches.empty?
end
+ def open_snippet_in_nvultra(filepath)
+ notebook = Snibbets.options[:source].gsub(/ /, '%20')
+ note = ERB::Util.url_encode(File.basename(filepath, '.md'))
+ url = "x-nvultra://open?notebook=#{notebook}¬e=#{note}"
+ puts url
+ `open '#{url}'`
+ end
+
def open_snippet_in_editor(filepath)
editor = Snibbets.options[:editor] || Snibbets::Config.best_editor
os = RbConfig::CONFIG['target_os']
@@ -179,10 +188,11 @@
end
puts "New snippet written to #{filename}."
open_snippet_in_editor(filepath) if Snibbets.arguments[:edit_snippet]
+ open_snippet_in_nvultra(filepath) if Snibbets.arguments[:nvultra]
end
def handle_launchbar(results)
output = []
@@ -249,9 +259,14 @@
input = IO.read(filepath)
end
if Snibbets.arguments[:edit_snippet]
open_snippet_in_editor(filepath)
+ Process.exit 0
+ end
+
+ if Snibbets.arguments[:nvultra]
+ open_snippet_in_nvultra(filepath)
Process.exit 0
end
snippets = input.snippets