diff --git a/lib/launchy.rb b/lib/launchy.rb index d7fe262..8e9d73d 100644 --- a/lib/launchy.rb +++ b/lib/launchy.rb @@ -86,15 +86,15 @@ def reset_global_options Launchy.application = nil Launchy.host_os = nil Launchy.dry_run = false - Launchy.path = ENV["PATH"] + Launchy.path = ENV.fetch("PATH", nil) end def extract_global_options(options) leftover = options.dup - Launchy.debug = leftover.delete(:debug) || ENV["LAUNCHY_DEBUG"] - Launchy.application = leftover.delete(:application) || ENV["LAUNCHY_APPLICATION"] - Launchy.host_os = leftover.delete(:host_os) || ENV["LAUNCHY_HOST_OS"] - Launchy.dry_run = leftover.delete(:dry_run) || ENV["LAUNCHY_DRY_RUN"] + Launchy.debug = leftover.delete(:debug) || ENV.fetch("LAUNCHY_DEBUG", nil) + Launchy.application = leftover.delete(:application) || ENV.fetch("LAUNCHY_APPLICATION", nil) + Launchy.host_os = leftover.delete(:host_os) || ENV.fetch("LAUNCHY_HOST_OS", nil) + Launchy.dry_run = leftover.delete(:dry_run) || ENV.fetch("LAUNCHY_DRY_RUN", nil) end def debug=(enabled) @@ -104,7 +104,7 @@ def debug=(enabled) # we may do logging before a call to 'open', hence the need to check # LAUNCHY_DEBUG here def debug? - @debug || to_bool(ENV["LAUNCHY_DEBUG"]) + @debug || to_bool(ENV.fetch("LAUNCHY_DEBUG", nil)) end def application=(app) @@ -112,7 +112,7 @@ def application=(app) end def application - @application || ENV["LAUNCHY_APPLICATION"] + @application || ENV.fetch("LAUNCHY_APPLICATION", nil) end def host_os=(host_os) @@ -120,7 +120,7 @@ def host_os=(host_os) end def host_os - @host_os || ENV["LAUNCHY_HOST_OS"] + @host_os || ENV.fetch("LAUNCHY_HOST_OS", nil) end def dry_run=(dry_run) @@ -128,7 +128,7 @@ def dry_run=(dry_run) end def dry_run? - @dry_run || to_bool(ENV["LAUNCHY_DRY_RUN"]) + @dry_run || to_bool(ENV.fetch("LAUNCHY_DRY_RUN", nil)) end def bug_report_message diff --git a/lib/launchy/detect/nix_desktop_environment.rb b/lib/launchy/detect/nix_desktop_environment.rb index 380bab6..556dc32 100644 --- a/lib/launchy/detect/nix_desktop_environment.rb +++ b/lib/launchy/detect/nix_desktop_environment.rb @@ -36,7 +36,7 @@ def self.browsers # KDE desktop environment class Kde < NixDesktopEnvironment def self.is_current_desktop_environment? - ENV["KDE_FULL_SESSION"] && + ENV.fetch("KDE_FULL_SESSION", nil) && Launchy::Application.find_executable("kde-open") end @@ -48,7 +48,7 @@ def self.browser # Gnome desktop environment class Gnome < NixDesktopEnvironment def self.is_current_desktop_environment? - ENV["GNOME_DESKTOP_SESSION_ID"] && + ENV.fetch("GNOME_DESKTOP_SESSION_ID", nil) && Launchy::Application.find_executable("gnome-open") end diff --git a/spec/detect/host_os_family_spec.rb b/spec/detect/host_os_family_spec.rb index b0c440c..3a156f3 100644 --- a/spec/detect/host_os_family_spec.rb +++ b/spec/detect/host_os_family_spec.rb @@ -12,7 +12,7 @@ Launchy.reset_global_options end - YAML.load_file(File.expand_path("../../tattle-host-os.yaml", __FILE__))["host_os"].keys.sort.each do |os| + YAML.load_file(File.expand_path("../tattle-host-os.yaml", __dir__))["host_os"].keys.sort.each do |os| it "OS family of #{os} is detected" do os_family = Launchy::Detect::HostOsFamily.detect(os) _(os_family).must_be_kind_of Launchy::Detect::HostOsFamily