mirror of
https://github.com/EnumeratedDev/stormfetch.git
synced 2026-09-16 07:56:12 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c493dc9f9 | ||
|
|
b8d7017299 | ||
|
|
cd08003752 | ||
|
|
c4c71fc49a | ||
|
|
efdbe94193 | ||
|
|
7b8c017ed0 | ||
|
|
66f3891b40 | ||
|
|
efae7c4b93 | ||
|
|
24da6ce083 | ||
|
|
b90b869643 | ||
|
|
720eb845ca | ||
|
|
81c4006e48 | ||
|
|
58b3e82346 | ||
|
|
ba67c074db | ||
|
|
c8b3f9f4a4 | ||
|
|
c05f34eb7d | ||
|
|
39b901e6fd | ||
|
|
2af3ab1156 | ||
|
|
aba10e3e9e | ||
|
|
0c376702c7 | ||
|
|
a5ffb4b32e | ||
|
|
4de0d34e28 | ||
|
|
7ed54ec1a5 | ||
|
|
2984a7da5f | ||
|
|
4a2833afff | ||
|
|
c13c730e4c | ||
|
|
4c72295972 | ||
|
|
a29a8f1dd9 | ||
|
|
1fc9a9ea79 | ||
|
|
01b23277fd |
@@ -1,4 +0,0 @@
|
|||||||
.idea
|
|
||||||
build
|
|
||||||
stormfetch
|
|
||||||
stormfetch.tar.gz
|
|
||||||
@@ -13,7 +13,7 @@ endif
|
|||||||
|
|
||||||
build:
|
build:
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
$(GO) build -o build/stormfetch stormfetch
|
$(GO) build -ldflags "-w" -o build/stormfetch stormfetch
|
||||||
|
|
||||||
install: build/stormfetch config/
|
install: build/stormfetch config/
|
||||||
mkdir -p $(DESTDIR)$(BINDIR)
|
mkdir -p $(DESTDIR)$(BINDIR)
|
||||||
@@ -29,5 +29,10 @@ compress: build/stormfetch config/
|
|||||||
tar --owner=root --group=root -czf stormfetch.tar.gz stormfetch
|
tar --owner=root --group=root -czf stormfetch.tar.gz stormfetch
|
||||||
rm -r stormfetch
|
rm -r stormfetch
|
||||||
|
|
||||||
|
run: build/stormfetch
|
||||||
|
build/stormfetch
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -r build/
|
rm -r build/
|
||||||
|
|
||||||
|
.PHONY: build
|
||||||
@@ -9,15 +9,15 @@
|
|||||||
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.
|
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.
|
||||||
Stormfetch is still in beta, so distro compatibility is limited. If you would like to contribute ASCII art or add other compatibility features feel free to create a pull request or notify me through GitLab Issues.
|
Stormfetch is still in beta, so distro compatibility is limited. If you would like to contribute ASCII art or add other compatibility features feel free to create a pull request or notify me through GitLab Issues.
|
||||||
|
|
||||||
|
### How it looks
|
||||||
|

|
||||||
|
|
||||||
### Installation Guide
|
### Installation Guide
|
||||||
#### AUR
|
#### Using a package manager
|
||||||
- If you are on Arch Linux, you can use your favorite AUR manager to install the `stormfetch` package.
|
- Arch Linux: You may use your favorite AUR manager to install the `stormfetch` package
|
||||||
#### Building from source
|
#### Building from source
|
||||||
- Download `go` from your package manager or from the go website
|
- Download `go` from your package manager or from the go website
|
||||||
- Download `make` from your package manager
|
- Download `make` from your package manager
|
||||||
- (Optional) Download `xorg-xhost` from your package manager to display DE/WM and monitor information
|
|
||||||
- (Optional) Download `xorg-xdpyinfo` from your package manager to display screen resolution
|
|
||||||
- (Optional) Download `lshw` from your package manager to display GPU information
|
|
||||||
- Run the following command to compile the project
|
- Run the following command to compile the project
|
||||||
```
|
```
|
||||||
make
|
make
|
||||||
|
|||||||
@@ -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
|
#/1;7;3;15
|
||||||
${C1} .-/+oossssoo+\-.
|
${C1} .-/+oossssoo+\-.
|
||||||
´:+ssssssssssssssssss+:`
|
':+ssssssssssssssssss+:'
|
||||||
-+ssssssssssssssssssyyssss+-
|
-+ssssssssssssssssssyyssss+-
|
||||||
.ossssssssssssssssss${C2}dMMMNy${C1}sssso.
|
.ossssssssssssssssss${C2}dMMMNy${C1}sssso.
|
||||||
/sssssssssss${C2}hdmmNNmmyNMMMMh${C1}ssssss\
|
/sssssssssss${C2}hdmmNNmmyNMMMMh${C1}ssssss\
|
||||||
@@ -17,5 +17,5 @@ oss${C2}yNMMMNyMMh${C1}sssssssssssssshmmmh${C1}ssssssso
|
|||||||
\sssssssssss${C2}hdmNNNNmyNMMMMh${C1}ssssss/
|
\sssssssssss${C2}hdmNNNNmyNMMMMh${C1}ssssss/
|
||||||
.ossssssssssssssssss${C2}dMMMNy${C1}sssso.
|
.ossssssssssssssssss${C2}dMMMNy${C1}sssso.
|
||||||
-+sssssssssssssssss${C2}yyy${C1}ssss+-
|
-+sssssssssssssssss${C2}yyy${C1}ssss+-
|
||||||
`:+ssssssssssssssssss+:`
|
':+ssssssssssssssssss+:'
|
||||||
.-\+oossssoo+/-.
|
.-\+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: []
|
ansii_colors: []
|
||||||
force_config_ansii: false
|
force_config_ansii: false
|
||||||
dependency_warning: true
|
dependency_warning: true
|
||||||
|
show_fs_type: true
|
||||||
|
hidden_gpus: []
|
||||||
|
|||||||
+35
-14
@@ -4,18 +4,39 @@ echo -e "${C3}Distribution: ${C4}${DISTRO_LONG_NAME} ($(uname -m))"
|
|||||||
echo -e "${C3}Hostname: ${C4}$(cat /etc/hostname)"
|
echo -e "${C3}Hostname: ${C4}$(cat /etc/hostname)"
|
||||||
echo -e "${C3}Kernel: ${C4}$(uname -s) $(uname -r)"
|
echo -e "${C3}Kernel: ${C4}$(uname -s) $(uname -r)"
|
||||||
echo -e "${C3}Packages: ${C4}$(get_packages)"
|
echo -e "${C3}Packages: ${C4}$(get_packages)"
|
||||||
echo -e "${C3}Shell: ${C4}$(get_shell)"
|
echo -e "${C3}Shell: ${C4}${USER_SHELL}"
|
||||||
echo -e "${C3}CPU: ${C4}$(get_cpu_name) ($(nproc) threads)"
|
if [ ! -z "$CPU_MODEL" ]; then echo -e "${C3}CPU: ${C4}${CPU_MODEL} (${CPU_THREADS} threads)"; fi
|
||||||
if command_exists lshw; then
|
for i in $(seq ${CONNECTED_GPUS}); do
|
||||||
echo -e "${C3}GPU: ${C4}$(lshw -class display 2> /dev/null | grep 'product' | cut -d":" -f2 | xargs)"
|
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"
|
||||||
|
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}"
|
||||||
|
for i in $(seq ${CONNECTED_MONITORS}); do
|
||||||
|
monitor="MONITOR$i"
|
||||||
|
echo -e "${C3}Screen $i: ${C4}${!monitor}"
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
echo -e "${C3}Memory: ${C4}$(get_used_mem) MiB / $(get_total_mem) MiB"
|
if [ ! -z "$DE_WM" ]; then echo -e "${C3}DE/WM: ${C4}${DE_WM}"; fi
|
||||||
if xhost >& /dev/null ; then
|
|
||||||
if get_de_wm &> /dev/null; then
|
|
||||||
echo -e "${C3}DE/WM: ${C4}$(get_de_wm)"
|
|
||||||
fi
|
|
||||||
if command_exists xdpyinfo ; then
|
|
||||||
echo -e "${C3}Screen Resolution: ${C4}$(get_screen_resolution)"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,77 +9,6 @@ command_exists() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
get_shell() {
|
|
||||||
case ${SHELL##*/} in
|
|
||||||
"")
|
|
||||||
echo "Unknown"
|
|
||||||
;;
|
|
||||||
sh|ash|dash|es)
|
|
||||||
echo "${SHELL##*/} $(${SHELL##*/} --version)"
|
|
||||||
;;
|
|
||||||
bash)
|
|
||||||
echo "${SHELL##*/} $(${SHELL##*/} -c "echo "'$BASH_VERSION')"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
SHELL_NAME=${SHELL##*/}
|
|
||||||
SHELL_VERSION="$($SHELL --version)"
|
|
||||||
SHELL_VERSION=${SHELL_VERSION//","}
|
|
||||||
SHELL_VERSION=${SHELL_VERSION//" "}
|
|
||||||
SHELL_VERSION=${SHELL_VERSION//"version"}
|
|
||||||
SHELL_VERSION=${SHELL_VERSION//"$SHELL_NAME"}
|
|
||||||
echo "$SHELL_NAME $SHELL_VERSION"
|
|
||||||
unset SHELL_NAME
|
|
||||||
unset SHELL_VERSION
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
get_cpu_name() {
|
|
||||||
grep -m1 "model name" /proc/cpuinfo | cut -d: -f2 | xargs
|
|
||||||
}
|
|
||||||
|
|
||||||
get_total_mem() {
|
|
||||||
free --mebi -t | grep 'Total' | tr -s ' ' | cut -d" " -f2
|
|
||||||
}
|
|
||||||
|
|
||||||
get_free_mem() {
|
|
||||||
free --mebi -t | grep 'Total' | tr -s ' ' | cut -d" " -f4
|
|
||||||
}
|
|
||||||
|
|
||||||
get_used_mem() {
|
|
||||||
free --mebi -t | grep 'Total' | tr -s ' ' | cut -d" " -f3
|
|
||||||
}
|
|
||||||
|
|
||||||
get_de_wm() {
|
|
||||||
if ps -e | grep "plasmashell" &> /dev/null ; then
|
|
||||||
echo "KDE Plasma $(plasmashell --version | awk '{print $2}')"
|
|
||||||
elif ps -e | grep "gnome-session" &> /dev/null ; then
|
|
||||||
echo "Gnome $(gnome-shell --version | awk '{print $3}')"
|
|
||||||
elif ps -e | grep "xfce4-session" &> /dev/null ; then
|
|
||||||
echo "XFCE $(xfce4-session --version | grep xfce4-session | awk '{print $2}')"
|
|
||||||
elif ps -e | grep "cinnamon" &> /dev/null ; then
|
|
||||||
echo "Cinnamon $(cinnamon --version | awk '{print $2}')"
|
|
||||||
elif ps -e | grep "mate-panel" &> /dev/null ; then
|
|
||||||
echo "Mate $(mate-about --version | awk '{print $4}')"
|
|
||||||
elif ps -e | grep "lxsession" &> /dev/null ; then
|
|
||||||
echo "LXDE"
|
|
||||||
elif ps -e | grep "sway" &> /dev/null ; then
|
|
||||||
echo "Sway $(sway --version | awk '{print $2}')"
|
|
||||||
elif ps -e | grep "icewm-session" &> /dev/null ; then
|
|
||||||
echo "IceWM $(icewm --version | awk '{print $2}' | sed 's/,//g')"
|
|
||||||
elif [ ! -z $DESKTOP_SESSION ]; then
|
|
||||||
echo "$DESKTOP_SESSION"
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
get_screen_resolution() {
|
|
||||||
if xhost >& /dev/null && command_exists xdpyinfo; then
|
|
||||||
xdpyinfo | grep dimensions | tr -s ' ' | cut -d " " -f3
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
get_packages() {
|
get_packages() {
|
||||||
ARRAY=()
|
ARRAY=()
|
||||||
if command_exists dpkg; then
|
if command_exists dpkg; then
|
||||||
@@ -91,11 +20,14 @@ get_packages() {
|
|||||||
if command_exists rpm; then
|
if command_exists rpm; then
|
||||||
ARRAY+=("$(rpm -qa | wc -l) (rpm)")
|
ARRAY+=("$(rpm -qa | wc -l) (rpm)")
|
||||||
fi
|
fi
|
||||||
|
if command_exists xbps-query; then
|
||||||
|
ARRAY+=("$(xbps-query -l | wc -l) (xbps)")
|
||||||
|
fi
|
||||||
if command_exists bpm; then
|
if command_exists bpm; then
|
||||||
ARRAY+=("$(bpm list -n) (bpm)")
|
ARRAY+=("$(bpm list -n) (bpm)")
|
||||||
fi
|
fi
|
||||||
if command_exists emerge; then
|
if command_exists emerge; then
|
||||||
ARRAY+=("$(ls -l /var/db/pkg/ | wc -l) (emerge)")
|
ARRAY+=("$(ls -l /var/db/pkg/* | wc -l) (emerge)")
|
||||||
fi
|
fi
|
||||||
if command_exists flatpak; then
|
if command_exists flatpak; then
|
||||||
ARRAY+=("$(flatpak list | wc -l) (flatpak)")
|
ARRAY+=("$(flatpak list | wc -l) (flatpak)")
|
||||||
|
|||||||
@@ -2,4 +2,19 @@ module stormfetch
|
|||||||
|
|
||||||
go 1.22
|
go 1.22
|
||||||
|
|
||||||
require gopkg.in/yaml.v3 v3.0.1 // indirect
|
require (
|
||||||
|
github.com/BurntSushi/xgb v0.0.0-20210121224620-deaf085860bc
|
||||||
|
github.com/jackmordaunt/ghw v1.0.4
|
||||||
|
github.com/mitchellh/go-ps v1.0.0
|
||||||
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
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
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,3 +1,28 @@
|
|||||||
|
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-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=
|
||||||
|
github.com/jackmordaunt/ghw v1.0.4/go.mod h1:4dReYvJ36CoAzIxlEx8du25Qi/YqKYvEGE9QJoRXiK8=
|
||||||
|
github.com/jackmordaunt/pcidb v1.0.1 h1:uLLZa6kD5P39r2cwMyJJkxmuHfH9Wq19gYQEbYcB0Z4=
|
||||||
|
github.com/jackmordaunt/pcidb v1.0.1/go.mod h1:OMmhrZOZVu2hYXhBDZXddypxwKR/dp4DbIgzCkQDxdQ=
|
||||||
|
github.com/jackmordaunt/wmi v1.2.4 h1:/XyuMiKby0qXNQp1j0uU0JqTWLM0QGOVok1Hf5Yagtg=
|
||||||
|
github.com/jackmordaunt/wmi v1.2.4/go.mod h1:K/+FH4467Vk2fJXhYQTZzhctkCMMR7PwHqKbnizFySo=
|
||||||
|
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||||
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
|
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=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
yaml "gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -21,24 +22,26 @@ var config = StormfetchConfig{
|
|||||||
AnsiiColors: make([]int, 0),
|
AnsiiColors: make([]int, 0),
|
||||||
ForceConfigAnsii: false,
|
ForceConfigAnsii: false,
|
||||||
DependencyWarning: true,
|
DependencyWarning: true,
|
||||||
|
ShowFSType: false,
|
||||||
|
HiddenGPUS: make([]int, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
type StormfetchConfig struct {
|
type StormfetchConfig struct {
|
||||||
Ascii string `yaml:"distro_ascii"`
|
Ascii string `yaml:"distro_ascii"`
|
||||||
|
DistroName string `yaml:"distro_name"`
|
||||||
FetchScript string `yaml:"fetch_script"`
|
FetchScript string `yaml:"fetch_script"`
|
||||||
AnsiiColors []int `yaml:"ansii_colors"`
|
AnsiiColors []int `yaml:"ansii_colors"`
|
||||||
ForceConfigAnsii bool `yaml:"force_config_ansii"`
|
ForceConfigAnsii bool `yaml:"force_config_ansii"`
|
||||||
DependencyWarning bool `yaml:"dependency_warning"`
|
DependencyWarning bool `yaml:"dependency_warning"`
|
||||||
}
|
ShowFSType bool `yaml:"show_fs_type"`
|
||||||
|
HiddenGPUS []int `yaml:"hidden_gpus"`
|
||||||
type DistroInfo struct {
|
|
||||||
ID string
|
|
||||||
LongName string
|
|
||||||
ShortName string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
readConfig()
|
readConfig()
|
||||||
|
readFlags()
|
||||||
|
checkDependencies()
|
||||||
|
runStormfetch()
|
||||||
}
|
}
|
||||||
|
|
||||||
func readConfig() {
|
func readConfig() {
|
||||||
@@ -78,9 +81,18 @@ func readConfig() {
|
|||||||
} else {
|
} else {
|
||||||
log.Fatalf("Fetch script file not found: %s", err.Error())
|
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
|
// Show Dependency warning if enabled
|
||||||
if config.DependencyWarning {
|
if config.DependencyWarning {
|
||||||
dependencies := []string{"lshw", "xhost", "xdpyinfo"}
|
var dependencies []string
|
||||||
var missing []string
|
var missing []string
|
||||||
for _, depend := range dependencies {
|
for _, depend := range dependencies {
|
||||||
if _, err := os.Stat(path.Join("/usr/bin/", depend)); err != nil {
|
if _, err := os.Stat(path.Join("/usr/bin/", depend)); err != nil {
|
||||||
@@ -95,6 +107,68 @@ func readConfig() {
|
|||||||
fmt.Println("You can disable this warning through your stormfetch config")
|
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
|
// Fetch ascii art and apply colors
|
||||||
colorMap := make(map[string]string)
|
colorMap := make(map[string]string)
|
||||||
colorMap["C0"] = "\033[0m"
|
colorMap["C0"] = "\033[0m"
|
||||||
@@ -108,9 +182,9 @@ func readConfig() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
setColorMap()
|
setColorMap()
|
||||||
ascii := ""
|
ascii := getDistroAsciiArt()
|
||||||
if strings.HasPrefix(getDistroAsciiArt(), "#/") {
|
if strings.HasPrefix(ascii, "#/") {
|
||||||
firstLine := strings.Split(getDistroAsciiArt(), "\n")[0]
|
firstLine := strings.Split(ascii, "\n")[0]
|
||||||
if !config.ForceConfigAnsii {
|
if !config.ForceConfigAnsii {
|
||||||
ansiiColors := strings.Split(strings.TrimPrefix(firstLine, "#/"), ";")
|
ansiiColors := strings.Split(strings.TrimPrefix(firstLine, "#/"), ";")
|
||||||
for i, color := range ansiiColors {
|
for i, color := range ansiiColors {
|
||||||
@@ -126,27 +200,26 @@ func readConfig() {
|
|||||||
}
|
}
|
||||||
setColorMap()
|
setColorMap()
|
||||||
}
|
}
|
||||||
ascii = os.Expand(getDistroAsciiArt(), func(s string) string {
|
ascii = os.Expand(ascii, func(s string) string {
|
||||||
return colorMap[s]
|
return colorMap[s]
|
||||||
})
|
})
|
||||||
ascii = strings.TrimPrefix(ascii, firstLine+"\n")
|
ascii = strings.TrimPrefix(ascii, firstLine+"\n")
|
||||||
} else {
|
} else {
|
||||||
ascii = os.Expand(getDistroAsciiArt(), func(s string) string {
|
ascii = os.Expand(ascii, func(s string) string {
|
||||||
return colorMap[s]
|
return colorMap[s]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
asciiSplit := strings.Split(ascii, "\n")
|
asciiSplit := strings.Split(ascii, "\n")
|
||||||
asciiNoColor := stripAnsii(ascii)
|
asciiNoColor := StripAnsii(ascii)
|
||||||
//Execute fetch script
|
//Execute fetch script
|
||||||
cmd := exec.Command("/bin/bash", fetchScriptPath)
|
cmd := exec.Command("/bin/bash", fetchScriptPath)
|
||||||
cmd.Dir = path.Dir(fetchScriptPath)
|
cmd.Dir = path.Dir(fetchScriptPath)
|
||||||
cmd.Env = os.Environ()
|
cmd.Env = os.Environ()
|
||||||
|
cmd.Env = append(cmd.Env, SetupFetchEnv()...)
|
||||||
cmd.Env = append(cmd.Env, "C0=\033[0m")
|
cmd.Env = append(cmd.Env, "C0=\033[0m")
|
||||||
for key, value := range colorMap {
|
for key, value := range colorMap {
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", key, value))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", key, value))
|
||||||
}
|
}
|
||||||
cmd.Env = append(cmd.Env, "DISTRO_LONG_NAME="+getDistroInfo().LongName)
|
|
||||||
cmd.Env = append(cmd.Env, "DISTRO_SHORT_NAME="+getDistroInfo().ShortName)
|
|
||||||
out, err := cmd.Output()
|
out, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@@ -159,137 +232,37 @@ func readConfig() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
final := ""
|
final := ""
|
||||||
for lineIndex, line := range asciiSplit {
|
y := len(asciiSplit)
|
||||||
lineVisibleLength := len(strings.Split(asciiNoColor, "\n")[lineIndex])
|
if len(asciiSplit) < len(strings.Split(string(out), "\n")) {
|
||||||
lastAsciiColor := ""
|
y = len(strings.Split(string(out), "\n"))
|
||||||
if lineIndex != 0 {
|
}
|
||||||
r := regexp.MustCompile("\033[38;5;[0-9]+m")
|
for lineIndex := 0; lineIndex < y; lineIndex++ {
|
||||||
matches := r.FindAllString(asciiSplit[lineIndex-1], -1)
|
line := ""
|
||||||
if len(matches) != 0 {
|
for i := 0; i < maxWidth+5; i++ {
|
||||||
lastAsciiColor = r.FindAllString(asciiSplit[lineIndex-1], -1)[len(matches)-1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for i := lineVisibleLength; i < maxWidth+5; i++ {
|
|
||||||
line = line + " "
|
line = line + " "
|
||||||
}
|
}
|
||||||
asciiSplit[lineIndex] = lastAsciiColor + 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)
|
||||||
|
if len(matches) != 0 {
|
||||||
|
lastAsciiColor = r.FindAllString(asciiSplit[lineIndex-1], -1)[len(matches)-1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i := lineVisibleLength; i < maxWidth+5; i++ {
|
||||||
|
line = line + " "
|
||||||
|
}
|
||||||
|
asciiSplit[lineIndex] = lastAsciiColor + line
|
||||||
|
}
|
||||||
str := string(out)
|
str := string(out)
|
||||||
if lineIndex < len(strings.Split(str, "\n")) {
|
if lineIndex < len(strings.Split(str, "\n")) {
|
||||||
line = line + colorMap["C0"] + strings.Split(str, "\n")[lineIndex]
|
line = line + colorMap["C0"] + strings.Split(str, "\n")[lineIndex]
|
||||||
}
|
}
|
||||||
final += lastAsciiColor + line + "\n"
|
final += lastAsciiColor + line + "\n"
|
||||||
}
|
}
|
||||||
fmt.Println(final)
|
final = strings.TrimRight(final, "\n\t ")
|
||||||
}
|
fmt.Println(final + "\033[0m")
|
||||||
|
|
||||||
func readKeyValueFile(filepath string) (map[string]string, error) {
|
|
||||||
ret := make(map[string]string)
|
|
||||||
if _, err := os.Stat(filepath); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
bytes, err := os.ReadFile(filepath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
str := string(bytes)
|
|
||||||
lines := strings.Split(str, "\n")
|
|
||||||
for _, line := range lines {
|
|
||||||
if len(strings.Split(line, "=")) >= 2 {
|
|
||||||
key := strings.SplitN(line, "=", 2)[0]
|
|
||||||
value := strings.SplitN(line, "=", 2)[1]
|
|
||||||
if strings.HasPrefix(value, "\"") && strings.HasSuffix(value, "\"") {
|
|
||||||
value = value[1 : len(value)-1]
|
|
||||||
}
|
|
||||||
ret[key] = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getDistroInfo() DistroInfo {
|
|
||||||
distroID := ""
|
|
||||||
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",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return DistroInfo{
|
|
||||||
ID: "unknown",
|
|
||||||
LongName: "Unknown",
|
|
||||||
ShortName: "Unknown",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func getDistroAsciiArt() string {
|
|
||||||
defaultAscii :=
|
|
||||||
` .--.
|
|
||||||
|o_o |
|
|
||||||
|:_/ |
|
|
||||||
// \ \
|
|
||||||
(| | )
|
|
||||||
/'\_ _/'\
|
|
||||||
\___)=(___/ `
|
|
||||||
var id string
|
|
||||||
if config.Ascii == "auto" {
|
|
||||||
id = getDistroInfo().ID
|
|
||||||
} else {
|
|
||||||
id = config.Ascii
|
|
||||||
}
|
|
||||||
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 != nil {
|
|
||||||
return defaultAscii
|
|
||||||
}
|
|
||||||
return string(bytes)
|
|
||||||
} else {
|
|
||||||
return defaultAscii
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if _, err := os.Stat(path.Join(userConfDir, "stormfetch/ascii/", id)); err == nil {
|
|
||||||
bytes, err := os.ReadFile(path.Join(userConfDir, "stormfetch/ascii/", id))
|
|
||||||
if err != nil {
|
|
||||||
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))
|
|
||||||
if err != nil {
|
|
||||||
return defaultAscii
|
|
||||||
}
|
|
||||||
return string(bytes)
|
|
||||||
} else {
|
|
||||||
return defaultAscii
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func stripAnsii(str string) string {
|
|
||||||
const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
|
|
||||||
var re = regexp.MustCompile(ansi)
|
|
||||||
return re.ReplaceAllString(str, "")
|
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 163 KiB |
@@ -0,0 +1,444 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"github.com/BurntSushi/xgb"
|
||||||
|
"github.com/BurntSushi/xgb/xinerama"
|
||||||
|
"github.com/jackmordaunt/ghw"
|
||||||
|
"github.com/mitchellh/go-ps"
|
||||||
|
"github.com/moby/sys/mountinfo"
|
||||||
|
"log"
|
||||||
|
"math"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"slices"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DistroInfo struct {
|
||||||
|
ID string
|
||||||
|
LongName string
|
||||||
|
ShortName string
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDistroInfo() DistroInfo {
|
||||||
|
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 info
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if id, ok := releaseMap["ID"]; ok {
|
||||||
|
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 info
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDistroAsciiArt() string {
|
||||||
|
defaultAscii :=
|
||||||
|
` .--.
|
||||||
|
|o_o |
|
||||||
|
|:_/ |
|
||||||
|
// \ \
|
||||||
|
(| | )
|
||||||
|
/'\_ _/'\
|
||||||
|
\___)=(___/ `
|
||||||
|
var id string
|
||||||
|
if config.Ascii == "auto" {
|
||||||
|
id = getDistroInfo().ID
|
||||||
|
} else {
|
||||||
|
id = config.Ascii
|
||||||
|
}
|
||||||
|
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 != nil {
|
||||||
|
return defaultAscii
|
||||||
|
}
|
||||||
|
return string(bytes)
|
||||||
|
} else {
|
||||||
|
return defaultAscii
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(path.Join(userConfDir, "stormfetch/ascii/", id)); err == nil {
|
||||||
|
bytes, err := os.ReadFile(path.Join(userConfDir, "stormfetch/ascii/", id))
|
||||||
|
if err != nil {
|
||||||
|
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))
|
||||||
|
if err != nil {
|
||||||
|
return defaultAscii
|
||||||
|
}
|
||||||
|
return strings.TrimRight(string(bytes), "\n\t ")
|
||||||
|
} else {
|
||||||
|
return defaultAscii
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCPUName() string {
|
||||||
|
cpu, err := ghw.CPU()
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if len(cpu.Processors) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return cpu.Processors[0].Model
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCPUThreads() int {
|
||||||
|
cpu, err := ghw.CPU()
|
||||||
|
if err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return int(cpu.TotalThreads)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGPUNames() []string {
|
||||||
|
var ret []string
|
||||||
|
null, _ := os.Open(os.DevNull)
|
||||||
|
serr := os.Stderr
|
||||||
|
os.Stderr = null
|
||||||
|
gpu, err := ghw.GPU()
|
||||||
|
defer null.Close()
|
||||||
|
os.Stderr = serr
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
for i, graphics := range gpu.GraphicsCards {
|
||||||
|
if slices.Contains(config.HiddenGPUS, i+1) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if graphics.DeviceInfo != nil {
|
||||||
|
ret = append(ret, graphics.DeviceInfo.Product.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
type Memory struct {
|
||||||
|
MemTotal int
|
||||||
|
MemFree int
|
||||||
|
MemAvailable int
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMemoryInfo() *Memory {
|
||||||
|
toInt := func(raw string) int {
|
||||||
|
if raw == "" {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
res, err := strconv.Atoi(raw)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
parseLine := func(raw string) (key string, value int) {
|
||||||
|
text := strings.ReplaceAll(raw[:len(raw)-2], " ", "")
|
||||||
|
keyValue := strings.Split(text, ":")
|
||||||
|
return keyValue[0], toInt(keyValue[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat("/proc/meminfo"); err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
file, err := os.Open("/proc/meminfo")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
bufio.NewScanner(file)
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
res := Memory{}
|
||||||
|
for scanner.Scan() {
|
||||||
|
key, value := parseLine(scanner.Text())
|
||||||
|
switch key {
|
||||||
|
case "MemTotal":
|
||||||
|
res.MemTotal = value / 1024
|
||||||
|
case "MemFree":
|
||||||
|
res.MemFree = value / 1024
|
||||||
|
case "MemAvailable":
|
||||||
|
res.MemAvailable = value / 1024
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &res
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetShell() 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))
|
||||||
|
}
|
||||||
|
file, err := os.ReadFile("/etc/passwd")
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
str := string(file)
|
||||||
|
shell := ""
|
||||||
|
|
||||||
|
for _, line := range strings.Split(str, "\n") {
|
||||||
|
if strings.TrimSpace(line) == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
userInfo := strings.Split(line, ":")
|
||||||
|
if userInfo[2] == strconv.Itoa(os.Getuid()) {
|
||||||
|
shell = userInfo[6]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
shellName := filepath.Base(shell)
|
||||||
|
switch shellName {
|
||||||
|
case "dash":
|
||||||
|
return "Dash"
|
||||||
|
case "bash":
|
||||||
|
return "Bash " + runCommand("echo $BASH_VERSION")
|
||||||
|
case "zsh":
|
||||||
|
return "Zsh " + runCommand("$SHELL --version | awk '{print $2}'")
|
||||||
|
case "fish":
|
||||||
|
return "Fish " + runCommand("$SHELL --version | awk '{print $3}'")
|
||||||
|
default:
|
||||||
|
return "Unknown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDEWM() string {
|
||||||
|
processes, err := ps.Processes()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
var executables []string
|
||||||
|
for _, process := range processes {
|
||||||
|
executables = append(executables, process.Executable())
|
||||||
|
}
|
||||||
|
|
||||||
|
processExists := func(process string) bool {
|
||||||
|
return slices.Contains(executables, process)
|
||||||
|
}
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
if processExists("plasmashell") {
|
||||||
|
return "KDE Plasma " + runCommand("plasmashell --version | awk '{print $2}'")
|
||||||
|
} 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}'")
|
||||||
|
} 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("sway") {
|
||||||
|
return "Sway " + runCommand("sway --version | awk '{print $3}'")
|
||||||
|
} else if processExists("bspwm") {
|
||||||
|
return "Bspwm " + runCommand("bspwm -v")
|
||||||
|
} else if processExists("icewm-session") {
|
||||||
|
return "IceWM " + runCommand("icewm --version | awk '{print $2}'")
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDisplayProtocol() string {
|
||||||
|
protocol := os.Getenv("XDG_SESSION_TYPE")
|
||||||
|
if protocol == "x11" {
|
||||||
|
return "X11"
|
||||||
|
} else if protocol == "wayland" {
|
||||||
|
return "Wayland"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMonitorResolution() []string {
|
||||||
|
var monitors []string
|
||||||
|
if GetDisplayProtocol() == "X11" {
|
||||||
|
conn, err := xgb.NewConn()
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
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)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return monitors
|
||||||
|
}
|
||||||
|
|
||||||
|
type partition struct {
|
||||||
|
Device string
|
||||||
|
MountPoint string
|
||||||
|
Label string
|
||||||
|
Type string
|
||||||
|
TotalSize uint64
|
||||||
|
UsedSize uint64
|
||||||
|
FreeSize uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
buf := new(syscall.Statfs_t)
|
||||||
|
err = syscall.Statfs(p.MountPoint, buf)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
totalBlocks := buf.Blocks
|
||||||
|
freeBlocks := buf.Bfree
|
||||||
|
usedBlocks := totalBlocks - freeBlocks
|
||||||
|
blockSize := uint64(buf.Bsize)
|
||||||
|
|
||||||
|
p.TotalSize = totalBlocks * blockSize
|
||||||
|
p.FreeSize = freeBlocks * blockSize
|
||||||
|
p.UsedSize = usedBlocks * blockSize
|
||||||
|
|
||||||
|
partitions = append(partitions, p)
|
||||||
|
}
|
||||||
|
return partitions
|
||||||
|
}
|
||||||
|
|
||||||
|
func FormatBytes(bytes uint64) string {
|
||||||
|
var suffixes [6]string
|
||||||
|
suffixes[0] = "B"
|
||||||
|
suffixes[1] = "KiB"
|
||||||
|
suffixes[2] = "MiB"
|
||||||
|
suffixes[3] = "GiB"
|
||||||
|
suffixes[4] = "TiB"
|
||||||
|
suffixes[5] = "PiB"
|
||||||
|
|
||||||
|
bf := float64(bytes)
|
||||||
|
for _, unit := range suffixes {
|
||||||
|
if math.Abs(bf) < 1024.0 {
|
||||||
|
return fmt.Sprintf("%3.1f %s", bf, unit)
|
||||||
|
}
|
||||||
|
bf /= 1024.0
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%.1fYiB", bf)
|
||||||
|
}
|
||||||
|
|
||||||
|
func StripAnsii(str string) string {
|
||||||
|
const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
|
||||||
|
var re = regexp.MustCompile(ansi)
|
||||||
|
return re.ReplaceAllString(str, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadKeyValueFile(filepath string) (map[string]string, error) {
|
||||||
|
ret := make(map[string]string)
|
||||||
|
if _, err := os.Stat(filepath); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
bytes, err := os.ReadFile(filepath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
str := string(bytes)
|
||||||
|
lines := strings.Split(str, "\n")
|
||||||
|
for _, line := range lines {
|
||||||
|
if len(strings.Split(line, "=")) >= 2 {
|
||||||
|
key := strings.SplitN(line, "=", 2)[0]
|
||||||
|
value := strings.SplitN(line, "=", 2)[1]
|
||||||
|
if strings.HasPrefix(value, "\"") && strings.HasSuffix(value, "\"") {
|
||||||
|
value = value[1 : len(value)-1]
|
||||||
|
}
|
||||||
|
ret[key] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user