mpx 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/mpx/cli.rb +31 -12
- data/lib/mpx/history.rb +0 -2
- data/lib/mpx/loader.rb +20 -15
- data/lib/mpx/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58b55c6f109c0b826001f54e1e45cafb056fce54b95a84236b8d42deec4695be
|
4
|
+
data.tar.gz: 7e4971446131b02ad9a76ea049ee79a5bbf27b34a660bd04972aa9c210df2d0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdb2d170667aba13ec3be1a6c2efd3b28af442309fbb4af551888cad7061f36bf08b3cd3cbdf8fdb845f71bd0913105a5e4781c636421b4cc99398b6774764ea
|
7
|
+
data.tar.gz: 664f5de4798bb1213025fcf784cc679529bb334a9ccd16859de3e250f0bd465f033142dee204fd2fd3dd6cbdacc67f9f6a72e1d935033ee0a0959939861bf0f0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/lib/mpx/cli.rb
CHANGED
@@ -8,7 +8,7 @@ module Mpx
|
|
8
8
|
A command multiplexer.
|
9
9
|
|
10
10
|
The root folder MPX_ROOT is an environment variable
|
11
|
-
which defaults to `~/.local/mpx`.
|
11
|
+
which defaults to `$XDG_DATA_HOME/mpx`, i.e. `~/.local/share/mpx`.
|
12
12
|
|
13
13
|
The following subfolders are used:
|
14
14
|
- `bin` Where commands are stored.
|
@@ -30,6 +30,10 @@ The first argument is a mandatory operation, and should be one of:
|
|
30
30
|
|
31
31
|
Prints the version.
|
32
32
|
|
33
|
+
`list`
|
34
|
+
|
35
|
+
Prints the available commands to run.
|
36
|
+
|
33
37
|
`history`
|
34
38
|
|
35
39
|
Taking each subsequent argument as a command or set, the history of each
|
@@ -58,7 +62,7 @@ EOF
|
|
58
62
|
class Cli
|
59
63
|
Usage = "Usage: #{File.basename($0)} [operation] [args...]"
|
60
64
|
MpxRoot = 'MPX_ROOT'
|
61
|
-
|
65
|
+
RootFolder = 'mpx'
|
62
66
|
|
63
67
|
def self.start
|
64
68
|
op, *args = ARGV
|
@@ -67,6 +71,8 @@ EOF
|
|
67
71
|
self.help
|
68
72
|
when 'version'
|
69
73
|
self.version
|
74
|
+
when 'list'
|
75
|
+
self.list
|
70
76
|
when 'history'
|
71
77
|
self.history(args)
|
72
78
|
when nil
|
@@ -91,14 +97,18 @@ EOF
|
|
91
97
|
puts Mpx::VERSION
|
92
98
|
end
|
93
99
|
|
100
|
+
def self.list
|
101
|
+
puts Loader.new(self.get_root).list
|
102
|
+
end
|
103
|
+
|
94
104
|
def self.history(args)
|
95
|
-
history = Loader.new(self.
|
105
|
+
history = Loader.new(self.get_root).history
|
96
106
|
puts history.get(*args)
|
97
107
|
end
|
98
108
|
|
99
109
|
def self.run(args)
|
110
|
+
loader = Loader.new(self.get_root)
|
100
111
|
request = Request.new(args)
|
101
|
-
loader = Loader.new(self.root)
|
102
112
|
commands = loader.load(request.name).sort
|
103
113
|
history = loader.history
|
104
114
|
|
@@ -116,18 +126,27 @@ EOF
|
|
116
126
|
end
|
117
127
|
end
|
118
128
|
|
129
|
+
def self.get_root
|
130
|
+
root = self.root
|
131
|
+
raise 'Unable to determine root folder' unless root
|
132
|
+
raise 'Root folder does not exist' unless File.directory?(root)
|
133
|
+
return root
|
134
|
+
end
|
135
|
+
|
119
136
|
def self.root
|
120
137
|
root = ENV[MpxRoot]
|
121
|
-
if root
|
122
|
-
return root
|
123
|
-
end
|
138
|
+
return root if root
|
124
139
|
|
125
|
-
|
126
|
-
if
|
127
|
-
|
128
|
-
|
140
|
+
data_home = self.data_home
|
141
|
+
return File.join(data_home, RootFolder) if data_home
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.data_home
|
145
|
+
data_home = ENV['XDG_DATA_HOME']
|
146
|
+
return data_home if data_home
|
129
147
|
|
130
|
-
|
148
|
+
home = ENV['HOME']
|
149
|
+
return File.join(home, '.local', 'share') if home
|
131
150
|
end
|
132
151
|
end
|
133
152
|
end
|
data/lib/mpx/history.rb
CHANGED
data/lib/mpx/loader.rb
CHANGED
@@ -14,23 +14,32 @@ module Mpx
|
|
14
14
|
@bin = File.join(root, BinFolder)
|
15
15
|
@spaces = File.join(root, SpacesFolder)
|
16
16
|
@sets = File.join(root, SetsFolder)
|
17
|
-
@history =
|
18
|
-
end
|
17
|
+
@history = File.join(root, HistoryFolder)
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
FileUtils.mkdir_p(@bin)
|
20
|
+
FileUtils.mkdir_p(@spaces)
|
21
|
+
FileUtils.mkdir_p(@sets)
|
22
|
+
FileUtils.mkdir_p(@history)
|
24
23
|
|
25
|
-
|
26
|
-
rescue
|
27
|
-
return load_set(name)
|
24
|
+
@history_obj = History.new(@history)
|
28
25
|
end
|
29
26
|
|
30
|
-
def
|
27
|
+
def list
|
31
28
|
return Dir.entries(@bin)
|
32
29
|
.select { |f| File.file?(File.join(@bin, f)) }
|
33
|
-
|
30
|
+
end
|
31
|
+
|
32
|
+
def history
|
33
|
+
@history_obj
|
34
|
+
end
|
35
|
+
|
36
|
+
def load(name)
|
37
|
+
return load_all if name.nil?
|
38
|
+
return [load_command(name)] rescue load_set(name)
|
39
|
+
end
|
40
|
+
|
41
|
+
def load_all
|
42
|
+
return list.map { |file| load_command(file) }
|
34
43
|
end
|
35
44
|
|
36
45
|
def load_command(command)
|
@@ -55,9 +64,5 @@ module Mpx
|
|
55
64
|
.uniq
|
56
65
|
.map { |line| load_command(line.strip) }
|
57
66
|
end
|
58
|
-
|
59
|
-
def history
|
60
|
-
@history
|
61
|
-
end
|
62
67
|
end
|
63
68
|
end
|
data/lib/mpx/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mpx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan Chan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ansi
|
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
- !ruby/object:Gem::Version
|
129
129
|
version: '0'
|
130
130
|
requirements: []
|
131
|
-
rubygems_version: 3.0.
|
131
|
+
rubygems_version: 3.0.2
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: A command multiplexer.
|