mirror of
https://github.com/EnumeratedDev/stormfetch.git
synced 2026-09-16 16:06:11 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed45b739a5 | ||
|
|
8c380dbec4 | ||
|
|
7c493dc9f9 | ||
|
|
b8d7017299 | ||
|
|
cd08003752 | ||
|
|
c4c71fc49a | ||
|
|
efdbe94193 | ||
|
|
7b8c017ed0 | ||
|
|
66f3891b40 | ||
|
|
efae7c4b93 | ||
|
|
24da6ce083 | ||
|
|
b90b869643 | ||
|
|
720eb845ca | ||
|
|
81c4006e48 | ||
|
|
58b3e82346 | ||
|
|
ba67c074db | ||
|
|
c8b3f9f4a4 | ||
|
|
c05f34eb7d | ||
|
|
39b901e6fd |
@@ -1,4 +0,0 @@
|
||||
.idea
|
||||
build
|
||||
stormfetch
|
||||
stormfetch.tar.gz
|
||||
@@ -13,7 +13,7 @@ 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)
|
||||
@@ -34,3 +34,5 @@ run: build/stormfetch
|
||||
|
||||
clean:
|
||||
rm -r build/
|
||||
|
||||
.PHONY: build
|
||||
@@ -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
|
||||
```
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#/43;45;45;15
|
||||
${C3}.${C1}-------------------------:
|
||||
.${C2}+=${C1}========================.
|
||||
:${C2}++${C1}===${C2}++===${C1}===============- :${C2}++${C1}-
|
||||
:${C2}*++${C1}====${C2}+++++==${C1}===========- .==:
|
||||
-${C2}*+++${C1}=====${C2}+***++=${C1}=========:
|
||||
=${C2}*++++=${C1}=======------------:
|
||||
=${C2}*+++++=${C1}====- ${C3}...${C1}
|
||||
.${C2}+*+++++${C1}=-===: .${C2}=+++=${C1}:
|
||||
:${C2}++++${C1}=====-==: -***${C2}**${C1}+
|
||||
:${C2}++=${C1}=======-=. .=+**+${C3}.${C1}
|
||||
.${C2}+${C1}==========-. ${C3}.${C1}
|
||||
:${C2}+++++++${C1}====- ${C3}.${C1}--==-${C3}.${C1}
|
||||
:${C2}++${C1}==========. ${C3}:${C2}+++++++${C1}${C3}:
|
||||
${C1}.-===========. =*****+*+
|
||||
${C1}.-===========: .+*****+:
|
||||
${C1}-=======${C2}++++${C1}:::::::::::::::::::::::::-: ${C3}.${C1}---:
|
||||
:======${C2}++++${C1}====${C2}+++******************=.
|
||||
${C1}:=====${C2}+++${C1}==========${C2}++++++++++++++*-
|
||||
${C1}.====${C2}++${C1}==============${C2}++++++++++*-
|
||||
${C1}.===${C2}+${C1}==================${C2}+++++++:
|
||||
${C1}.-=======================${C2}+++:
|
||||
${C3}..........................
|
||||
@@ -0,0 +1,20 @@
|
||||
#/34;15;46;252
|
||||
${C2} ...-:::::-...
|
||||
${C2} .-MMMMMMMMMMMMMMM-.
|
||||
.-MMMM${C1}`..-:::::::-..`${C2}MMMM-.
|
||||
.:MMMM${C1}.:MMMMMMMMMMMMMMM:.${C2}MMMM:.
|
||||
-MMM${C1}-M---MMMMMMMMMMMMMMMMMMM.${C2}MMM-
|
||||
`:MMM${C1}:MM` :MMMM:....::-...-MMMM:${C2}MMM:`
|
||||
:MMM${C1}:MMM` :MM:` `` `` `:MMM:${C2}MMM:
|
||||
.MMM${C1}.MMMM` :MM. -MM. .MM- `MMMM.${C2}MMM.
|
||||
:MMM${C1}:MMMM` :MM. -MM- .MM: `MMMM-${C2}MMM:
|
||||
:MMM${C1}:MMMM` :MM. -MM- .MM: `MMMM:${C2}MMM:
|
||||
:MMM${C1}:MMMM` :MM. -MM- .MM: `MMMM-${C2}MMM:
|
||||
.MMM${C1}.MMMM` :MM:--:MM:--:MM: `MMMM.${C2}MMM.
|
||||
:MMM${C1}:MMM- `-MMMMMMMMMMMM-` -MMM-${C2}MMM:
|
||||
:MMM${C1}:MMM:` `:MMM:${C2}MMM:
|
||||
.MMM${C1}.MMMM:--------------:MMMM.${C2}MMM.
|
||||
'-MMMM${C1}.-MMMMMMMMMMMMMMM-.${C2}MMMM-'
|
||||
'.-MMMM${C1}``--:::::--``${C2}MMMM-.'
|
||||
${C2} '-MMMMMMMMMMMMM-'
|
||||
${C2} ``-:::::-``
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
#/1;7;3;15
|
||||
${C1} .-/+oossssoo+\-.
|
||||
´:+ssssssssssssssssss+:`
|
||||
':+ssssssssssssssssss+:'
|
||||
-+ssssssssssssssssssyyssss+-
|
||||
.ossssssssssssssssss${C2}dMMMNy${C1}sssso.
|
||||
/sssssssssss${C2}hdmmNNmmyNMMMMh${C1}ssssss\
|
||||
@@ -17,5 +17,5 @@ oss${C2}yNMMMNyMMh${C1}sssssssssssssshmmmh${C1}ssssssso
|
||||
\sssssssssss${C2}hdmNNNNmyNMMMMh${C1}ssssss/
|
||||
.ossssssssssssssssss${C2}dMMMNy${C1}sssso.
|
||||
-+sssssssssssssssss${C2}yyy${C1}ssss+-
|
||||
`:+ssssssssssssssssss+:`
|
||||
':+ssssssssssssssssss+:'
|
||||
.-\+oossssoo+/-.
|
||||
|
||||
@@ -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} ===+=****++===
|
||||
@@ -3,3 +3,5 @@ fetch_script: auto
|
||||
ansii_colors: []
|
||||
force_config_ansii: false
|
||||
dependency_warning: true
|
||||
show_fs_type: true
|
||||
hidden_gpus: []
|
||||
|
||||
+19
-2
@@ -6,14 +6,31 @@ 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
|
||||
for i in $(seq ${CONNECTED_GPUS}); do
|
||||
gpu="GPU$i"
|
||||
echo -e "${C3}GPU: ${C4}${!gpu}"
|
||||
done
|
||||
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"
|
||||
type="PARTITION${i}_TYPE"
|
||||
total="PARTITION${i}_TOTAL_SIZE"
|
||||
used="PARTITION${i}_USED_SIZE"
|
||||
echo -e "${C3}${!mountpoint}: ${C4}${!used}/${!total}"
|
||||
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
|
||||
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
|
||||
if [ ! -z "$DISPLAY_PROTOCOL" ]; then
|
||||
echo -e "${C3}Display Protocol: ${C4}${DISPLAY_PROTOCOL}"
|
||||
|
||||
@@ -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)")
|
||||
|
||||
@@ -14,6 +14,7 @@ require (
|
||||
github.com/jackmordaunt/pcidb v1.0.1 // indirect
|
||||
github.com/jackmordaunt/wmi v1.2.4 // indirect
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
github.com/moby/sys/mountinfo v0.7.1 // indirect
|
||||
golang.org/x/sys v0.3.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
||||
)
|
||||
|
||||
@@ -15,7 +15,10 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc=
|
||||
github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg=
|
||||
github.com/moby/sys/mountinfo v0.7.1 h1:/tTvQaSJRr2FshkhXiIpux6fQ2Zvc4j7tAhMTStAG2g=
|
||||
github.com/moby/sys/mountinfo v0.7.1/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI=
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
|
||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
yaml "gopkg.in/yaml.v3"
|
||||
"gopkg.in/yaml.v3"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -12,6 +13,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var systemConfigDir = "/etc/"
|
||||
|
||||
var configPath = ""
|
||||
var fetchScriptPath = ""
|
||||
|
||||
@@ -21,28 +24,36 @@ var config = StormfetchConfig{
|
||||
AnsiiColors: make([]int, 0),
|
||||
ForceConfigAnsii: false,
|
||||
DependencyWarning: true,
|
||||
ShowFSType: false,
|
||||
HiddenGPUS: make([]int, 0),
|
||||
}
|
||||
|
||||
type StormfetchConfig struct {
|
||||
Ascii string `yaml:"distro_ascii"`
|
||||
DistroName string `yaml:"distro_name"`
|
||||
FetchScript string `yaml:"fetch_script"`
|
||||
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() {
|
||||
readConfig()
|
||||
readFlags()
|
||||
checkDependencies()
|
||||
runStormfetch()
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
@@ -65,13 +76,22 @@ 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.Parse()
|
||||
}
|
||||
|
||||
func checkDependencies() {
|
||||
// Show Dependency warning if enabled
|
||||
if config.DependencyWarning {
|
||||
var dependencies []string
|
||||
@@ -89,6 +109,68 @@ func readConfig() {
|
||||
fmt.Println("You can disable this warning through your stormfetch config")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func SetupFetchEnv() []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())
|
||||
memory := GetMemoryInfo()
|
||||
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)
|
||||
}
|
||||
partitions := getMountedPartitions()
|
||||
if len(partitions) != 0 {
|
||||
env["MOUNTED_PARTITIONS"] = strconv.Itoa(len(partitions))
|
||||
for i, part := range partitions {
|
||||
env["PARTITION"+strconv.Itoa(i+1)+"_DEVICE"] = part.Device
|
||||
env["PARTITION"+strconv.Itoa(i+1)+"_MOUNTPOINT"] = part.MountPoint
|
||||
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()
|
||||
monitors := getMonitorResolution()
|
||||
if len(monitors) != 0 {
|
||||
env["CONNECTED_MONITORS"] = strconv.Itoa(len(monitors))
|
||||
for i, monitor := range monitors {
|
||||
env["MONITOR"+strconv.Itoa(i+1)] = monitor
|
||||
}
|
||||
}
|
||||
gpus := getGPUNames()
|
||||
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))
|
||||
i := 0
|
||||
for key, value := range env {
|
||||
ret[i] = fmt.Sprintf("%s=%s", key, value)
|
||||
i++
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func runStormfetch() {
|
||||
// Fetch ascii art and apply colors
|
||||
colorMap := make(map[string]string)
|
||||
colorMap["C0"] = "\033[0m"
|
||||
@@ -152,9 +234,19 @@ func readConfig() {
|
||||
}
|
||||
}
|
||||
final := ""
|
||||
for lineIndex, line := range asciiSplit {
|
||||
lineVisibleLength := len(strings.Split(asciiNoColor, "\n")[lineIndex])
|
||||
y := len(asciiSplit)
|
||||
if len(asciiSplit) < len(strings.Split(string(out), "\n")) {
|
||||
y = len(strings.Split(string(out), "\n"))
|
||||
}
|
||||
for lineIndex := 0; lineIndex < y; lineIndex++ {
|
||||
line := ""
|
||||
for i := 0; i < maxWidth+5; i++ {
|
||||
line = line + " "
|
||||
}
|
||||
lastAsciiColor := ""
|
||||
if lineIndex < len(asciiSplit) {
|
||||
line = asciiSplit[lineIndex]
|
||||
lineVisibleLength := len(strings.Split(asciiNoColor, "\n")[lineIndex])
|
||||
if lineIndex != 0 {
|
||||
r := regexp.MustCompile("\033[38;5;[0-9]+m")
|
||||
matches := r.FindAllString(asciiSplit[lineIndex-1], -1)
|
||||
@@ -166,57 +258,13 @@ func readConfig() {
|
||||
line = line + " "
|
||||
}
|
||||
asciiSplit[lineIndex] = lastAsciiColor + line
|
||||
}
|
||||
str := string(out)
|
||||
if lineIndex < len(strings.Split(str, "\n")) {
|
||||
line = line + colorMap["C0"] + strings.Split(str, "\n")[lineIndex]
|
||||
}
|
||||
final += lastAsciiColor + line + "\n"
|
||||
}
|
||||
fmt.Println(final)
|
||||
}
|
||||
|
||||
func SetupFetchEnv() []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())
|
||||
memory := GetMemoryInfo()
|
||||
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)
|
||||
}
|
||||
partitions := getMountedPartitions()
|
||||
if len(partitions) != 0 {
|
||||
env["MOUNTED_PARTITIONS"] = strconv.Itoa(len(partitions))
|
||||
for i, part := range partitions {
|
||||
env["PARTITION"+strconv.Itoa(i+1)+"_DEVICE"] = part.Device
|
||||
env["PARTITION"+strconv.Itoa(i+1)+"_MOUNTPOINT"] = part.MountPoint
|
||||
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()
|
||||
monitors := getMonitorResolution()
|
||||
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()
|
||||
}
|
||||
|
||||
var ret = make([]string, len(env))
|
||||
i := 0
|
||||
for key, value := range env {
|
||||
ret[i] = fmt.Sprintf("%s=%s", key, value)
|
||||
i++
|
||||
}
|
||||
return ret
|
||||
final = strings.TrimRight(final, "\n\t ")
|
||||
fmt.Println(final + "\033[0m")
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 163 KiB After Width: | Height: | Size: 121 KiB |
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/BurntSushi/xgb/xinerama"
|
||||
"github.com/jackmordaunt/ghw"
|
||||
"github.com/mitchellh/go-ps"
|
||||
"github.com/moby/sys/mountinfo"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
@@ -27,41 +28,32 @@ type DistroInfo struct {
|
||||
}
|
||||
|
||||
func getDistroInfo() DistroInfo {
|
||||
distroID := ""
|
||||
info := DistroInfo{
|
||||
ID: "unknown",
|
||||
LongName: "Unknown",
|
||||
ShortName: "Unknown",
|
||||
}
|
||||
if strings.TrimSpace(config.DistroName) != "" {
|
||||
info.LongName = strings.TrimSpace(config.DistroName)
|
||||
info.ShortName = strings.TrimSpace(config.DistroName)
|
||||
}
|
||||
var releaseMap = make(map[string]string)
|
||||
if _, err := os.Stat("/etc/os-release"); err == nil {
|
||||
releaseMap, err = ReadKeyValueFile("/etc/os-release")
|
||||
if err != nil {
|
||||
return DistroInfo{
|
||||
ID: "unknown",
|
||||
LongName: "Unknown",
|
||||
ShortName: "Unknown",
|
||||
return info
|
||||
}
|
||||
}
|
||||
if value, ok := releaseMap["ID"]; ok {
|
||||
distroID = value
|
||||
}
|
||||
}
|
||||
|
||||
switch distroID {
|
||||
default:
|
||||
if id, ok := releaseMap["ID"]; ok {
|
||||
if longName, ok := releaseMap["PRETTY_NAME"]; ok {
|
||||
if shortName, ok := releaseMap["NAME"]; ok {
|
||||
return DistroInfo{
|
||||
ID: id,
|
||||
LongName: longName,
|
||||
ShortName: shortName,
|
||||
info.ID = id
|
||||
}
|
||||
if longName, ok := releaseMap["PRETTY_NAME"]; ok && info.LongName == "Unknown" {
|
||||
info.LongName = longName
|
||||
}
|
||||
if shortName, ok := releaseMap["NAME"]; ok && info.ShortName == "Unknown" {
|
||||
info.ShortName = shortName
|
||||
}
|
||||
}
|
||||
return DistroInfo{
|
||||
ID: "unknown",
|
||||
LongName: "Unknown",
|
||||
ShortName: "Unknown",
|
||||
}
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
func getDistroAsciiArt() string {
|
||||
@@ -102,7 +94,7 @@ func getDistroAsciiArt() string {
|
||||
if err != nil {
|
||||
return defaultAscii
|
||||
}
|
||||
return string(bytes)
|
||||
return strings.TrimRight(string(bytes), "\n\t ")
|
||||
} else {
|
||||
return defaultAscii
|
||||
}
|
||||
@@ -127,7 +119,8 @@ func getCPUThreads() int {
|
||||
return int(cpu.TotalThreads)
|
||||
}
|
||||
|
||||
func getGPUName() string {
|
||||
func getGPUNames() []string {
|
||||
var ret []string
|
||||
null, _ := os.Open(os.DevNull)
|
||||
serr := os.Stderr
|
||||
os.Stderr = null
|
||||
@@ -135,14 +128,17 @@ func getGPUName() string {
|
||||
defer null.Close()
|
||||
os.Stderr = serr
|
||||
if err != nil {
|
||||
return ""
|
||||
return nil
|
||||
}
|
||||
for i, graphics := range gpu.GraphicsCards {
|
||||
if slices.Contains(config.HiddenGPUS, i+1) {
|
||||
continue
|
||||
}
|
||||
for _, graphics := range gpu.GraphicsCards {
|
||||
if graphics.DeviceInfo != nil {
|
||||
return graphics.DeviceInfo.Product.Name
|
||||
ret = append(ret, graphics.DeviceInfo.Product.Name)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
return ret
|
||||
}
|
||||
|
||||
type Memory struct {
|
||||
@@ -267,7 +263,6 @@ func GetDEWM() string {
|
||||
}
|
||||
return strings.TrimSpace(string(out))
|
||||
}
|
||||
|
||||
if processExists("plasmashell") {
|
||||
return "KDE Plasma " + runCommand("plasmashell --version | awk '{print $2}'")
|
||||
} else if processExists("gnome-session") {
|
||||
@@ -323,51 +318,67 @@ func getMonitorResolution() []string {
|
||||
type partition struct {
|
||||
Device string
|
||||
MountPoint string
|
||||
Label string
|
||||
Type string
|
||||
TotalSize uint64
|
||||
UsedSize uint64
|
||||
FreeSize uint64
|
||||
}
|
||||
|
||||
func getMountedPartitions() []partition {
|
||||
entries, err := os.ReadDir("/dev/disk/by-partuuid")
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
bytes, err := os.ReadFile("/proc/mounts")
|
||||
if err != nil {
|
||||
partlabels, err := os.ReadDir("/dev/disk/by-partlabel")
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
mountsRaw := strings.Split(string(bytes), "\n")
|
||||
mounts := make(map[string]string)
|
||||
for i := 0; i < len(mountsRaw); i++ {
|
||||
split := strings.Split(mountsRaw[i], " ")
|
||||
if len(split) <= 2 {
|
||||
labels := make(map[string]string)
|
||||
for _, entry := range partlabels {
|
||||
link, err := filepath.EvalSymlinks(filepath.Join("/dev/disk/by-partlabel/", entry.Name()))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
mounts[split[0]] = split[1]
|
||||
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 entries {
|
||||
link, err := filepath.EvalSymlinks(filepath.Join("/dev/disk/by-partuuid/", entry.Name()))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if _, ok := mounts[link]; !ok {
|
||||
continue
|
||||
}
|
||||
for _, entry := range mounts {
|
||||
p := partition{
|
||||
link,
|
||||
mounts[link],
|
||||
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
|
||||
}
|
||||
buf := new(syscall.Statfs_t)
|
||||
err = syscall.Statfs(p.MountPoint, buf)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
continue
|
||||
}
|
||||
totalBlocks := buf.Blocks
|
||||
freeBlocks := buf.Bfree
|
||||
|
||||
Reference in New Issue
Block a user