launchy 2.5.2 → 3.1.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 +4 -4
- data/HISTORY.md +22 -0
- data/Manifest.txt +4 -21
- data/README.md +0 -36
- data/exe/launchy +5 -0
- data/launchy.gemspec +33 -0
- data/lib/launchy/application.rb +38 -20
- data/lib/launchy/applications/browser.rb +70 -63
- data/lib/launchy/argv.rb +11 -6
- data/lib/launchy/cli.rb +29 -34
- data/lib/launchy/descendant_tracker.rb +14 -12
- data/lib/launchy/detect/host_os.rb +21 -18
- data/lib/launchy/detect/host_os_family.rb +94 -53
- data/lib/launchy/detect/nix_desktop_environment.rb +74 -69
- data/lib/launchy/detect.rb +7 -5
- data/lib/launchy/error.rb +2 -0
- data/lib/launchy/os_family.rb +2 -0
- data/lib/launchy/runner.rb +55 -0
- data/lib/launchy/version.rb +7 -5
- data/lib/launchy.rb +76 -68
- metadata +19 -79
- data/Rakefile +0 -27
- data/bin/launchy +0 -4
- data/lib/launchy/deprecated.rb +0 -52
- data/lib/launchy/detect/ruby_engine.rb +0 -78
- data/lib/launchy/detect/runner.rb +0 -152
- data/spec/application_spec.rb +0 -43
- data/spec/applications/browser_spec.rb +0 -73
- data/spec/cli_spec.rb +0 -75
- data/spec/detect/host_os_family_spec.rb +0 -42
- data/spec/detect/host_os_spec.rb +0 -19
- data/spec/detect/nix_desktop_environment_spec.rb +0 -27
- data/spec/detect/ruby_engine_spec.rb +0 -37
- data/spec/detect/runner_spec.rb +0 -103
- data/spec/launchy_spec.rb +0 -119
- data/spec/mock_application.rb +0 -9
- data/spec/spec_helper.rb +0 -11
- data/spec/tattle-host-os.yaml +0 -427
- data/spec/version_spec.rb +0 -11
- data/tasks/default.rake +0 -242
- data/tasks/this.rb +0 -208
- /data/{LICENSE → LICENSE.txt} +0 -0
|
@@ -1,32 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
class HostOs
|
|
3
|
+
require "rbconfig"
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
module Launchy
|
|
6
|
+
module Detect
|
|
7
|
+
# Internal: Determine the host operating system that Launchy is running on
|
|
8
|
+
#
|
|
9
|
+
class HostOs
|
|
10
|
+
attr_reader :host_os
|
|
11
|
+
alias to_s host_os
|
|
12
|
+
alias to_str host_os
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
def initialize(host_os = nil)
|
|
15
|
+
@host_os = host_os
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
return if @host_os
|
|
18
|
+
|
|
19
|
+
if (@host_os = override_host_os)
|
|
15
20
|
Launchy.log "Using LAUNCHY_HOST_OS override value of '#{Launchy.host_os}'"
|
|
16
21
|
else
|
|
17
22
|
@host_os = default_host_os
|
|
18
23
|
end
|
|
19
24
|
end
|
|
20
|
-
end
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
def default_host_os
|
|
27
|
+
::RbConfig::CONFIG["host_os"].downcase
|
|
28
|
+
end
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
def override_host_os
|
|
31
|
+
Launchy.host_os
|
|
32
|
+
end
|
|
28
33
|
end
|
|
29
|
-
|
|
30
34
|
end
|
|
31
|
-
|
|
32
35
|
end
|
|
@@ -1,71 +1,112 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Launchy
|
|
4
|
+
module Detect
|
|
5
|
+
# Detect the current host os family
|
|
6
|
+
#
|
|
7
|
+
# If the current host familiy cannot be detected then return
|
|
8
|
+
# HostOsFamily::Unknown
|
|
9
|
+
class HostOsFamily
|
|
10
|
+
class NotFoundError < Launchy::Error; end
|
|
11
|
+
extend ::Launchy::DescendantTracker
|
|
12
|
+
|
|
13
|
+
class << self
|
|
14
|
+
def detect(host_os = HostOs.new)
|
|
15
|
+
found = find_child(:matches?, host_os)
|
|
16
|
+
return found.new(host_os) if found
|
|
17
|
+
|
|
18
|
+
raise NotFoundError, "Unknown OS family for host os '#{host_os}'. #{Launchy.bug_report_message}"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def matches?(host_os)
|
|
22
|
+
matching_regex.match(host_os.to_s)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def windows?
|
|
26
|
+
self == Windows
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def darwin?
|
|
30
|
+
self == Darwin
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def nix?
|
|
34
|
+
self == Nix
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def cygwin?
|
|
38
|
+
self == Cygwin
|
|
39
|
+
end
|
|
16
40
|
end
|
|
17
41
|
|
|
18
|
-
|
|
19
|
-
|
|
42
|
+
attr_reader :host_os
|
|
43
|
+
|
|
44
|
+
def initialize(host_os = HostOs.new)
|
|
45
|
+
@host_os = host_os
|
|
20
46
|
end
|
|
21
47
|
|
|
22
|
-
def windows?
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def cygwin?() self == Cygwin; end
|
|
26
|
-
end
|
|
48
|
+
def windows?
|
|
49
|
+
self.class.windows?
|
|
50
|
+
end
|
|
27
51
|
|
|
52
|
+
def darwin?
|
|
53
|
+
self.class.darwin?
|
|
54
|
+
end
|
|
28
55
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
end
|
|
56
|
+
def nix?
|
|
57
|
+
self.class.nix?
|
|
58
|
+
end
|
|
33
59
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def cygwin?() self.class.cygwin?; end
|
|
60
|
+
def cygwin?
|
|
61
|
+
self.class.cygwin?
|
|
62
|
+
end
|
|
38
63
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
64
|
+
#---------------------------
|
|
65
|
+
# All known host os families
|
|
66
|
+
#---------------------------
|
|
67
|
+
#
|
|
68
|
+
class Windows < HostOsFamily
|
|
69
|
+
def self.matching_regex
|
|
70
|
+
/(mingw|mswin|msys|windows)/i
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def app_list(app)
|
|
74
|
+
app.windows_app_list
|
|
75
|
+
end
|
|
46
76
|
end
|
|
47
|
-
def app_list( app ) app.windows_app_list; end
|
|
48
|
-
end
|
|
49
77
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
78
|
+
# Mac OS X family
|
|
79
|
+
class Darwin < HostOsFamily
|
|
80
|
+
def self.matching_regex
|
|
81
|
+
/(darwin|mac os)/i
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def app_list(app)
|
|
85
|
+
app.darwin_app_list
|
|
86
|
+
end
|
|
53
87
|
end
|
|
54
|
-
def app_list( app ) app.darwin_app_list; end
|
|
55
|
-
end
|
|
56
88
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
89
|
+
# All the *nix family of operating systems, and BSDs
|
|
90
|
+
class Nix < HostOsFamily
|
|
91
|
+
def self.matching_regex
|
|
92
|
+
/(linux|bsd|aix|solaris|sunos|dragonfly)/i
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def app_list(app)
|
|
96
|
+
app.nix_app_list
|
|
97
|
+
end
|
|
60
98
|
end
|
|
61
|
-
def app_list( app ) app.nix_app_list; end
|
|
62
|
-
end
|
|
63
99
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
100
|
+
# Cygwin - if anyone is still using that
|
|
101
|
+
class Cygwin < HostOsFamily
|
|
102
|
+
def self.matching_regex
|
|
103
|
+
/cygwin/i
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def app_list(app)
|
|
107
|
+
app.cygwin_app_list
|
|
108
|
+
end
|
|
67
109
|
end
|
|
68
|
-
def app_list( app ) app.cygwin_app_list; end
|
|
69
110
|
end
|
|
70
111
|
end
|
|
71
112
|
end
|
|
@@ -1,93 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
#
|
|
3
|
-
# Detect the current desktop environment for *nix machines
|
|
4
|
-
# Currently this is Linux centric. The detection is based upon the detection
|
|
5
|
-
# used by xdg-open from http://portland.freedesktop.org/
|
|
6
|
-
class NixDesktopEnvironment
|
|
7
|
-
class NotFoundError < Launchy::Error; end
|
|
1
|
+
# frozen_string_literal: true
|
|
8
2
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
# Detect the current *nix desktop environment
|
|
3
|
+
module Launchy
|
|
4
|
+
module Detect
|
|
12
5
|
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
# Detect the current desktop environment for *nix machines
|
|
7
|
+
# Currently this is Linux centric. The detection is based upon the detection
|
|
8
|
+
# used by xdg-open from http://portland.freedesktop.org/
|
|
9
|
+
class NixDesktopEnvironment
|
|
10
|
+
class NotFoundError < Launchy::Error; end
|
|
11
|
+
|
|
12
|
+
extend ::Launchy::DescendantTracker
|
|
13
|
+
|
|
14
|
+
# Detect the current *nix desktop environment
|
|
15
|
+
#
|
|
16
|
+
# If the current dekstop environment be detected, the return
|
|
17
|
+
# NixDekstopEnvironment::Unknown
|
|
18
|
+
def self.detect
|
|
19
|
+
found = find_child(:is_current_desktop_environment?)
|
|
20
|
+
Launchy.log("Current Desktop environment not found. #{Launchy.bug_report_message}") unless found
|
|
21
|
+
found
|
|
22
|
+
end
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
def self.fallback_browsers
|
|
25
|
+
%w[firefox iceweasel seamonkey opera mozilla netscape galeon links lynx].map { |x| ::Launchy::Argv.new(x) }
|
|
26
|
+
end
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
def self.browsers
|
|
29
|
+
[browser, fallback_browsers].flatten
|
|
30
|
+
end
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
#---------------------------------------
|
|
33
|
+
# The list of known desktop environments
|
|
34
|
+
#---------------------------------------
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
# KDE desktop environment
|
|
37
|
+
class Kde < NixDesktopEnvironment
|
|
38
|
+
def self.is_current_desktop_environment?
|
|
39
|
+
ENV.fetch("KDE_FULL_SESSION", nil) &&
|
|
40
|
+
Launchy::Application.find_executable("kde-open")
|
|
41
|
+
end
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
def self.browser
|
|
44
|
+
::Launchy::Argv.new("kde-open")
|
|
45
|
+
end
|
|
41
46
|
end
|
|
42
|
-
end
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
# Gnome desktop environment
|
|
49
|
+
class Gnome < NixDesktopEnvironment
|
|
50
|
+
def self.is_current_desktop_environment?
|
|
51
|
+
ENV.fetch("GNOME_DESKTOP_SESSION_ID", nil) &&
|
|
52
|
+
Launchy::Application.find_executable("gnome-open")
|
|
53
|
+
end
|
|
49
54
|
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
def self.browser
|
|
56
|
+
::Launchy::Argv.new("gnome-open")
|
|
57
|
+
end
|
|
52
58
|
end
|
|
53
|
-
end
|
|
54
59
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
# Xfce desktop environment
|
|
61
|
+
class Xfce < NixDesktopEnvironment
|
|
62
|
+
def self.is_current_desktop_environment?
|
|
63
|
+
if Launchy::Application.find_executable("xprop")
|
|
64
|
+
`xprop -root _DT_SAVE_MODE`.include?("xfce")
|
|
65
|
+
else
|
|
66
|
+
false
|
|
67
|
+
end
|
|
61
68
|
end
|
|
62
|
-
end
|
|
63
69
|
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
def self.browser
|
|
71
|
+
::Launchy::Argv.new(%w[exo-open --launch WebBrowser])
|
|
72
|
+
end
|
|
66
73
|
end
|
|
67
|
-
end
|
|
68
74
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
# Fall back environment as the last case
|
|
76
|
+
class Xdg < NixDesktopEnvironment
|
|
77
|
+
def self.is_current_desktop_environment?
|
|
78
|
+
Launchy::Application.find_executable(browser)
|
|
79
|
+
end
|
|
74
80
|
|
|
75
|
-
|
|
76
|
-
|
|
81
|
+
def self.browser
|
|
82
|
+
::Launchy::Argv.new("xdg-open")
|
|
83
|
+
end
|
|
77
84
|
end
|
|
78
|
-
end
|
|
79
85
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
# The one that is found when all else fails. And this must be declared last
|
|
87
|
+
class NotFound < NixDesktopEnvironment
|
|
88
|
+
def self.is_current_desktop_environment?
|
|
89
|
+
true
|
|
90
|
+
end
|
|
85
91
|
|
|
86
|
-
|
|
87
|
-
|
|
92
|
+
def self.browser
|
|
93
|
+
::Launchy::Argv.new
|
|
94
|
+
end
|
|
88
95
|
end
|
|
89
96
|
end
|
|
90
|
-
|
|
91
97
|
end
|
|
92
98
|
end
|
|
93
|
-
|
data/lib/launchy/detect.rb
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Launchy
|
|
4
|
+
# Internal: Namespace for detecting the environment that Launchy is running in
|
|
5
|
+
#
|
|
2
6
|
module Detect
|
|
3
7
|
end
|
|
4
8
|
end
|
|
5
9
|
|
|
6
|
-
require
|
|
7
|
-
require
|
|
8
|
-
require
|
|
9
|
-
require 'launchy/detect/nix_desktop_environment'
|
|
10
|
-
require 'launchy/detect/runner'
|
|
10
|
+
require "launchy/detect/host_os"
|
|
11
|
+
require "launchy/detect/host_os_family"
|
|
12
|
+
require "launchy/detect/nix_desktop_environment"
|
data/lib/launchy/error.rb
CHANGED
data/lib/launchy/os_family.rb
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "childprocess"
|
|
4
|
+
module Launchy
|
|
5
|
+
# Internal: Run a command in a child process
|
|
6
|
+
#
|
|
7
|
+
class Runner
|
|
8
|
+
def run(cmd, *args)
|
|
9
|
+
unless cmd
|
|
10
|
+
raise Launchy::CommandNotFoundError,
|
|
11
|
+
"No command found to run with args '#{args.join(' ')}'. If this is unexpected, #{Launchy.bug_report_message}"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
if Launchy.dry_run?
|
|
15
|
+
$stdout.puts dry_run(cmd, *args)
|
|
16
|
+
else
|
|
17
|
+
wet_run(cmd, *args)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def wet_run(cmd, *args)
|
|
22
|
+
argv = shell_commands(cmd, args)
|
|
23
|
+
Launchy.log "ChildProcess: argv => #{argv.inspect}"
|
|
24
|
+
|
|
25
|
+
process = ChildProcess.build(*argv)
|
|
26
|
+
|
|
27
|
+
process.io.inherit!
|
|
28
|
+
process.leader = true
|
|
29
|
+
process.detach = true
|
|
30
|
+
process.start
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def dry_run(cmd, *args)
|
|
34
|
+
shell_commands(cmd, args).join(" ")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# cut it down to just the shell commands that will be passed to exec or
|
|
38
|
+
# posix_spawn. The cmd argument is split according to shell rules and the
|
|
39
|
+
# args are not escaped because the whole set is passed to system as *args
|
|
40
|
+
# and in that case system shell escaping rules are not done.
|
|
41
|
+
#
|
|
42
|
+
def shell_commands(cmd, args)
|
|
43
|
+
cmdline = [cmd.to_s.shellsplit]
|
|
44
|
+
cmdline << args.flatten.collect(&:to_s)
|
|
45
|
+
commandline_normalize(cmdline)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def commandline_normalize(cmdline)
|
|
49
|
+
c = cmdline.flatten!
|
|
50
|
+
c = c.find_all { |a| !a.nil? and a.size.positive? }
|
|
51
|
+
Launchy.log "commandline_normalized => #{c.join(' ')}"
|
|
52
|
+
c
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
data/lib/launchy/version.rb
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Launchy
|
|
2
|
-
VERSION = "
|
|
4
|
+
VERSION = "3.1.1"
|
|
3
5
|
|
|
6
|
+
# Internal: Version number of Launchy
|
|
4
7
|
module Version
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
PATCH = Integer(VERSION.split('.')[2])
|
|
8
|
+
MAJOR = Integer(VERSION.split(".")[0])
|
|
9
|
+
MINOR = Integer(VERSION.split(".")[1])
|
|
10
|
+
PATCH = Integer(VERSION.split(".")[2])
|
|
9
11
|
|
|
10
12
|
def self.to_a
|
|
11
13
|
[MAJOR, MINOR, PATCH]
|