panda-motd 0.0.2 → 0.0.3
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/bin/panda-motd +1 -1
- data/lib/panda_motd.rb +5 -1
- data/lib/panda_motd/component.rb +0 -0
- data/lib/panda_motd/components/ascii_text_art.rb +10 -4
- data/lib/panda_motd/components/service_status.rb +101 -0
- data/lib/panda_motd/components/uptime.rb +6 -1
- data/lib/panda_motd/config.rb +32 -0
- data/lib/panda_motd/default_config.yaml +23 -0
- data/lib/panda_motd/motd.rb +12 -6
- data/lib/panda_motd/version.rb +1 -1
- metadata +38 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 602cdbb28a1c8eb7b902dd7c1dee4f0caffb0663fcda3d4b505ca9f53b2aebf7
|
4
|
+
data.tar.gz: 638ca548913a3de96d7534bc22f84aa1fef57e4ee45ad18c4b295de7ce8add42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca2a3254437207351125a08175382980cc43905a22b9f84127993e900d9a2e20213b89d79f973fc9505b8ee38423e24b8542e78135f6cb4423f729782d60400f
|
7
|
+
data.tar.gz: fb2e551bc3bcf911fc9d01aad4af7906aaad435ec19e89026232e34e53ef536d6eae592a6a68e9700b69ac3924d7714e4d22a299e6f75746acbdf951880eaa1e
|
data/bin/panda-motd
CHANGED
data/lib/panda_motd.rb
CHANGED
File without changes
|
@@ -1,12 +1,18 @@
|
|
1
1
|
require 'artii'
|
2
|
+
require 'colorize'
|
2
3
|
|
3
4
|
class AsciiTextArt
|
4
|
-
def initialize(
|
5
|
-
@
|
6
|
-
@
|
5
|
+
def initialize(motd)
|
6
|
+
@motd = motd
|
7
|
+
@config = motd.config.component_config('ascii_text_art')
|
8
|
+
end
|
9
|
+
|
10
|
+
def process
|
11
|
+
@text = `hostname`
|
12
|
+
@art = Artii::Base.new font: @config['font']
|
7
13
|
end
|
8
14
|
|
9
15
|
def to_s
|
10
|
-
return
|
16
|
+
return @art.asciify(@text).red
|
11
17
|
end
|
12
18
|
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
|
3
|
+
class ServiceStatus
|
4
|
+
attr_reader :results
|
5
|
+
|
6
|
+
def initialize(motd)
|
7
|
+
@motd = motd
|
8
|
+
@config = motd.config.component_config('service_status')
|
9
|
+
end
|
10
|
+
|
11
|
+
def process
|
12
|
+
@services = @config['services']
|
13
|
+
@results = {}
|
14
|
+
|
15
|
+
parse_services
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
if @results.any?
|
20
|
+
result = "Services:\n"
|
21
|
+
longest_name_size = @results.keys.map { |k| k.to_s.length }.max + 1 # add 1 for the ':' at the end
|
22
|
+
@results.each do |name, status|
|
23
|
+
name_part = if name.to_s.length > longest_name_size
|
24
|
+
name.to_s.slice(1..longest_name_size)
|
25
|
+
else
|
26
|
+
(name.to_s + ':').ljust(longest_name_size, ' ')
|
27
|
+
end
|
28
|
+
result += " #{name_part} #{status}\n"
|
29
|
+
end
|
30
|
+
|
31
|
+
return result
|
32
|
+
else
|
33
|
+
return "Services:\n No matching services found."
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def parse_services
|
40
|
+
case Gem::Platform.local.os
|
41
|
+
when 'darwin'
|
42
|
+
@results = parse_services_macos(@services)
|
43
|
+
when 'linux'
|
44
|
+
@results = parse_services_linux(@services)
|
45
|
+
end
|
46
|
+
|
47
|
+
return self
|
48
|
+
end
|
49
|
+
|
50
|
+
def parse_services_macos(services)
|
51
|
+
results = {}
|
52
|
+
|
53
|
+
# valid statuses are started, stopped, error, and unknown
|
54
|
+
`brew services list`.split("\n").each do |line|
|
55
|
+
parsed_name = line.split[0]
|
56
|
+
parsed_status = line.split[1]
|
57
|
+
|
58
|
+
matching_service = services.find { |service, _name| service == parsed_name }
|
59
|
+
|
60
|
+
if matching_service
|
61
|
+
results[parsed_name.to_sym] = parsed_status.send(macos_service_colors[parsed_status.to_sym])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
return results
|
66
|
+
end
|
67
|
+
|
68
|
+
def parse_services_linux(services)
|
69
|
+
results = {}
|
70
|
+
|
71
|
+
`systemctl | grep '\.service'`.split("\n").each do |line|
|
72
|
+
parsed_name = line.split[0].gsub('.service', '')
|
73
|
+
parsed_status = line.split[3]
|
74
|
+
|
75
|
+
matching_service = services.find { |service, _name| service == parsed_name }
|
76
|
+
|
77
|
+
if matching_service
|
78
|
+
results[parsed_name.to_sym] = parsed_status.send(linux_service_colors[parsed_status.to_sym])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
return results
|
83
|
+
end
|
84
|
+
|
85
|
+
def macos_service_colors
|
86
|
+
return {
|
87
|
+
started: :green,
|
88
|
+
stopped: :white,
|
89
|
+
error: :red,
|
90
|
+
unknown: :yellow
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
def linux_service_colors
|
95
|
+
return {
|
96
|
+
running: :green,
|
97
|
+
exited: :white,
|
98
|
+
failed: :red
|
99
|
+
}
|
100
|
+
end
|
101
|
+
end
|
@@ -3,7 +3,12 @@ require 'sysinfo'
|
|
3
3
|
class Uptime
|
4
4
|
attr_reader :days, :hours, :minutes
|
5
5
|
|
6
|
-
def initialize
|
6
|
+
def initialize(motd)
|
7
|
+
@motd = motd
|
8
|
+
@config = motd.config.component_config('ascii_text_art')
|
9
|
+
end
|
10
|
+
|
11
|
+
def process
|
7
12
|
sysinfo = SysInfo.new
|
8
13
|
uptime = sysinfo.uptime
|
9
14
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class Config
|
5
|
+
def initialize(file_path = nil)
|
6
|
+
@file_path = File.join(Dir.home, '.config', 'panda-motd.yaml') if file_path.nil?
|
7
|
+
create_config(@file_path) unless File.exist?(@file_path)
|
8
|
+
load_config(@file_path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def components_enabled
|
12
|
+
# first iterate through the config hash and grab all names of enabled components
|
13
|
+
enabled_list = @config['components'].map { |component, setting| component if setting['enabled'] }.compact
|
14
|
+
# convert each snake_case name to an upper-camel-case name which represents a class, and get that class constant
|
15
|
+
return enabled_list.map { |e| Object.const_get(e.split('_').map(&:capitalize).join) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def component_config(component_name)
|
19
|
+
return @config['components'][component_name.to_s]
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def create_config(file_path)
|
25
|
+
default_config_path = File.join(File.dirname(__dir__), 'panda_motd', 'default_config.yaml')
|
26
|
+
FileUtils.cp(default_config_path, file_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def load_config(file_path)
|
30
|
+
@config = YAML.safe_load(File.read(file_path))
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
components:
|
2
|
+
ascii_text_art:
|
3
|
+
enabled: true
|
4
|
+
font: slant
|
5
|
+
color: red
|
6
|
+
|
7
|
+
service_status:
|
8
|
+
enabled: true
|
9
|
+
services:
|
10
|
+
chunkwm: chunkwm
|
11
|
+
skhd: skhd
|
12
|
+
elasticsearch@5.6: elasticsearch
|
13
|
+
mysql: MySQL
|
14
|
+
|
15
|
+
uptime:
|
16
|
+
enabled: true
|
17
|
+
|
18
|
+
# disk_info:
|
19
|
+
# enabled: true
|
20
|
+
# disks:
|
21
|
+
# /dev/disk3s1: Macintosh HD
|
22
|
+
# /dev/disk0s4: Windows
|
23
|
+
# /dev/disk2s2: Games
|
data/lib/panda_motd/motd.rb
CHANGED
@@ -1,14 +1,20 @@
|
|
1
|
+
require 'sysinfo'
|
2
|
+
|
1
3
|
class MOTD
|
2
|
-
attr_reader :components
|
4
|
+
attr_reader :config, :components
|
3
5
|
|
4
6
|
def initialize
|
5
|
-
@
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
@config = Config.new
|
8
|
+
|
9
|
+
@components = []
|
10
|
+
@config.components_enabled.each do |component_class|
|
11
|
+
@components << component_class.new(self)
|
12
|
+
end
|
13
|
+
|
14
|
+
@components.each(&:process)
|
9
15
|
end
|
10
16
|
|
11
17
|
def to_s
|
12
|
-
return @components.map(&:to_s).join("\n")
|
18
|
+
return @components.map(&:to_s).join("\n\n")
|
13
19
|
end
|
14
20
|
end
|
data/lib/panda_motd/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: panda-motd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taylor Thurlow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: artii
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: colorize
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
@@ -39,19 +39,33 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.8'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: require_all
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sysinfo
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
61
|
+
version: '0.8'
|
48
62
|
type: :runtime
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0.
|
68
|
+
version: '0.8'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: byebug
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,6 +150,20 @@ dependencies:
|
|
136
150
|
- - "~>"
|
137
151
|
- !ruby/object:Gem::Version
|
138
152
|
version: '1.25'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: simplecov
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0.12'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0.12'
|
139
167
|
description: Enhance your MOTD with useful at-a-glance information.
|
140
168
|
email: taylorthurlow8@gmail.com
|
141
169
|
executables:
|
@@ -145,8 +173,12 @@ extra_rdoc_files: []
|
|
145
173
|
files:
|
146
174
|
- bin/panda-motd
|
147
175
|
- lib/panda_motd.rb
|
176
|
+
- lib/panda_motd/component.rb
|
148
177
|
- lib/panda_motd/components/ascii_text_art.rb
|
178
|
+
- lib/panda_motd/components/service_status.rb
|
149
179
|
- lib/panda_motd/components/uptime.rb
|
180
|
+
- lib/panda_motd/config.rb
|
181
|
+
- lib/panda_motd/default_config.yaml
|
150
182
|
- lib/panda_motd/motd.rb
|
151
183
|
- lib/panda_motd/version.rb
|
152
184
|
homepage: https://github.com/taylorthurlow/panda-motd
|