-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.exs
116 lines (98 loc) · 3.18 KB
/
main.exs
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
defmodule Amogusfetch do
def main do
{args, _, _} =
System.argv()
|> OptionParser.parse(
aliases: [b: :body_color, w: :window_color],
strict: [body_color: :string, window_color: :string]
)
Enum.zip([Amogusfetch.picture(args[:body_color], args[:window_color]), Amogusfetch.values()])
|> Enum.map(fn {x, y} -> x <> String.duplicate(" ", 5) <> y end)
|> IO.puts()
end
defp term, do: System.get_env("TERM") |> String.downcase()
defp os_release do
File.read!("/etc/os-release")
|> String.split(["\n", "="], trim: true)
|> Enum.chunk_every(2)
|> Map.new(fn [k, v] -> {k, v} end)
end
defp uptime do
File.read!("/proc/uptime")
|> String.split(" ")
|> hd
|> String.to_float()
|> round
|> then(&Time.add(~T[00:00:00], &1, :second))
|> then(fn x ->
if(x.hour > 23, do: "#{div(x.hour, 24)}d ", else: "") <>
if(0 < x.hour and x.hour < 24, do: "#{rem(x.hour, 24)}h ", else: "") <>
"#{x.minute}m"
end)
end
defp shell, do: System.get_env("SHELL")
defp version do
File.read!("/proc/sys/kernel/osrelease")
|> String.trim()
end
defp mem do
File.read!("/proc/meminfo")
|> then(&Regex.named_captures(~r/^MemTotal:\s*(?<all>\d+)\X*^MemFree:\s*(?<free>\d+)/m, &1))
|> Map.new(fn {k, v} -> {k, String.to_integer(v) |> div(1024)} end)
end
defp cpu do
File.read!("/proc/cpuinfo")
|> then(&Regex.run(~r/^model name\W*(\N+)/m, &1, capture: :all_but_first))
|> List.to_string()
|> String.downcase()
|> String.replace(["intel(r) core(tm) ", "cpu ", "amd"], "")
end
defp user, do: System.get_env("USER")
defp hostname do
File.read!("/etc/hostname")
|> String.trim()
end
defp colors do
Enum.map(1..7, fn x -> "\x1b[#{40 + x}m \x1b[0m" end)
|> List.to_string()
end
def picture(fir, sec) do
[fir, sec] = Enum.map([fir, sec], &String.to_atom(to_string(&1)))
colors =
Enum.zip(
["gray", "red", "green", "yellow", "blue", "violet", "light_blue", "white"],
30..37
)
|> Enum.map(fn {x, y} -> {String.to_atom(x), y} end)
win = "\x1b[#{colors[sec]}m"
clear = "\x1b[0m"
body = "\x1b[#{colors[fir]}m"
[
" #{body}.mmmmmmmmmmmmmmm.#{clear} ",
" #{win}.+oooooooooooo+.#{clear}#{body} 'm.#{clear} ",
"#{win}oooooooooooooooooo#{clear}#{body} mmmmm.#{clear}",
"#{win}oooooooooooooooooo#{clear}#{body} m::::m#{clear}",
" #{win}'+oooooooooooo+'#{clear}#{body} m::::m#{clear}",
" #{body}m m::::m#{clear}",
" #{body}m +mmmmmmm. mmmmm'#{clear}",
" #{body}m 'm 'm m#{clear} ",
" #{body}.mmmm.#{clear} #{body}.mmmm.#{clear} "
]
end
def values do
clear = "\x1b[0m"
bold = "\x1b[1m"
[
"#{bold}#{user()}@#{hostname()}#{clear}\n",
"os: #{os_release()["ID"]}\n",
"kernel: #{version()}\n",
"mem: #{mem()["all"] - mem()["free"]}/#{mem()["all"]} mib\n",
"cpu: #{cpu()}\n",
"uptime: #{uptime()}\n",
"shell: #{shell()}\n",
"term: #{term()}\n",
"#{colors()}"
]
end
end
Amogusfetch.main()