-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.rb
More file actions
72 lines (60 loc) · 1.26 KB
/
script.rb
File metadata and controls
72 lines (60 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require "json"
query = ARGV[0]
def all
content = `/usr/local/bin/docker ps -a --format '{{.ID}}|{{.Names}}|{{.Status}}'`
content = content.split "\n"
content.map! do |node|
splited = node.split '|'
if splited[2][0..5] == 'Exited'
splited[2] = 'Exited'
splited[3] = 9
else
splited[3] = 1
end
splited
end
content.sort { |a, b| a[3] <=> b[3] }
end
def find_from_name(query)
a = all
a.select { |node| node[1].include? query }
end
if query == ''
content = all
else
content = find_from_name(query)
end
result = {items: []}
content.each do |node|
command = node[2] == "Exited" ? 'start' : 'stop'
data = {
uid: node[0],
type: "default",
title: node[1],
subtitle: node[2],
arg: "#{node[1]}|#{command}",
autocomplete: node[1],
icon: {
path: command == "start" ? "./icons/stop.png" : "./icons/ok.png"
}
}
result[:items] << data
end
print result.to_json
=begin
{"items": [
{
"uid": "desktop",
"type": "file",
"title": "Desktop",
"subtitle": "~/Desktop",
"arg": "~/Desktop",
"autocomplete": "Desktop",
"icon": {
"type": "fileicon",
"path": "~/Desktop"
}
}
]}
=end
#`/usr/local/bin/docker ps -a --format "{{.ID}}|{{.Names}}"`