-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.lua
More file actions
117 lines (101 loc) · 2.8 KB
/
fetch.lua
File metadata and controls
117 lines (101 loc) · 2.8 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env lua
local user = os.getenv("USERNAME") or os.getenv("USER")
local host = os.getenv("HOSTNAME") or os.getenv("COMPUTERNAME")
if not user or not host then
print("failed to obtain machine name, that is, user@host")
os.exit(1)
end
local machine = user .. "@" .. host
local sepline = string.rep("-", #machine)
local is_unix = true
if package.config:sub(1, 1) == "\\" then
is_unix = false
end
local cmd = "ver"
if is_unix then
cmd = "uname -o"
end
local pipe, err = io.popen(cmd)
if not pipe then
print(err)
os.exit(1)
end
local system = pipe:read("*a")
if not system then
print(string.format("failed to read pipe from io.popen(\"%s\")", cmd))
os.exit(1)
end
local date = os.date("%Y/%m/%d ")
local time = os.date("%H:%M:%S")
local coloring = "all"
for _, v in ipairs(arg) do
if v == "--all" then
coloring = "all"
elseif v == "--none" then
coloring = "none"
elseif v == "--normal" then
coloring = "normal"
elseif v == "--bright" then
coloring = "bright"
elseif v == "--no-machine" then
machine = ""
elseif v == "--no-system" then
system = ""
elseif v == "--no-date" then
date = ""
elseif v == "--no-time" then
time = ""
elseif v == "--no-sepline" then
sepline = ""
elseif v == "--help" then
print("--help prints this")
print("--all uses all colors")
print("--none uses no colors")
print("--normal uses normal colors")
print("--bright uses bright colors")
print("--no-machine disables printing user@host")
print("--no-system disables printing the system info")
print("--no-date disables printing the date component")
print("--no-time disables printing the time component")
print("--no-sepline disables the seperating line between machine and system+date")
os.exit(0)
else
print("encountered invalid argument: ", v)
os.exit(1)
end
end
local colors = {}
if coloring == "all" or coloring == "normal" then
table.insert(colors, "31")
table.insert(colors, "32")
table.insert(colors, "33")
table.insert(colors, "34")
table.insert(colors, "35")
table.insert(colors, "36")
elseif coloring == "all" or coloring == "bright" then
table.insert(colors, "91")
table.insert(colors, "92")
table.insert(colors, "93")
table.insert(colors, "94")
table.insert(colors, "95")
table.insert(colors, "96")
end
local text =
"\\ /\\ " .. machine .. "\n" ..
" ) ( ') " .. sepline .. "\n" ..
" ( / ) " .. system:gsub("\r", ""):gsub("\n", "") .. "\n" ..
" \\(__)| " .. date .. time
if coloring ~= "none" then
math.randomseed(os.time())
end
for i = 1, #text do
local char = string.sub(text, i, i)
local color = ""
if coloring ~= "none" then
color = "\27[" .. colors[math.random(#colors)] .. "m"
end
io.write(color .. char)
end
if coloring ~= "none" then
print("\27[0m")
end