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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 416522ba4a16b6f0cb8f011d69c11d2da7983293eedbf58e9d2d02ff750de6ef
4
- data.tar.gz: '0059e3dfd1c5ab4d2a872b4432a5992dc95024ed1f93841615cd66ed927255a6'
3
+ metadata.gz: 58b55c6f109c0b826001f54e1e45cafb056fce54b95a84236b8d42deec4695be
4
+ data.tar.gz: 7e4971446131b02ad9a76ea049ee79a5bbf27b34a660bd04972aa9c210df2d0d
5
5
  SHA512:
6
- metadata.gz: 2c6d22ea2c4eda0f8dc2186f42be121706c92e2ec250f52218c664408eec6d04e16a2fb156c65a9927b082520963e4f6c3dab4fb240253cab6ee4fa3c542df60
7
- data.tar.gz: c854c03324af78f14904118b3d93821b5a6b3f1b488efa2a494a90efb48c85b3898cff0cbf4e97e8110515f84b98c773659c6193d05c85a580c324f538f91088
6
+ metadata.gz: cdb2d170667aba13ec3be1a6c2efd3b28af442309fbb4af551888cad7061f36bf08b3cd3cbdf8fdb845f71bd0913105a5e4781c636421b4cc99398b6774764ea
7
+ data.tar.gz: 664f5de4798bb1213025fcf784cc679529bb334a9ccd16859de3e250f0bd465f033142dee204fd2fd3dd6cbdacc67f9f6a72e1d935033ee0a0959939861bf0f0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mpx (0.1.1)
4
+ mpx (0.1.2)
5
5
  ansi (~> 1.5)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  A command multiplexer.
5
5
 
6
6
  The root folder MPX_ROOT is an environment variable
7
- which defaults to `~/.local/mpx`.
7
+ which defaults to `$XDG_DATA_HOME/mpx`, i.e. `~/.local/share/mpx`.
8
8
 
9
9
  The following subfolders are used:
10
10
  - `bin` Where commands are stored.
@@ -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
- DefaultRoot = File.join('.local', 'mpx')
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.root).history
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
- home = ENV['HOME']
126
- if !home
127
- raise "#{MpxRoot} and $HOME are both not set"
128
- end
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
- return File.join(home, DefaultRoot)
148
+ home = ENV['HOME']
149
+ return File.join(home, '.local', 'share') if home
131
150
  end
132
151
  end
133
152
  end
@@ -6,8 +6,6 @@ module Mpx
6
6
  class History
7
7
  def initialize(root)
8
8
  @root = root
9
-
10
- FileUtils.mkdir_p(@root)
11
9
  end
12
10
 
13
11
  def now
@@ -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 = History.new(File.join(root, HistoryFolder))
18
- end
17
+ @history = File.join(root, HistoryFolder)
19
18
 
20
- def load(name)
21
- if name.nil?
22
- return load_all
23
- end
19
+ FileUtils.mkdir_p(@bin)
20
+ FileUtils.mkdir_p(@spaces)
21
+ FileUtils.mkdir_p(@sets)
22
+ FileUtils.mkdir_p(@history)
24
23
 
25
- return [load_command(name)]
26
- rescue
27
- return load_set(name)
24
+ @history_obj = History.new(@history)
28
25
  end
29
26
 
30
- def load_all
27
+ def list
31
28
  return Dir.entries(@bin)
32
29
  .select { |f| File.file?(File.join(@bin, f)) }
33
- .map { |file| load_command(file) }
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
@@ -1,3 +1,3 @@
1
1
  module Mpx
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.2
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-01-31 00:00:00.000000000 Z
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.1
131
+ rubygems_version: 3.0.2
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: A command multiplexer.