aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar √Čtienne Deparis 2020-01-26 17:11:04 +0100
committerGravatar √Čtienne Deparis 2020-01-26 17:11:41 +0100
commit7b00ab5bdff32f3b22bd2f6ecbf1a9e29d746e89 (patch)
treed32e61262184c123c83abb50a5300193441c6951
parent9c8cbea553a81097b0fa2becb81280f507285172 (diff)
downloadneruda-7b00ab5bdff32f3b22bd2f6ecbf1a9e29d746e89.zip
neruda-7b00ab5bdff32f3b22bd2f6ecbf1a9e29d746e89.tar.gz
neruda-7b00ab5bdff32f3b22bd2f6ecbf1a9e29d746e89.tar.xz
Open preview in default browser when using the preview command
-rwxr-xr-xbin/pablo13
-rw-r--r--lib/neruda/utils.rb11
2 files changed, 24 insertions, 0 deletions
diff --git a/bin/pablo b/bin/pablo
index aa6a803..3f5bc3e 100755
--- a/bin/pablo
+++ b/bin/pablo
@@ -35,6 +35,19 @@ module PabloCommands
end
def pablo_preview
+ Thread.new do
+ sleep 1
+ port = Neruda::Config.settings['server_port'] || 5000
+ uri = "http://127.0.0.1:#{port}/"
+ current_os = Neruda::Utils.current_os
+ if current_os == 'windows'
+ system 'start', uri
+ elsif current_os == 'apple'
+ system 'open', uri
+ else
+ system 'gio', 'open', uri
+ end
+ end
@rake.invoke_task('site:preview')
end
diff --git a/lib/neruda/utils.rb b/lib/neruda/utils.rb
index 088121f..b68bfd5 100644
--- a/lib/neruda/utils.rb
+++ b/lib/neruda/utils.rb
@@ -142,6 +142,17 @@ module Neruda
return cmd_opt[:alias] if cmd_opt.has_key?(:alias)
command
end
+
+ # Try to discover the current host operating system.
+ #
+ # @return [String] either apple, windows or linux (default)
+ def current_os
+ if ENV['OS'] == 'Windows_NT' || RUBY_PLATFORM =~ /cygwin/
+ return 'windows'
+ end
+ return 'apple' if RUBY_PLATFORM =~ /darwin/
+ 'linux'
+ end
end
end
end