md-reader 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d129588e696a1118fab3bad3aff52be9242166e569b964761dd5c41977c9681
4
- data.tar.gz: 709f61a422b410476670404bb19bf0de5156a22ea96a69e2e8af48548eda22b0
3
+ metadata.gz: f19af5e102c9eea366a9df28b932e1c0bebfdda9313cfb303d3b899590a60121
4
+ data.tar.gz: 22d688f9092748da05a64a201d0a2a130743abf963725ce3aa41bef26ac442b5
5
5
  SHA512:
6
- metadata.gz: 415e241c867f7b6ca05e8095334d8a44bf0215c98b0aa59d8c003a13fd3da464230b8aa5bacf177ac01bb0e275d089da614976acf19caa698919f665f06f704f
7
- data.tar.gz: 80dd5f0f191deb6cdacb82cfa1f24f3a933ea1a0eae4a1125109d135071f063366c737c8f4e74940a97b420d302c9e178f4f5c77d411a2a4989277a096eaf0cf
6
+ metadata.gz: 287b6f2b39fdf728c36dac8df8fb8d10580df8c8b7216dab5f1380297155216e65ec69fbf603e87937b2fd29286dcd3b5aaf40c9ddbc35034d63c878277e9d4d
7
+ data.tar.gz: 519b7e84b7c1f88e8a897980056c14679aa4fa2ba60905df8d303f4ae3d7169a1318a87cf393df3ae7afc9cec0a13364e2b2912e016664b217a72512f486198d
data/bin/md-reader CHANGED
@@ -6,6 +6,27 @@ $LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
6
6
  require "md_reader"
7
7
  require "launchy"
8
8
  require "tmpdir"
9
+ require "shellwords"
10
+
11
+ # Dentro do WSL o launchy não acha browser (procura xdg-open/navegador de
12
+ # desktop Linux). Detectamos o WSL e abrimos no Windows, traduzindo o caminho
13
+ # Linux para o formato UNC (\\wsl.localhost\...) e montando uma URL file://.
14
+ def wsl?
15
+ return ENV.key?("WSL_DISTRO_NAME") if ENV.key?("WSL_DISTRO_NAME")
16
+
17
+ File.exist?("/proc/version") &&
18
+ File.read("/proc/version").downcase.include?("microsoft")
19
+ end
20
+
21
+ def open_file(path)
22
+ if wsl?
23
+ win_path = `wslpath -w #{Shellwords.escape(path)}`.strip # \\wsl.localhost\...\x.html
24
+ url = "file:#{win_path.tr('\\', '/')}" # file://wsl.localhost/...
25
+ system("explorer.exe", url) # explorer costuma retornar status != 0 mesmo em sucesso
26
+ else
27
+ Launchy.open("file://#{path}")
28
+ end
29
+ end
9
30
 
10
31
  if ARGV.empty?
11
32
  warn "Usage: md-reader <arquivo.md>"
@@ -35,6 +56,6 @@ File.write(tmp_path, html, encoding: "utf-8")
35
56
  at_exit { File.delete(tmp_path) rescue nil }
36
57
 
37
58
  puts "Abrindo #{title} no browser..."
38
- Launchy.open("file://#{tmp_path}")
59
+ open_file(tmp_path)
39
60
 
40
61
  sleep 3
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MdReader
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: md-reader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Italo Matos