Skip to content

Commit

Permalink
Merge pull request #5 from xbt573/develop
Browse files Browse the repository at this point in the history
Distro detection
  • Loading branch information
xbt573 authored Dec 3, 2022
2 parents 6c11d10 + 49b7066 commit 8b521d6
Show file tree
Hide file tree
Showing 19 changed files with 284 additions and 11 deletions.
1 change: 1 addition & 0 deletions barkfetch.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
logo=auto
userline=true
userunderline=true
os=true
kernel=true
uptime=true
shell=true
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
74 changes: 65 additions & 9 deletions info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
Expand All @@ -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++
}
Expand Down
8 changes: 8 additions & 0 deletions info/logos/arch.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#accent c14
${c14} /\
/ \
/\ \
/ \
/ ,, \
/ | | -\
/_-'' ''-_\${creset}
8 changes: 8 additions & 0 deletions info/logos/linuxmint.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#accent c10
${c10} ___________
|_ \
| ${creset}| _____ ${c10}|
| ${creset}| | | | ${c10}|
| ${creset}| | | | ${c10}|
| ${creset}\__${creset}___/ ${c10}|
\_________/
8 changes: 8 additions & 0 deletions info/logos/manjaro.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#accent c10
${c10}||||||||| ||||
||||||||| ||||
|||| ||||
|||| |||| ||||
|||| |||| ||||
|||| |||| ||||
|||| |||| ||||
8 changes: 8 additions & 0 deletions info/logos/mxlinux.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#accent creset
\\ /
\\/
\\
/\/ \\
/ \ /\
/ \/ \
/__________\
8 changes: 8 additions & 0 deletions info/logos/netbsd.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#accent c5
\\${c5}\`-______,----__
${creset} \\ ${c5}__,---\`_
${creset} \\ ${c5}\`.____
${creset} \\${c5}-______,----\`-
${creset} \\
\\
\\
8 changes: 8 additions & 0 deletions info/logos/nixos.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#accent c4
${c4} \\ \\ //
==\\__\\/ //
// \\//
==// //==
//\\___//
// /\\ \\==
// \\ \\
8 changes: 8 additions & 0 deletions info/logos/openbsd.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#accent c11
${c11} _____
\- -/
\_/ \
| ${creset}O O${c11} |
|_ < ) 3 )
/ \ /
/-_____-\
8 changes: 8 additions & 0 deletions info/logos/opensuse.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#accent c10
${c10} _______
__| __ \
/ .\ \
\__/ |
_______|
\_______
__________/
7 changes: 7 additions & 0 deletions info/logos/parabola.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#accent c5
${c5} __ __ __ _
.`_/_/_/ / `.
/ .`
/ .`
/.`
/`
9 changes: 9 additions & 0 deletions info/logos/popos.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#accent c14
${c14}______
\ _ \ __
\ \ \ \ / /
\ \_\ \ / /
\ ___\ /_/
\ \ _
__\_\__(_)_
(___________)`
10 changes: 10 additions & 0 deletions info/logos/postmarketos.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#accent c10
${c10} /\
/ \
/ \
\__ \
/\__ \ _\
/ / \/ __
/ / ____/ \
/ \ \ \
/_____/ /________\
7 changes: 7 additions & 0 deletions info/logos/pureos.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#accent c10
${c10} _____________
| _________ |
| | | |
| | | |
| |_________| |
|_____________|
8 changes: 8 additions & 0 deletions info/logos/slackware.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#accent c4
${c4} ________
/ ______|
| |______
\______ \
______| |
| |________/
|____________
7 changes: 7 additions & 0 deletions info/logos/ubuntu.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#accent c9
${c9} _
---(_)
_/ --- \
(_) | |
\ --- _/
---(_)
85 changes: 85 additions & 0 deletions info/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
_ "embed"
"os"
"regexp"
"runtime"
"strings"
)

Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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
}
Expand Down
Loading

0 comments on commit 8b521d6

Please sign in to comment.