neowofetch/main.go

129 lines
3.7 KiB
Go
Raw Normal View History

2022-09-07 15:09:50 +02:00
package main
import (
2022-09-09 10:45:27 +02:00
"io/ioutil"
2022-09-07 17:28:27 +02:00
"os"
2022-12-14 23:48:42 +01:00
"os/exec"
2022-09-09 21:41:50 +02:00
"path/filepath"
2022-09-07 17:28:27 +02:00
"strconv"
"strings"
2022-09-09 22:24:04 +02:00
2022-09-22 14:44:27 +02:00
"github.com/exhq/neowofetch/data"
2022-09-22 14:05:20 +02:00
"github.com/exhq/neowofetch/utils"
2022-09-07 15:09:50 +02:00
)
2022-09-08 17:57:10 +02:00
var isuwuified bool = true
2022-10-16 14:02:02 +02:00
func checkforconfigfolder() {
_, folder := os.Stat(data.GetHome() + "/.config")
2022-10-14 21:09:40 +02:00
if os.IsNotExist(folder) {
os.Mkdir(data.GetHome()+"/.config", os.ModePerm)
}
}
2022-12-14 23:48:42 +01:00
2022-12-15 00:01:45 +01:00
func getShellVersion(shellCommand string) string {
2022-12-14 23:48:42 +01:00
// https://www.youtube.com/watch?v=YPN0qhSyWy8
2022-12-15 00:01:45 +01:00
cmd := shellCommand + " --version | grep -o -E \"([0-9]\\.?)*\" | head -n1"
2022-12-14 23:48:42 +01:00
out, _ := exec.Command("bash", "-c", cmd).Output()
2022-12-25 07:07:48 +01:00
return filepath.Base(shellCommand) + " " + strings.ReplaceAll(string(out), "\n", "")
2022-12-14 23:48:42 +01:00
}
2022-10-14 21:09:40 +02:00
2022-09-09 10:45:27 +02:00
func handleConfig() {
2022-09-26 10:23:44 +02:00
_, folder := os.Stat(filepath.Dir(data.GetConfigFile()))
_, file := os.Stat(data.GetConfigFile())
2022-09-09 10:45:27 +02:00
if os.IsNotExist(folder) {
2022-09-26 10:23:44 +02:00
os.Mkdir(filepath.Dir(data.GetConfigFile()), os.ModePerm)
2022-09-09 10:45:27 +02:00
}
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"
2022-09-09 10:45:27 +02:00
if os.IsNotExist(file) {
2022-09-26 10:23:44 +02:00
f, _ := os.Create(data.GetConfigFile())
_, _ = f.WriteString(defaultconfig)
2022-10-16 14:02:02 +02:00
}
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
}
2022-10-16 14:02:02 +02:00
action := word[0]
color := word[1]
rest := strings.Join(word[2:], " ")
handlePrint(action, color, rest)
}
}
2022-09-22 14:05:20 +02:00
func handlePrint(action, format string, rest string) {
if action == "print" {
2022-09-22 14:05:20 +02:00
utils.CutePrint(rest, format)
} else if action == "println" {
2022-09-22 14:05:20 +02:00
utils.CutePrint(rest, format)
utils.CuteNewLine()
} else if action == "info" || action == "infoln" {
switch rest {
case "distro":
if utils.Asciiforced {
utils.CutePrint(utils.Forceddistro, format)
} else {
utils.CutePrint(data.GetDistro(), format)
}
case "username":
2022-09-26 10:23:44 +02:00
utils.CutePrint(data.GetUsername(), format)
case "uptime":
2022-09-26 10:23:44 +02:00
no, _ := strconv.Atoi(data.GetUptime())
utils.CutePrint(data.FormatTime(no), format)
case "hostname":
2022-10-20 08:19:21 +02:00
utils.CutePrint(data.Unamebs("-n"), format)
case "kernelname":
utils.CutePrint(data.Unamebs("-s"), format)
case "GPU":
2022-09-26 10:23:44 +02:00
utils.CutePrint(data.GetGPU(), format)
case "shell":
2022-12-15 00:01:45 +01:00
utils.CutePrint(getShellVersion(data.GetShell()), format)
case "terminal":
2022-09-26 10:23:44 +02:00
utils.CutePrint(data.GetTerminal(), format)
case "memoryAll":
2022-09-26 10:23:44 +02:00
utils.CutePrint(data.GetMemory(false), format)
case "memoryUsed":
2022-09-26 10:23:44 +02:00
utils.CutePrint(data.GetMemory(true), format)
2022-11-14 12:48:59 +01:00
case "wm":
utils.CutePrint(data.GetWM(), format)
2022-11-20 10:40:31 +01:00
case "ip":
utils.CutePrint(data.GetLocalIP(), format)
default:
2022-11-14 12:48:59 +01:00
print("{UNKNOWN KEYWORD: " + rest + "}")
2022-09-09 10:45:27 +02:00
}
2022-09-22 14:05:20 +02:00
if action == "infoln" {
utils.CuteNewLine()
}
}
2022-09-09 22:24:04 +02:00
}
2022-12-25 07:07:48 +01:00
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)
}
}
2022-09-09 10:45:27 +02:00
2022-09-07 15:09:50 +02:00
func main() {
2022-09-22 12:48:20 +02:00
utils.Initargs()
2022-12-25 07:07:48 +01:00
runpage()
checkforconfigfolder()
utils.Initcolor()
2022-09-22 14:44:27 +02:00
utils.CutePrintInit()
2022-09-09 10:45:27 +02:00
handleConfig()
2022-09-22 14:05:20 +02:00
utils.CutePrintEnd()
2022-09-07 15:09:50 +02:00
}