25 Commits
Author SHA1 Message Date
EnumDev 0ed976a06e Fixed bug where the getDistroAsciiArt function would ignore the systemConfigDir variable 2025-02-06 21:18:55 +02:00
EnumDev ce9813a2af Made fatal errors clearer and fixed bug in fetch script 2025-02-06 21:18:55 +02:00
EnumDev 0d3d3fafb2 Added motherboard information 2025-02-06 21:18:55 +02:00
EnumDev a99defd401 Makefile will now always use bash 2025-02-06 21:18:55 +02:00
EnumDev f34537eb5a Updated README.md 2025-01-24 18:10:17 +00:00
EnumDev 120a1cf8e4 Fix for Xfce 2024-11-04 13:37:57 +02:00
EnumDev 76974ee789 Added i3, swayfx and hyprland WM detection 2024-10-23 17:14:23 +03:00
EnumDev 20cf7fe869 Fixed error when attempting to use stormfetch without being connected to the internet and simplified fetch script 2024-09-06 19:07:45 +03:00
EnumDev c5e02c07b5 Added wayland monitor resolution support 2024-08-23 15:13:09 +03:00
EnumDev e8a95e5313 Added Local IPv4 address support 2024-08-23 14:32:26 +03:00
EnumDev 0fd198d83e Added init system support 2024-08-22 21:54:14 +03:00
EnumDev 673f231c42 Added nushell support 2024-08-22 21:25:46 +03:00
CapCreeperGR e311649a48 Added PopOS ascii 2024-07-18 15:35:14 +03:00
CapCreeperGR 712fd78e21 Updated tide ascii 2024-07-18 14:12:45 +03:00
CapCreeperGR 7d83b0996d Improved GPU and added --time-taken flag 2024-07-17 20:11:30 +03:00
CapCreeperGR f3a016b674 Added Libc information 2024-07-17 13:18:31 +03:00
CapCreeperGR 0e2631d5b0 Added Artix ascii 2024-07-16 20:55:06 +03:00
EnumDev 153758b68e make should now be able to locate the go executable more easily 2024-07-01 13:16:37 +03:00
EnumDev ed45b739a5 Updated BPM package count fetching 2024-07-01 12:44:22 +03:00
EnumDev 8c380dbec4 Stormfetch can now read config files in the directory specified with the Makefile SYSCONFDIR variable 2024-06-20 21:23:50 +03:00
EnumDev 7c493dc9f9 Added filesystem label detection, btrfs subvolumes should now be grouped under one partition and the filesystem type will now be shown if enabled in config.yaml 2024-06-19 18:20:16 +03:00
EnumDev b8d7017299 Fixed bug where xbps packages would be counted on arch systems and not void systems 2024-06-18 07:49:19 +03:00
EnumDev cd08003752 Fixed emerge package count and added VoidLinux/xbps support 2024-06-17 19:41:20 +03:00
EnumDev c4c71fc49a Added hidden_gpus option in the config 2024-06-09 14:45:17 +03:00
EnumDev efdbe94193 Stormfetch will now list all GPUs if multiple of them are connected 2024-06-09 14:39:24 +03:00
14 changed files with 328 additions and 93 deletions
+7 -3
View File
@@ -1,3 +1,5 @@
SHELL := /bin/bash
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif
@@ -8,12 +10,12 @@ ifeq ($(SYSCONFDIR),)
SYSCONFDIR := $(PREFIX)/etc
endif
ifeq ($(GO),)
GO := /usr/bin/go
GO := $(shell type -a -P go | head -n 1)
endif
build:
mkdir -p build
$(GO) build -ldflags "-w" -o build/stormfetch stormfetch
$(GO) build -ldflags "-w -X 'main.systemConfigDir=$(SYSCONFDIR)'" -o build/stormfetch stormfetch
install: build/stormfetch config/
mkdir -p $(DESTDIR)$(BINDIR)
@@ -33,4 +35,6 @@ run: build/stormfetch
build/stormfetch
clean:
rm -r build/
rm -r build/
.PHONY: build
+2 -2
View File
@@ -3,7 +3,7 @@
## A simple linux fetch program written in go and bash
### Developers:
- [CapCreeperGR ](https://gitlab.com/CapCreeperGR)
- [EnumDev](https://gitlab.com/EnumDev)
### Project Information
Stormfetch is a program that can read your system's information and display it in the terminal along with the ASCII art of the Linux distribution you are running.
@@ -20,7 +20,7 @@ Stormfetch is still in beta, so distro compatibility is limited. If you would li
- Download `make` from your package manager
- Run the following command to compile the project
```
make
make SYSCONFDIR=/etc
```
- Run the following command to install stormfetch into your system. You may also append a DESTDIR variable at the end of this line if you wish to install in a different location
```
+20
View File
@@ -0,0 +1,20 @@
#/45;27;45;7
${C1} 'o'
'ooo'
'ooxoo'
'ooxxxoo'
'oookkxxoo'
'oiioxkkxxoo'
':;:iiiioxxxoo'
`'.;::ioxxoo'
'-. `':;jiooo'
'oooio-.. `'i:io'
'ooooxxxxoio:,. `'-;'
'ooooxxxxxkkxoooIi:-. `'
'ooooxxxxxkkkkxoiiiiiji'
'ooooxxxxxkxxoiiii:'` .i'
'ooooxxxxxoi:::'` .;ioxo'
'ooooxooi::'` .:iiixkxxo'
'ooooi:'` `'';ioxxo'
'i:'` '':io'
'` `'
+21
View File
@@ -0,0 +1,21 @@
#/33;7;11;15
${C1} /////////////
/////////////////////
///////${C2}*767${C1}////////////////
//////${C2}7676767676*${C1}//////////////
/////${C2}76767${C1}//${C2}7676767${C1}//////////////
/////${C2}767676${C1}///${C2}*76767${C1}///////////////
///////${C2}767676${C1}///${C2}76767${C1}.///${C2}7676*${C1}///////
/////////${C2}767676${C1}//${C2}76767${C1}///${C2}767676${C1}////////
//////////${C2}76767676767${C1}////${C2}76767${C1}/////////
///////////${C2}76767676${C1}//////${C2}7676${C1}//////////
////////////,${C2}7676${C1},///////${C2}767${C1}///////////
/////////////*${C2}7676${C1}///////${C2}76${C1}////////////
///////////////${C2}7676${C1}////////////////////
///////////////${C2}7676${C1}///${C2}767${C1}////////////
//////////////////////${C2}'${C1}////////////
//////${C2}.7676767676767676767,${C1}//////
/////${C2}767676767676767676767${C1}/////
///////////////////////////
/////////////////////
/////////////
+15 -18
View File
@@ -1,18 +1,15 @@
#/6;10;5;12
${C1} @@@@@@@@@
@@@~~~~~~~~~@@
@@~~~ ~~@
@~~ @
@~ @@@ @
@@~ @ @@
@@~~ @
@@@~~ ~@@ @@@
~~~ ~~@@@ @@@@~~~
~~~@@@@~~~~
@@@@ @@@@@@@ ~~~~ @@@@
~~~~@@@@ @@~~~~~~~@@ @@@@
~~~~@@@@~~ ~~@@@@~~~~
@@@ ~~~~ @@@@@ ~~~~ @@@
~~~@@@@ @@@@~~~~~@@@@ @@@@~~~
~~~~@@@~~~~ ~~~~@@@~~~
~~~ ~~~
#/27;39;5;12
${C1}@@@@ ${C1}@@@${C2}*
${C1}@@${C2}~~~~${C1}@@ ${C1}@@${C2}~~~
${C1}@@${C2}~~ ${C2}~~${C1}@ ${C1}@@${C2}~~
${C1}@@${C2}~~ ${C2}~${C1}@ ${C1}@@@${C2}~~
${C2}*${C1}@@${C2}~~ ${C1}@@@@ ${C2}~${C1}@@@@${C2}~~~ ${C1}@@@${C2}*
${C2}~~ ${C1}@@${C2}~~~~${C1}@@ ${C2}~~~~ ${C1}@@${C2}~~~
${C1}@@${C2}~~ ${C2}~~${C1}@ ${C1}@@${C2}~~
${C1}@@${C2}~~ ${C2}~${C1}@ ${C1}@@@${C2}~~
${C2}*${C1}@@${C2}~~ ${C1}@@@@ ${C2}~${C1}@@@@${C2}~~~ ${C1}@@@${C2}*
${C2}~~ ${C1}@@${C2}~~~~${C1}@@ ${C2}~~~~ ${C1}@@${C2}~~~
${C1}@@${C2}~~ ${C2}~~${C1}@ ${C1}@@${C2}~~
${C1}@@${C2}~~ ${C2}~${C1}@ ${C1}@@@${C2}~~
${C2}*${C1}@@${C2}~~ ${C2}~${C1}@@@@${C2}~~~
${C2}~~ ${C2}~~~~
+19
View File
@@ -0,0 +1,19 @@
#/2;36;72;15
${C2}:::::----:::::
${C2}::----------------::=
${C2}:-------------------::
${C1} : ${C2}:::. ..:-------:
${C1} =*=. ${C2}.:-----:
${C1} =****- ${C2}:-----:
${C1}=*****- ${C2}:::::: :-----:
${C1}=****+ ${C2}:--------: :----:
${C1}+****- ${C2}.----------. :----:
${C1}+****- ${C2}.----------. :-----
${C1}=****+ ${C2}:--------: :----:
${C1}=*****- ${C2}:::::: :-----:
${C1} =*****- ${C2}:----:
${C1} =*****+: ${C2}:-:
${C1} =*******=:: ::=-. ${C2}.
${C1} ==*******************-
${C1} ===****************=-
${C1} ===+=****++===
+2
View File
@@ -3,3 +3,5 @@ fetch_script: auto
ansii_colors: []
force_config_ansii: false
dependency_warning: true
show_fs_type: true
hidden_gpus: []
+31 -13
View File
@@ -5,26 +5,44 @@ echo -e "${C3}Hostname: ${C4}$(cat /etc/hostname)"
echo -e "${C3}Kernel: ${C4}$(uname -s) $(uname -r)"
echo -e "${C3}Packages: ${C4}$(get_packages)"
echo -e "${C3}Shell: ${C4}${USER_SHELL}"
if [ ! -z "$CPU_MODEL" ]; then echo -e "${C3}CPU: ${C4}${CPU_MODEL} (${CPU_THREADS} threads)"; fi
if [ ! -z "$GPU_MODEL" ]; then echo -e "${C3}GPU: ${C4}${GPU_MODEL}"; fi
if [ ! -z "$MEM_TOTAL" ] && [ ! -z "$MEM_USED" ]; then echo -e "${C3}Memory: ${C4}${MEM_USED} MiB / ${MEM_TOTAL} MiB"; fi
for i in $(seq ${MOUNTED_PARTITIONS}); do
device="PARTITION${i}_DEVICE"
mountpoint="PARTITION${i}_MOUNTPOINT"
label="PARTITION${i}_LABEL"
total="PARTITION${i}_TOTAL_SIZE"
used="PARTITION${i}_USED_SIZE"
echo -e "${C3}Init: ${C4}${INIT_SYSTEM}"
echo -e "${C3}Libc: ${C4}${LIBC}"
[ -n "$MOTHERBOARD" ] && echo -e "${C3}Motherboard: ${C4}${MOTHERBOARD}"
[ -n "$CPU_MODEL" ] && echo -e "${C3}CPU: ${C4}${CPU_MODEL} (${CPU_THREADS} threads)"
for i in $(seq "${CONNECTED_GPUS}"); do
gpu="GPU$i"
echo -e "${C3}GPU: ${C4}${!gpu}"
done
[ -n "$MEM_TOTAL" ] && [ -n "$MEM_USED" ] && echo -e "${C3}Memory: ${C4}${MEM_USED} MiB / ${MEM_TOTAL} MiB"
for i in $(seq "${MOUNTED_PARTITIONS}"); do
mountpoint="PARTITION${i}_MOUNTPOINT"
label="PARTITION${i}_LABEL"
type="PARTITION${i}_TYPE"
total="PARTITION${i}_TOTAL_SIZE"
used="PARTITION${i}_USED_SIZE"
if [ -z "${!type}" ]; then
if [ -z "${!label}" ]; then
echo -e "${C3}Partition ${!mountpoint}: ${C4}${!used}/${!total}"
else
echo -e "${C3}Partition ${!label}: ${C4}${!used}/${!total}"
fi
done
if [ ! -z "$DISPLAY_PROTOCOL" ]; then
else
if [ -z "${!label}" ]; then
echo -e "${C3}Partition ${!mountpoint} (${!type}): ${C4}${!used}/${!total}"
else
echo -e "${C3}Partition ${!label} (${!type}): ${C4}${!used}/${!total}"
fi
fi
done
[ -n "$LOCAL_IPV4" ] && echo -e "${C3}Local IPv4 Address: ${C4}${LOCAL_IPV4}"
if [ -n "$DISPLAY_PROTOCOL" ]; then
echo -e "${C3}Display Protocol: ${C4}${DISPLAY_PROTOCOL}"
for i in $(seq ${CONNECTED_MONITORS}); do
for i in $(seq "${CONNECTED_MONITORS}"); do
monitor="MONITOR$i"
echo -e "${C3}Screen $i: ${C4}${!monitor}"
done
fi
if [ ! -z "$DE_WM" ]; then echo -e "${C3}DE/WM: ${C4}${DE_WM}"; fi
[ -n "$DE_WM" ] && echo -e "${C3}DE/WM: ${C4}${DE_WM}"
# Exiting with error code 0 in case the condition above returns 1
exit 0
+5 -2
View File
@@ -20,11 +20,14 @@ get_packages() {
if command_exists rpm; then
ARRAY+=("$(rpm -qa | wc -l) (rpm)")
fi
if command_exists xbps-query; then
ARRAY+=("$(xbps-query -l | wc -l) (xbps)")
fi
if command_exists bpm; then
ARRAY+=("$(bpm list -n) (bpm)")
ARRAY+=("$(bpm list -c) (bpm)")
fi
if command_exists emerge; then
ARRAY+=("$(ls -l /var/db/pkg/ | wc -l) (emerge)")
ARRAY+=("$(ls -l /var/db/pkg/* | wc -l) (emerge)")
fi
if command_exists flatpak; then
ARRAY+=("$(flatpak list | wc -l) (flatpak)")
+1
View File
@@ -10,6 +10,7 @@ require (
)
require (
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/jackmordaunt/pcidb v1.0.1 // indirect
github.com/jackmordaunt/wmi v1.2.4 // indirect
+2
View File
@@ -1,5 +1,7 @@
github.com/BurntSushi/xgb v0.0.0-20210121224620-deaf085860bc h1:7D+Bh06CRPCJO3gr2F7h1sriovOZ8BMhca2Rg85c2nk=
github.com/BurntSushi/xgb v0.0.0-20210121224620-deaf085860bc/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a h1:vxnBhFDDT+xzxf1jTJKMKZw3H0swfWk9RpWbBbDK5+0=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/jackmordaunt/ghw v1.0.4 h1:as+COFuPuXaNQC3WqzoHS/E2JYWZU7gN8ompNTUxNxs=
+75 -23
View File
@@ -11,17 +11,24 @@ import (
"regexp"
"strconv"
"strings"
"time"
)
var systemConfigDir = "/etc/"
var configPath = ""
var fetchScriptPath = ""
var TimeTaken = false
var config = StormfetchConfig{
Ascii: "auto",
FetchScript: "auto",
AnsiiColors: make([]int, 0),
ForceConfigAnsii: false,
DependencyWarning: true,
ShowFSType: false,
HiddenGPUS: make([]int, 0),
}
type StormfetchConfig struct {
@@ -31,6 +38,8 @@ type StormfetchConfig struct {
AnsiiColors []int `yaml:"ansii_colors"`
ForceConfigAnsii bool `yaml:"force_config_ansii"`
DependencyWarning bool `yaml:"dependency_warning"`
ShowFSType bool `yaml:"show_fs_type"`
HiddenGPUS []int `yaml:"hidden_gpus"`
}
func main() {
@@ -42,12 +51,12 @@ func main() {
func readConfig() {
// Get home directory
configDir, _ := os.UserConfigDir()
userConfigDir, _ := os.UserConfigDir()
// Find valid config directory
if _, err := os.Stat(path.Join(configDir, "stormfetch/config.yaml")); err == nil {
configPath = path.Join(configDir, "stormfetch/config.yaml")
} else if _, err := os.Stat("/etc/stormfetch/config.yaml"); err == nil {
configPath = "/etc/stormfetch/config.yaml"
if _, err := os.Stat(path.Join(userConfigDir, "stormfetch/config.yaml")); err == nil {
configPath = path.Join(userConfigDir, "stormfetch/config.yaml")
} else if _, err := os.Stat(path.Join(systemConfigDir, "stormfetch/config.yaml")); err == nil {
configPath = path.Join(systemConfigDir, "stormfetch/config.yaml")
} else {
log.Fatalf("Config file not found: %s", err.Error())
}
@@ -70,18 +79,19 @@ func readConfig() {
log.Fatalf("Fetch script path points to a directory")
}
}
if _, err := os.Stat(path.Join(configDir, "stormfetch/fetch_script.sh")); err == nil {
fetchScriptPath = path.Join(configDir, "stormfetch/fetch_script.sh")
} else if _, err := os.Stat("/etc/stormfetch/fetch_script.sh"); err == nil {
fetchScriptPath = "/etc/stormfetch/fetch_script.sh"
if _, err := os.Stat(path.Join(userConfigDir, "stormfetch/fetch_script.sh")); err == nil {
fetchScriptPath = path.Join(userConfigDir, "stormfetch/fetch_script.sh")
} else if _, err := os.Stat(path.Join(systemConfigDir, "stormfetch/fetch_script.sh")); err == nil {
fetchScriptPath = path.Join(systemConfigDir, "stormfetch/fetch_script.sh")
} else {
log.Fatalf("Fetch script file not found: %s", err.Error())
}
}
func readFlags() {
flag.StringVar(&config.Ascii, "ascii", config.Ascii, "help message for flagname")
flag.StringVar(&config.DistroName, "distro-name", config.DistroName, "help message for flagname")
flag.StringVar(&config.Ascii, "ascii", config.Ascii, "Set distro ascii")
flag.StringVar(&config.DistroName, "distro-name", config.DistroName, "Set distro name")
flag.BoolVar(&TimeTaken, "time-taken", false, "Show time taken for fetched information")
flag.Parse()
}
@@ -105,19 +115,38 @@ func checkDependencies() {
}
}
func SetupFetchEnv() []string {
func SetupFetchEnv(showTimeTaken bool) []string {
var env = make(map[string]string)
env["DISTRO_LONG_NAME"] = getDistroInfo().LongName
env["DISTRO_SHORT_NAME"] = getDistroInfo().ShortName
env["CPU_MODEL"] = getCPUName()
env["CPU_THREADS"] = strconv.Itoa(getCPUThreads())
setVariable := func(key string, setter func() string) {
start := time.Now().UnixMilli()
env[key] = setter()
end := time.Now().UnixMilli()
if showTimeTaken {
fmt.Println(fmt.Sprintf("Setting '%s' took %d milliseconds", key, end-start))
}
}
setVariable("DISTRO_LONG_NAME", func() string { return getDistroInfo().LongName })
setVariable("DISTRO_SHORT_NAME", func() string { return getDistroInfo().ShortName })
setVariable("CPU_MODEL", func() string { return getCPUName() })
setVariable("MOTHERBOARD", func() string { return getMotherboardModel() })
setVariable("CPU_THREADS", func() string { return strconv.Itoa(getCPUThreads()) })
start := time.Now().UnixMilli()
memory := GetMemoryInfo()
end := time.Now().UnixMilli()
if showTimeTaken {
fmt.Println(fmt.Sprintf("Setting '%s' took %d milliseconds", "MEM_*", end-start))
}
if memory != nil {
env["MEM_TOTAL"] = strconv.Itoa(memory.MemTotal)
env["MEM_USED"] = strconv.Itoa(memory.MemTotal - memory.MemAvailable)
env["MEM_FREE"] = strconv.Itoa(memory.MemAvailable)
}
start = time.Now().UnixMilli()
partitions := getMountedPartitions()
end = time.Now().UnixMilli()
if showTimeTaken {
fmt.Println(fmt.Sprintf("Setting '%s' took %d milliseconds", "PARTITION_*", end-start))
}
if len(partitions) != 0 {
env["MOUNTED_PARTITIONS"] = strconv.Itoa(len(partitions))
for i, part := range partitions {
@@ -126,23 +155,46 @@ func SetupFetchEnv() []string {
if part.Label != "" {
env["PARTITION"+strconv.Itoa(i+1)+"_LABEL"] = part.Label
}
if part.Type != "" && config.ShowFSType {
env["PARTITION"+strconv.Itoa(i+1)+"_TYPE"] = part.Type
}
env["PARTITION"+strconv.Itoa(i+1)+"_TOTAL_SIZE"] = FormatBytes(part.TotalSize)
env["PARTITION"+strconv.Itoa(i+1)+"_USED_SIZE"] = FormatBytes(part.UsedSize)
env["PARTITION"+strconv.Itoa(i+1)+"_FREE_SIZE"] = FormatBytes(part.FreeSize)
}
}
env["DE_WM"] = GetDEWM()
env["USER_SHELL"] = GetShell()
env["DISPLAY_PROTOCOL"] = GetDisplayProtocol()
setVariable("DE_WM", func() string { return GetDEWM() })
setVariable("USER_SHELL", func() string { return GetShell() })
setVariable("DISPLAY_PROTOCOL", func() string { return GetDisplayProtocol() })
setVariable("LIBC", func() string { return GetLibc() })
setVariable("INIT_SYSTEM", func() string { return GetInitSystem() })
setVariable("LOCAL_IPV4", func() string { return GetLocalIP() })
start = time.Now().UnixMilli()
monitors := getMonitorResolution()
end = time.Now().UnixMilli()
if showTimeTaken {
fmt.Println(fmt.Sprintf("Setting '%s' took %d milliseconds", "MONITOR_*", end-start))
}
if len(monitors) != 0 {
env["CONNECTED_MONITORS"] = strconv.Itoa(len(monitors))
for i, monitor := range monitors {
env["MONITOR"+strconv.Itoa(i+1)] = monitor
}
}
if getGPUName() != "" {
env["GPU_MODEL"] = getGPUName()
start = time.Now().UnixMilli()
gpus := getGPUNames()
end = time.Now().UnixMilli()
if showTimeTaken {
fmt.Println(fmt.Sprintf("Setting '%s' took %d milliseconds", "GPU_*", end-start))
}
if len(gpus) != 0 {
env["CONNECTED_GPUS"] = strconv.Itoa(len(gpus))
for i, gpu := range gpus {
if gpu == "" {
continue
}
env["GPU"+strconv.Itoa(i+1)] = gpu
}
}
var ret = make([]string, len(env))
@@ -201,14 +253,14 @@ func runStormfetch() {
cmd := exec.Command("/bin/bash", fetchScriptPath)
cmd.Dir = path.Dir(fetchScriptPath)
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, SetupFetchEnv()...)
cmd.Env = append(cmd.Env, SetupFetchEnv(TimeTaken)...)
cmd.Env = append(cmd.Env, "C0=\033[0m")
for key, value := range colorMap {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", key, value))
}
out, err := cmd.Output()
if err != nil {
log.Fatal(err)
log.Fatalf("Error: Could not run fetch script: %s", err)
}
// Print Distro Information
maxWidth := 0
Binary file not shown.

Before

Width:  |  Height:  |  Size: 163 KiB

After

Width:  |  Height:  |  Size: 121 KiB

+128 -32
View File
@@ -3,13 +3,13 @@ package main
import (
"bufio"
"fmt"
"github.com/BurntSushi/xgb"
"github.com/BurntSushi/xgb/xinerama"
"github.com/go-gl/glfw/v3.3/glfw"
"github.com/jackmordaunt/ghw"
"github.com/mitchellh/go-ps"
"github.com/moby/sys/mountinfo"
"log"
"math"
"net"
"os"
"os/exec"
"path"
@@ -73,8 +73,8 @@ func getDistroAsciiArt() string {
}
userConfDir, err := os.UserConfigDir()
if err != nil {
if _, err := os.Stat(path.Join("/etc/stormfetch/ascii/", id)); err == nil {
bytes, err := os.ReadFile(path.Join("/etc/stormfetch/ascii/", id))
if _, err := os.Stat(path.Join(systemConfigDir, "stormfetch/ascii/", id)); err == nil {
bytes, err := os.ReadFile(path.Join(systemConfigDir, "stormfetch/ascii/", id))
if err != nil {
return defaultAscii
}
@@ -89,8 +89,8 @@ func getDistroAsciiArt() string {
return defaultAscii
}
return string(bytes)
} else if _, err := os.Stat(path.Join("/etc/stormfetch/ascii/", id)); err == nil {
bytes, err := os.ReadFile(path.Join("/etc/stormfetch/ascii/", id))
} else if _, err := os.Stat(path.Join(systemConfigDir, "stormfetch/ascii/", id)); err == nil {
bytes, err := os.ReadFile(path.Join(systemConfigDir, "stormfetch/ascii/", id))
if err != nil {
return defaultAscii
}
@@ -100,6 +100,14 @@ func getDistroAsciiArt() string {
}
}
func getMotherboardModel() string {
bytes, err := os.ReadFile("/sys/devices/virtual/dmi/id/board_name")
if err != nil {
return ""
}
return strings.TrimSpace(string(bytes))
}
func getCPUName() string {
cpu, err := ghw.CPU()
if err != nil {
@@ -119,22 +127,21 @@ func getCPUThreads() int {
return int(cpu.TotalThreads)
}
func getGPUName() string {
null, _ := os.Open(os.DevNull)
serr := os.Stderr
os.Stderr = null
gpu, err := ghw.GPU()
defer null.Close()
os.Stderr = serr
func getGPUNames() []string {
var ret []string
cmd := exec.Command("/bin/bash", "-c", "lspci -v -m | grep 'VGA' -A6 | grep '^Device:' | sed 's/^Device://' | awk '{$1=$1};1'")
bytes, err := cmd.Output()
if err != nil {
return ""
return nil
}
for _, graphics := range gpu.GraphicsCards {
if graphics.DeviceInfo != nil {
return graphics.DeviceInfo.Product.Name
for _, name := range strings.Split(string(bytes), "\n") {
name = strings.TrimSpace(name)
if name == "" {
continue
}
ret = append(ret, name)
}
return ""
return ret
}
type Memory struct {
@@ -227,6 +234,8 @@ func GetShell() string {
return "Zsh " + runCommand("$SHELL --version | awk '{print $2}'")
case "fish":
return "Fish " + runCommand("$SHELL --version | awk '{print $3}'")
case "nu":
return "Nushell " + runCommand("$SHELL --version")
default:
return "Unknown"
}
@@ -235,7 +244,7 @@ func GetShell() string {
func GetDEWM() string {
processes, err := ps.Processes()
if err != nil {
log.Fatal(err)
log.Fatalf("Error: could not get processes: %s", err)
}
var executables []string
for _, process := range processes {
@@ -264,17 +273,25 @@ func GetDEWM() string {
} else if processExists("gnome-session") {
return "Gnome " + runCommand("gnome-shell --version | awk '{print $3}'")
} else if processExists("xfce4-session") {
return "XFCE " + runCommand("xfce4-session --version | grep xfce4-session | awk '{print $2}'")
return "XFCE " + runCommand("xfce4-session --version | head -n1 | awk '{print $2}'")
} else if processExists("cinnamon") {
return "Cinnamon " + runCommand("cinnamon --version | awk '{print $3}'")
} else if processExists("mate-panel") {
return "MATE " + runCommand("mate-about --version | awk '{print $4}'")
} else if processExists("lxsession") {
return "LXDE"
} else if processExists("i3") {
return "i3 " + runCommand("i3 --version | awk '{print $3}'")
} else if processExists("sway") {
return "Sway " + runCommand("sway --version | awk '{print $3}'")
if runCommand("sway --version | awk '{print $1}'") == "swayfx" {
return "SwayFX " + runCommand("sway --version | awk '{print $3}'")
} else {
return "Sway " + runCommand("sway --version | awk '{print $3}'")
}
} else if processExists("bspwm") {
return "Bspwm " + runCommand("bspwm -v")
} else if processExists("Hyprland") {
return "Hyprland " + runCommand("hyprctl version | sed -n 3p | awk '{print $2}' | tr -d 'v,'")
} else if processExists("icewm-session") {
return "IceWM " + runCommand("icewm --version | awk '{print $2}'")
}
@@ -293,20 +310,16 @@ func GetDisplayProtocol() string {
func getMonitorResolution() []string {
var monitors []string
if GetDisplayProtocol() == "X11" {
conn, err := xgb.NewConn()
if GetDisplayProtocol() != "" {
err := glfw.Init()
if err != nil {
return nil
panic(err)
}
err = xinerama.Init(conn)
if err != nil {
return nil
}
reply, _ := xinerama.QueryScreens(conn).Reply()
conn.Close()
for _, screen := range reply.ScreenInfo {
monitors = append(monitors, strconv.Itoa(int(screen.Width))+"x"+strconv.Itoa(int(screen.Height)))
for _, monitor := range glfw.GetMonitors() {
mode := monitor.GetVideoMode()
monitors = append(monitors, fmt.Sprintf("%dx%d %dHz", mode.Width, mode.Height, mode.RefreshRate))
}
defer glfw.Terminate()
}
return monitors
}
@@ -315,6 +328,7 @@ type partition struct {
Device string
MountPoint string
Label string
Type string
TotalSize uint64
UsedSize uint64
FreeSize uint64
@@ -324,6 +338,10 @@ func getMountedPartitions() []partition {
mounts, err := mountinfo.GetMounts(func(info *mountinfo.Info) (skip, stop bool) {
return !strings.HasPrefix(info.Source, "/dev/"), false
})
fslabels, err := os.ReadDir("/dev/disk/by-label")
if err != nil && !os.IsNotExist(err) {
return nil
}
partlabels, err := os.ReadDir("/dev/disk/by-partlabel")
if err != nil && !os.IsNotExist(err) {
return nil
@@ -336,16 +354,33 @@ func getMountedPartitions() []partition {
}
labels[link] = entry.Name()
}
for _, entry := range fslabels {
link, err := filepath.EvalSymlinks(filepath.Join("/dev/disk/by-label/", entry.Name()))
if err != nil {
continue
}
labels[link] = entry.Name()
}
var partitions []partition
for _, entry := range mounts {
p := partition{
entry.Source,
entry.Mountpoint,
"",
entry.FSType,
0,
0,
0,
}
skip := false
for _, part := range partitions {
if part.Device == p.Device {
skip = true
}
}
if skip {
continue
}
if value, ok := labels[entry.Source]; ok {
p.Label = value
}
@@ -368,6 +403,67 @@ func getMountedPartitions() []partition {
return partitions
}
func GetInitSystem() string {
runCommand := func(command string) string {
cmd := exec.Command("/bin/bash", "-c", command)
workdir, err := os.Getwd()
if err != nil {
return ""
}
cmd.Dir = workdir
cmd.Env = os.Environ()
out, err := cmd.Output()
if err != nil {
return ""
}
return strings.TrimSpace(string(out))
}
link, err := os.Readlink("/sbin/init")
if err != nil {
return "Unknown"
}
if path.Base(link) == "systemd" {
return "Systemd " + runCommand("systemctl --version | head -1 | awk '{print $2}'")
} else if path.Base(link) == "openrc-init" {
return "OpenRC " + runCommand("openrc --version | awk '{print $3}'")
} else if path.Base(link) == "runit-init" {
return "Runit"
} else {
return "Unknown"
}
}
func GetLibc() string {
cmd := exec.Command("/bin/bash", "-c", "find /usr/lib64/ -maxdepth 1 -name 'ld-*' | grep musl")
if err := cmd.Run(); err != nil {
cmd = exec.Command("/bin/bash", "-c", "ldd --version | head -1 | cut -d' ' -f4")
bytes, err := cmd.Output()
if err != nil {
return "Glibc"
}
return "Glibc " + strings.TrimSpace(string(bytes))
}
cmd = exec.Command("/bin/bash", "-c", "ldd 2>&1 | grep 'Version' | cut -d' ' -f2")
bytes, err := cmd.Output()
if err != nil {
return "Musl"
}
return "Musl " + strings.TrimSpace(string(bytes))
}
func GetLocalIP() string {
conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil {
return ""
}
defer conn.Close()
localAddr := conn.LocalAddr().(*net.UDPAddr)
return localAddr.IP.String()
}
func FormatBytes(bytes uint64) string {
var suffixes [6]string
suffixes[0] = "B"