-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
127 lines (116 loc) · 3.69 KB
/
main.go
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
118
119
120
121
122
123
124
125
126
127
package main
import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"github.com/exhq/neowofetch/data"
"github.com/exhq/neowofetch/utils"
)
var isuwuified bool = true
func checkforconfigfolder() {
_, folder := os.Stat(data.GetHome() + "/.config")
if os.IsNotExist(folder) {
os.Mkdir(data.GetHome()+"/.config", os.ModePerm)
}
}
func getShellVersion(shellCommand string) string {
// https://www.youtube.com/watch?v=YPN0qhSyWy8
cmd := shellCommand + " --version | grep -o -E \"([0-9]\\.?)*\" | head -n1"
out, _ := exec.Command("bash", "-c", cmd).Output()
return filepath.Base(shellCommand) + " " + strings.ReplaceAll(string(out), "\n", "")
}
func handleConfig() {
_, folder := os.Stat(filepath.Dir(data.GetConfigFile()))
_, file := os.Stat(data.GetConfigFile())
if os.IsNotExist(folder) {
os.Mkdir(filepath.Dir(data.GetConfigFile()), os.ModePerm)
}
defaultconfig := "println green neOwOfetchh 🔥\ninfo white username\nprint blue @\ninfoln blue hostname\nprint white|space=12 uptime:\ninfoln red uptime\nprint white|space=12 shell:\ninfoln blue shell\nprint white|space=12 distro:\ninfoln blue distro\nprint white|space=12 terminal:\ninfoln blue terminal\nprint white|space=12 WM:\ninfoln blue wm\nprint white|space=12 memory:\ninfo blue memoryUsed\nprint white /\ninfoln blue memoryAll"
if os.IsNotExist(file) {
f, _ := os.Create(data.GetConfigFile())
_, _ = f.WriteString(defaultconfig)
}
body, _ := ioutil.ReadFile(data.GetConfigFile())
sbody := (string(body))
if utils.Defaultconf {
sbody = defaultconfig
}
fbody := strings.Split(sbody, "\n")
for _, line := range fbody {
word := strings.Split(line, " ")
if len(word) < 3 {
continue
}
action := word[0]
color := word[1]
rest := strings.Join(word[2:], " ")
handlePrint(action, color, rest)
}
}
func handlePrint(action, format string, rest string) {
if action == "print" {
utils.CutePrint(rest, format)
} else if action == "println" {
utils.CutePrint(rest, format)
utils.CuteNewLine()
} else if action == "info" || action == "infoln" {
infoGetters := map[string]func() string{
"distro": func() string {
if utils.Asciiforced {
return utils.Forceddistro
}
return data.GetDistro()
},
"username": data.GetUsername,
"uptime": func() string {
no, _ := strconv.Atoi(data.GetUptime())
return data.FormatTime(no)
},
"hostname": func() string { return data.Unamebs("-n") },
"kernelname": func() string { return data.Unamebs("-srm") },
//"CPU": data.GetCPU,
"GPU": data.GetGPU,
"shell": func() string { return getShellVersion(data.GetShell()) },
"terminal": data.GetTerminal,
"memoryAll": func() string { return data.GetMemory(false) },
"memoryUsed": func() string { return data.GetMemory(true) },
"wm": data.GetWM,
"ip": data.GetLocalIP,
}
getter, ok := infoGetters[rest]
if ok {
utils.CutePrint(getter(), format)
} else {
utils.CutePrint("{UNKNOWN KEYWORD: "+rest+"}", format)
}
if action == "infoln" {
utils.CuteNewLine()
}
}
}
func runpage() {
if utils.Ishelp {
println(`neowofetch version x (idk how to implement this)
--nouwu turns off uwuifying
--usepng uses a png (only supports arch and ubuntu rn)
--noascii turns off the ascii
--nocolor no color.
--noconf uses builtin config instead of looking for one in the filesystem
--nocolorconf same thing but for color config :P
--16color uses escape codes instead of RGB
--help YOU LITERALLY FUCKING RAN IT RIGHT NOW`)
os.Exit(0)
}
}
func main() {
utils.Initargs()
runpage()
checkforconfigfolder()
utils.Initcolor()
utils.CutePrintInit()
handleConfig()
utils.CutePrintEnd()
}