diff --git a/barkfetch.config b/barkfetch.config index 2c30c4f..cd2ddf4 100644 --- a/barkfetch.config +++ b/barkfetch.config @@ -2,6 +2,7 @@ logo=auto userline=true userunderline=true +os=true kernel=true uptime=true shell=true diff --git a/cmd/cmd.go b/cmd/cmd.go index 08d9408..7a03a81 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -75,7 +75,7 @@ func Run() error { return err } - // "logo", "userline", "userunderline", "kernel", "uptime", "shell", "memory" + // "logo", "userline", "userunderline", "os", "kernel", "uptime", "shell", "memory" sysinfo, err := info.GetInfoString(config) if err != nil { diff --git a/info/info.go b/info/info.go index 498141c..096863b 100644 --- a/info/info.go +++ b/info/info.go @@ -8,11 +8,11 @@ import ( ) // Possible options, to make output sorted independent of config/cmd -var possibleOptions = []string{"logo", "userline", "userunderline", "kernel", - "uptime", "shell", "memory"} +var possibleOptions = []string{"logo", "userline", "userunderline", "os", + "kernel", "uptime", "shell", "memory"} // Regexp matching empty lines, useful to make output more pretty -var emptyLinesRegex = regexp.MustCompile(`\n$`) +var emptyLinesRegex = regexp.MustCompile(`(?m)\n$`) // Helper function, chains fmt.Sprintf and os.Expand(..., ColorExpand) func formatAndColor(format string, args ...any) string { @@ -85,6 +85,22 @@ func GetInfoString(options map[string]string) (string, error) { ) lines++ + case "os": + os, err := getRawPrettyName() + if err != nil { + return "", err + } + + arch := getRawArchitecture() + + output += formatAndColor( + "\x1b[%vG${caccent}OS${creset}: %v %v\n", + offset, + os, + arch, + ) + lines++ + case "kernel": kernel, err := getRawKernel() if err != nil { @@ -104,12 +120,51 @@ func GetInfoString(options map[string]string) (string, error) { return "", err } - output += formatAndColor( - "\x1b[%vG${caccent}Uptime${creset}: %v minutes\n", - offset, - int(uptime/60), - ) + if uptime <= 60 { + output += formatAndColor( + "\x1b[%vG${caccent}Uptime${creset}: %v s\n", + offset, + int(uptime), + ) + } + + if uptime <= 3600 { + output += formatAndColor( + "\x1b[%vG${caccent}Uptime${creset}: %v m, %v s\n", + offset, + int(uptime/60), + int(uptime%60), + ) + } + + if uptime <= 86400 { + output += formatAndColor( + "\x1b[%vG${caccent}Uptime${creset}: %v h, %v m, %v s\n", + offset, + int(uptime/3600), + int((uptime%3600)/60), + int((uptime%3600)%60), + ) + } + + if uptime > 86400 { + output += formatAndColor( + "\x1b[%vG${caccent}Uptime${creset}: %v d, %v h, %v m, %v s\n", + offset, + int(uptime/86400), + int(uptime%86400), + int((uptime%86400)%3600), + int(((uptime%86400)%3600)%60), + ) + } + lines++ + // output += formatAndColor( + // "\x1b[%vG${caccent}Uptime${creset}: %v minutes\n", + // offset, + // int(uptime/60), + // ) + // lines++ case "shell": shell := getRawShell() @@ -128,10 +183,11 @@ func GetInfoString(options map[string]string) (string, error) { } output += formatAndColor( - "\x1b[%vG${caccent}Memory${creset}: %v / %v Mb\n", + "\x1b[%vG${caccent}Memory${creset}: %v / %v Mb (%v%%)\n", offset, used, total, + int(float32(used)/float32(total)*100.0), ) lines++ } diff --git a/info/logos/arch.txt b/info/logos/arch.txt new file mode 100644 index 0000000..61000dd --- /dev/null +++ b/info/logos/arch.txt @@ -0,0 +1,8 @@ +#accent c14 +${c14} /\ + / \ + /\ \ + / \ + / ,, \ + / | | -\ +/_-'' ''-_\${creset} \ No newline at end of file diff --git a/info/logos/linuxmint.txt b/info/logos/linuxmint.txt new file mode 100644 index 0000000..31b2a59 --- /dev/null +++ b/info/logos/linuxmint.txt @@ -0,0 +1,8 @@ +#accent c10 +${c10} ___________ +|_ \ + | ${creset}| _____ ${c10}| + | ${creset}| | | | ${c10}| + | ${creset}| | | | ${c10}| + | ${creset}\__${creset}___/ ${c10}| + \_________/ \ No newline at end of file diff --git a/info/logos/manjaro.txt b/info/logos/manjaro.txt new file mode 100644 index 0000000..180f7e0 --- /dev/null +++ b/info/logos/manjaro.txt @@ -0,0 +1,8 @@ +#accent c10 +${c10}||||||||| |||| +||||||||| |||| +|||| |||| +|||| |||| |||| +|||| |||| |||| +|||| |||| |||| +|||| |||| |||| \ No newline at end of file diff --git a/info/logos/mxlinux.txt b/info/logos/mxlinux.txt new file mode 100644 index 0000000..9283a85 --- /dev/null +++ b/info/logos/mxlinux.txt @@ -0,0 +1,8 @@ +#accent creset + \\ / + \\/ + \\ + /\/ \\ + / \ /\ + / \/ \ +/__________\ \ No newline at end of file diff --git a/info/logos/netbsd.txt b/info/logos/netbsd.txt new file mode 100644 index 0000000..1171ed5 --- /dev/null +++ b/info/logos/netbsd.txt @@ -0,0 +1,8 @@ +#accent c5 +\\${c5}\`-______,----__ +${creset} \\ ${c5}__,---\`_ +${creset} \\ ${c5}\`.____ +${creset} \\${c5}-______,----\`- +${creset} \\ + \\ + \\ \ No newline at end of file diff --git a/info/logos/nixos.txt b/info/logos/nixos.txt new file mode 100644 index 0000000..0e48c86 --- /dev/null +++ b/info/logos/nixos.txt @@ -0,0 +1,8 @@ +#accent c4 +${c4} \\ \\ // + ==\\__\\/ // + // \\// +==// //== + //\\___// +// /\\ \\== + // \\ \\ \ No newline at end of file diff --git a/info/logos/openbsd.txt b/info/logos/openbsd.txt new file mode 100644 index 0000000..78eaf40 --- /dev/null +++ b/info/logos/openbsd.txt @@ -0,0 +1,8 @@ +#accent c11 +${c11} _____ + \- -/ + \_/ \ + | ${creset}O O${c11} | + |_ < ) 3 ) + / \ / + /-_____-\ \ No newline at end of file diff --git a/info/logos/opensuse.txt b/info/logos/opensuse.txt new file mode 100644 index 0000000..b6b1803 --- /dev/null +++ b/info/logos/opensuse.txt @@ -0,0 +1,8 @@ +#accent c10 +${c10} _______ +__| __ \ + / .\ \ + \__/ | + _______| + \_______ +__________/ \ No newline at end of file diff --git a/info/logos/parabola.txt b/info/logos/parabola.txt new file mode 100644 index 0000000..2d52331 --- /dev/null +++ b/info/logos/parabola.txt @@ -0,0 +1,7 @@ +#accent c5 +${c5} __ __ __ _ +.`_/_/_/ / `. + / .` + / .` + /.` + /` \ No newline at end of file diff --git a/info/logos/popos.txt b/info/logos/popos.txt new file mode 100644 index 0000000..d9c3da7 --- /dev/null +++ b/info/logos/popos.txt @@ -0,0 +1,9 @@ +#accent c14 +${c14}______ +\ _ \ __ + \ \ \ \ / / + \ \_\ \ / / + \ ___\ /_/ + \ \ _ + __\_\__(_)_ + (___________)` \ No newline at end of file diff --git a/info/logos/postmarketos.txt b/info/logos/postmarketos.txt new file mode 100644 index 0000000..dbe3bfe --- /dev/null +++ b/info/logos/postmarketos.txt @@ -0,0 +1,10 @@ +#accent c10 +${c10} /\ + / \ + / \ + \__ \ + /\__ \ _\ + / / \/ __ + / / ____/ \ + / \ \ \ +/_____/ /________\ \ No newline at end of file diff --git a/info/logos/pureos.txt b/info/logos/pureos.txt new file mode 100644 index 0000000..f293a02 --- /dev/null +++ b/info/logos/pureos.txt @@ -0,0 +1,7 @@ +#accent c10 +${c10} _____________ +| _________ | +| | | | +| | | | +| |_________| | +|_____________| \ No newline at end of file diff --git a/info/logos/slackware.txt b/info/logos/slackware.txt new file mode 100644 index 0000000..aa3acc4 --- /dev/null +++ b/info/logos/slackware.txt @@ -0,0 +1,8 @@ +#accent c4 +${c4} ________ + / ______| + | |______ + \______ \ + ______| | +| |________/ +|____________ \ No newline at end of file diff --git a/info/logos/ubuntu.txt b/info/logos/ubuntu.txt new file mode 100644 index 0000000..2d5935f --- /dev/null +++ b/info/logos/ubuntu.txt @@ -0,0 +1,7 @@ +#accent c9 +${c9} _ + ---(_) + _/ --- \ +(_) | | + \ --- _/ + ---(_) \ No newline at end of file diff --git a/info/raw.go b/info/raw.go index c5c7170..01aff5b 100644 --- a/info/raw.go +++ b/info/raw.go @@ -4,6 +4,7 @@ import ( _ "embed" "os" "regexp" + "runtime" "strings" ) @@ -24,6 +25,12 @@ func getRawHostname() (string, error) { return os.Hostname() } +// Gets OS architecture +func getRawArchitecture() string { + return runtime.GOARCH +} + +// Logos var ( //go:embed logos/default.txt _default string @@ -33,6 +40,42 @@ var ( //go:embed logos/gentoo.txt _gentoo string + + //go:embed logos/arch.txt + _arch string + + //go:embed logos/linuxmint.txt + _linuxmint string + + //go:embed logos/manjaro.txt + _manjaro string + + //go:embed logos/mxlinux.txt + _mxlinux string + + //go:embed logos/nixos.txt + _nixos string + + //go:embed logos/opensuse.txt + _opensuse string + + //go:embed logos/parabola.txt + _parabola string + + //go:embed logos/popos.txt + _popos string + + //go:embed logos/postmarketos.txt + _postmarketos string + + //go:embed logos/pureos.txt + _pureos string + + //go:embed logos/slackware.txt + _slackware string + + //go:embed logos/ubuntu.txt + _ubuntu string ) // Returns distro logo by name, or guesses if arg is "auto" @@ -50,6 +93,48 @@ func getLogo(distro string) (Logo, error) { case "gentoo": logoText = _gentoo + case "arch": + logoText = _arch + + case "linuxmint": + logoText = _linuxmint + + case "manjaro": + logoText = _manjaro + + case "mxlinux": + logoText = _mxlinux + + case "nixos": + logoText = _nixos + + case "opensuse": + logoText = _opensuse + + case "suse": + logoText = _opensuse + + case "parabola": + logoText = _parabola + + case "pop-os": + logoText = _popos + + case "popos": + logoText = _popos + + case "postmarketos": + logoText = _postmarketos + + case "pureos": + logoText = _pureos + + case "slackware": + logoText = _slackware + + case "ubuntu": + logoText = _ubuntu + default: logoText = _default } diff --git a/info/raw_linux.go b/info/raw_linux.go index 9b4f871..4fd60d5 100644 --- a/info/raw_linux.go +++ b/info/raw_linux.go @@ -15,7 +15,8 @@ import ( var ( getTotalMemRegex = regexp.MustCompile(`MemTotal:\s+(\d+) kB`) getAvailableMemRegex = regexp.MustCompile(`MemAvailable:\s+(\d+) kB`) - getIdRegex = regexp.MustCompile(`(?m)^ID=\"*(.*)\"*$`) + getIdRegex = regexp.MustCompile(`(?m)^ID=\"*([^\"]+)\"*$`) + getPrettyNameRegex = regexp.MustCompile(`(?m)^PRETTY_NAME=\"*([^\"]+)\"*$`) ) // Convert array of int8 to string @@ -91,6 +92,24 @@ func getRawMemory() (used, total int, err error) { return } +// Returns OS pretty name +func getRawPrettyName() (string, error) { + f, err := os.Open("/etc/os-release") + if err != nil { + return "", err + } + defer f.Close() + + raw, err := io.ReadAll(f) + if err != nil { + return "", err + } + + contents := string(raw) + match := getPrettyNameRegex.FindStringSubmatch(contents) + return match[1], nil +} + // Guesses distro by /etc/os-release values func guessDistro() string { f, err := os.Open("/etc/os-release")