2022-09-07 15:09:50 +02:00
package main
import (
2022-09-07 17:28:27 +02:00
"fmt"
2022-09-09 10:45:27 +02:00
"io/ioutil"
2022-09-22 12:48:20 +02:00
"neowofetch/utils"
2022-09-07 17:28:27 +02:00
"os"
"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-18 16:20:27 +02:00
"github.com/fatih/color"
2022-09-07 15:09:50 +02:00
)
2022-09-08 17:57:10 +02:00
var isuwuified bool = true
2022-09-22 12:48:20 +02:00
var asciiart [ ] string
2022-09-18 16:20:27 +02:00
var aa int
2022-09-09 22:24:04 +02:00
func getHome ( ) string {
return os . Getenv ( "HOME" )
2022-09-18 16:20:27 +02:00
}
func incrementaa ( ) {
aa += 1
2022-09-09 22:24:04 +02:00
}
2022-09-09 17:09:19 +02:00
2022-09-09 22:24:04 +02:00
func getConfigFile ( ) string {
return getHome ( ) + "/.config/neowofetch/conf"
2022-09-09 10:45:27 +02:00
}
2022-09-18 16:20:27 +02:00
func initascii ( ) {
2022-09-22 12:48:20 +02:00
asciiart = utils . Asciioverwrite ( utils . Getascii ( getDistro ( ) ) )
2022-09-18 16:20:27 +02:00
aa = 0
2022-09-22 12:48:20 +02:00
print ( asciiart [ aa ] )
2022-09-18 16:20:27 +02:00
aa = aa + 1
}
2022-09-09 10:45:27 +02:00
func handleConfig ( ) {
2022-09-09 22:24:04 +02:00
_ , folder := os . Stat ( filepath . Dir ( getConfigFile ( ) ) )
_ , file := os . Stat ( getConfigFile ( ) )
2022-09-09 10:45:27 +02:00
if os . IsNotExist ( folder ) {
2022-09-09 22:24:04 +02:00
os . Mkdir ( filepath . Dir ( getConfigFile ( ) ) , os . ModePerm )
2022-09-09 10:45:27 +02:00
}
if os . IsNotExist ( file ) {
2022-09-10 08:31:27 +02:00
println ( "config was not found. a default config file has been generated in '~/.config/neowofetch/conf'" )
2022-09-09 22:24:04 +02:00
f , _ := os . Create ( getConfigFile ( ) )
2022-09-22 09:54:22 +02:00
_ , _ = f . WriteString ( "println green neOwOfetch 🔥\ninfo magenta username\nprint blue @\ninfoln blue hostname\nprint white uptime: \ninfoln red uptime\nprint white shell: \ninfoln blue shell\nprint white distro: \ninfoln blue distro\nprint white terminal: \ninfoln blue terminal\nprint white memory: \ninfo blue memoryUsed\nprint white /\ninfoln blue memoryAll" )
2022-09-09 10:45:27 +02:00
} else {
2022-09-09 22:24:04 +02:00
body , _ := ioutil . ReadFile ( getConfigFile ( ) )
2022-09-18 16:20:27 +02:00
sbody := ( string ( body ) )
fbody := strings . Split ( sbody , "\n" )
for _ , line := range fbody {
word := strings . Split ( line , " " )
if len ( word ) < 3 {
2022-09-09 10:45:27 +02:00
continue
}
2022-09-18 16:20:27 +02:00
action := word [ 0 ]
color := word [ 1 ]
rest := strings . Join ( word [ 2 : ] , " " )
handlePrint ( action , color , rest )
}
}
}
func handlePrint ( action , colour string , rest string ) {
if action == "print" {
Cprint ( colour , rest , true )
} else if action == "println" {
Cprint ( colour , rest , true )
print ( "\n" )
2022-09-22 12:48:20 +02:00
if aa < len ( asciiart ) {
print ( asciiart [ aa ] )
2022-09-18 16:20:27 +02:00
}
2022-09-22 12:48:20 +02:00
if aa == len ( asciiart ) || aa == len ( asciiart ) - 1 {
print ( strings . Repeat ( " " , len ( asciiart [ 1 ] ) ) )
2022-09-18 16:20:27 +02:00
}
2022-09-22 12:48:20 +02:00
if aa > len ( asciiart ) {
print ( strings . Repeat ( " " , len ( asciiart [ 1 ] ) ) )
2022-09-18 16:20:27 +02:00
}
incrementaa ( )
} else if action == "info" || action == "infoln" {
switch rest {
case "distro" :
Cprint ( colour , getDistro ( ) , true )
case "username" :
Cprint ( colour , getUsername ( ) , true )
case "uptime" :
no , _ := strconv . Atoi ( getUptime ( ) )
Cprint ( colour , formatTime ( no ) , false )
case "hostname" :
Cprint ( colour , getHostname ( ) , true )
2022-09-21 13:17:42 +02:00
case "GPU" :
Cprint ( colour , getGPU ( ) , true )
case "shell" :
Cprint ( colour , getShell ( ) , true )
2022-09-22 09:12:47 +02:00
case "terminal" :
Cprint ( colour , getTerminal ( ) , true )
case "memoryAll" :
Cprint ( colour , getMemory ( false ) , true )
case "memoryUsed" :
Cprint ( colour , getMemory ( true ) , true )
default :
print ( "{UNKNOWN KEYWORD}" )
2022-09-09 10:45:27 +02:00
}
}
2022-09-18 16:20:27 +02:00
if action == "infoln" {
print ( "\n" )
2022-09-22 12:48:20 +02:00
if aa < len ( asciiart ) {
print ( asciiart [ aa ] )
2022-09-18 16:20:27 +02:00
} else {
2022-09-22 12:48:20 +02:00
print ( strings . Repeat ( " " , len ( asciiart [ 1 ] ) ) )
2022-09-18 16:20:27 +02:00
}
incrementaa ( )
}
}
func Cprint ( colour string , message string , uwu bool ) {
2022-09-22 12:48:20 +02:00
if uwu && utils . Woulduwuify ( ) {
2022-09-18 16:20:27 +02:00
message = uwuify ( message )
}
yellow := color . New ( color . FgYellow ) . SprintFunc ( )
red := color . New ( color . FgRed ) . SprintFunc ( )
green := color . New ( color . FgGreen ) . SprintFunc ( )
magenta := color . New ( color . FgMagenta ) . SprintFunc ( )
blue := color . New ( color . FgBlue ) . SprintFunc ( )
black := color . New ( color . FgBlack ) . SprintFunc ( )
switch colour {
case "yellow" :
print ( yellow ( message ) )
case "white" :
print ( message )
case "magenta" :
print ( magenta ( message ) )
case "red" :
print ( red ( message ) )
case "blue" :
print ( blue ( message ) )
case "black" :
print ( black ( message ) )
case "green" :
print ( green ( message ) )
}
2022-09-09 22:24:04 +02:00
}
2022-09-09 10:45:27 +02:00
2022-09-18 16:20:27 +02:00
func uwuify ( message string ) string {
var answer string
var sentence [ ] string
var hasspace bool
if strings . Contains ( message , " " ) {
sentence = strings . Split ( message , " " )
hasspace = true
} else {
sentence = strings . Split ( message , " " )
hasspace = false
2022-09-09 22:24:04 +02:00
}
2022-09-11 13:55:08 +02:00
2022-09-18 16:20:27 +02:00
for _ , word := range sentence {
if ! strings . Contains ( strings . ToLower ( word ) , "uwu" ) {
2022-09-21 13:17:42 +02:00
word = strings . Replace ( word , "u" , "UwU" , - 1 )
2022-09-18 16:20:27 +02:00
if strings . Contains ( strings . ToLower ( word ) , "owo" ) {
2022-09-21 13:17:42 +02:00
word = strings . Replace ( word , "o" , "OwO" , - 1 )
2022-09-18 16:20:27 +02:00
}
2022-09-22 09:12:47 +02:00
word = strings . Replace ( word , "r" , "w" , - 1 )
2022-09-18 16:20:27 +02:00
}
if hasspace {
answer += word + " "
} else {
answer += word
}
}
return answer
2022-09-09 10:45:27 +02:00
}
2022-09-08 17:57:10 +02:00
2022-09-07 17:28:27 +02:00
func getHostname ( ) string {
cmd := exec . Command ( "uname" , "-n" )
shell , _ := cmd . Output ( )
return strings . Replace ( string ( shell ) , "\n" , "" , - 1 )
}
func getUsername ( ) string {
cmd := exec . Command ( "whoami" )
shell , _ := cmd . Output ( )
return strings . Replace ( string ( shell ) , "\n" , "" , - 1 )
}
2022-09-07 15:09:50 +02:00
func getLogo ( ) {
2022-09-09 21:41:50 +02:00
2022-09-07 15:09:50 +02:00
}
2022-09-07 17:28:27 +02:00
func getDistro ( ) string {
2022-09-07 15:09:50 +02:00
distro , err := os . Open ( "/etc/os-release" )
if err != nil {
fmt . Println ( "Error:" , err )
os . Exit ( 0 )
}
distro_info := make ( [ ] byte , 1024 )
distro . Read ( distro_info )
distro . Close ( )
distro_list := strings . Split ( string ( distro_info ) , "\n" )
distro_tuples := make ( map [ string ] string )
for _ , v := range distro_list {
if strings . Contains ( v , "=" ) {
kv := strings . Split ( v , "=" )
kv [ 0 ] = strings . TrimSpace ( kv [ 0 ] )
kv [ 1 ] = strings . TrimSpace ( kv [ 1 ] )
distro_tuples [ kv [ 0 ] ] = kv [ 1 ]
}
}
2022-09-07 17:28:27 +02:00
return strings . Trim ( distro_tuples [ "PRETTY_NAME" ] , "\"" )
2022-09-07 15:09:50 +02:00
}
func getKernel ( ) string {
2022-09-07 17:28:27 +02:00
cmd := exec . Command ( "uname" , "-r" )
kernel , err := cmd . Output ( )
if err != nil {
fmt . Println ( err . Error ( ) )
return "fuck you"
}
return string ( kernel )
2022-09-07 15:09:50 +02:00
}
2022-09-08 13:36:04 +02:00
func getUptime ( ) string {
2022-09-09 17:09:19 +02:00
content , _ := os . ReadFile ( "/proc/uptime" )
return ( string ( content [ 0 : strings . Index ( string ( content ) , "." ) ] ) )
2022-09-07 15:09:50 +02:00
}
func getPackages ( ) {
}
func getShell ( ) string {
2022-09-07 17:28:27 +02:00
return os . Getenv ( "SHELL" )
2022-09-07 15:09:50 +02:00
}
func getResolution ( ) {
2022-09-07 17:28:27 +02:00
2022-09-07 15:09:50 +02:00
}
func getWM ( ) {
}
func getTheme ( ) {
}
func getIcons ( ) {
}
2022-09-08 09:34:39 +02:00
func getTerminal ( ) string {
_ , existprgm := os . LookupEnv ( "TERM_PROGRAM" )
2022-09-22 09:12:47 +02:00
if ! existprgm {
return os . Getenv ( "TERM" )
} else {
return os . Getenv ( "TERM_PROGRAM" )
}
2022-09-07 15:09:50 +02:00
}
func getCPU ( ) {
2022-09-22 09:12:47 +02:00
mem , _ := os . Open ( "/proc/cpuinfo" )
2022-09-08 09:34:39 +02:00
mem_info := make ( [ ] byte , 1024 )
mem . Read ( mem_info )
mem . Close ( )
2022-09-22 09:12:47 +02:00
// mem_list := strings.Split(string(mem_info), "\n")
// mem_map := make(map[string]string)
print ( mem_info )
2022-09-07 15:09:50 +02:00
}
2022-09-07 17:28:27 +02:00
func getGPU ( ) string {
cmd := exec . Command ( "lspci" , "-v" )
shell , err := cmd . Output ( )
_ = err
var bruh string
//return strings.Replace(string(shell), "\n", "", -1)
//return string(shell)
for _ , line := range strings . Split ( strings . TrimSuffix ( string ( shell ) , "\n" ) , "\n" ) {
if strings . Contains ( line , "VGA" ) {
bruh += line [ strings . Index ( line , ": " ) + 2 : strings . Index ( line , " (" ) ]
}
}
return bruh
2022-09-07 15:09:50 +02:00
}
2022-09-08 09:34:39 +02:00
func getMemory ( used bool ) string {
2022-09-07 15:09:50 +02:00
2022-09-07 17:28:27 +02:00
//
// The coolest part about this function unlike neofetch is that it also takes account of the basic os operations
// into account thus not giving an illusion that your os is completely having fun
// honestly idk lmao
//
mem , err := os . Open ( "/proc/meminfo" )
if err != nil {
fmt . Println ( err . Error ( ) )
os . Exit ( 0 )
}
mem_info := make ( [ ] byte , 1024 )
mem . Read ( mem_info )
mem . Close ( )
mem_list := strings . Split ( string ( mem_info ) , "\n" )
mem_map := make ( map [ string ] string )
for _ , v := range mem_list {
if strings . Contains ( v , ":" ) {
kv := strings . Split ( v , ":" )
kv [ 0 ] = strings . TrimSpace ( kv [ 0 ] )
kv [ 1 ] = strings . TrimSpace ( kv [ 1 ] )
kv [ 1 ] = strings . Replace ( kv [ 1 ] , "kB" , "" , 3 )
kv [ 1 ] = strings . TrimSpace ( kv [ 1 ] )
mem_map [ kv [ 0 ] ] = kv [ 1 ]
}
}
mem_free , _ := strconv . Atoi ( mem_map [ "MemFree" ] )
mem_total , _ := strconv . Atoi ( mem_map [ "MemTotal" ] )
mem_used := mem_total - mem_free
2022-09-08 09:34:39 +02:00
//memory := fmt.Sprintf("%d/%d", mem_used/1024, mem_total/1024)
if used {
return strconv . Itoa ( mem_used / 1024 )
} else {
return strconv . Itoa ( mem_total / 1024 )
}
2022-09-07 15:09:50 +02:00
}
2022-09-18 16:20:27 +02:00
func handleremainingascii ( ) {
2022-09-22 12:48:20 +02:00
if aa < len ( asciiart ) {
for i := 0 ; i < len ( asciiart ) - aa ; i ++ {
print ( "\n" , asciiart [ aa ] )
2022-09-18 16:20:27 +02:00
incrementaa ( )
}
}
}
2022-09-08 17:57:10 +02:00
func formatTime ( seconds int ) string {
2022-09-08 13:36:04 +02:00
minutes := seconds / 60
secondsre := strconv . Itoa ( seconds % 60 )
hour := strconv . Itoa ( minutes / 60 )
minutesre := strconv . Itoa ( minutes % 60 )
return ( hour + "h " + minutesre + "m " + secondsre + "s" )
}
2022-09-07 17:28:27 +02:00
func getColorPalette ( ) {
}
2022-09-07 15:09:50 +02:00
func main ( ) {
2022-09-22 12:48:20 +02:00
utils . Initargs ( )
2022-09-18 16:20:27 +02:00
initascii ( )
2022-09-09 10:45:27 +02:00
handleConfig ( )
2022-09-18 16:20:27 +02:00
handleremainingascii ( )
print ( "\n" )
2022-09-07 15:09:50 +02:00
}