Skip to content

Commit

Permalink
feat: proper FreeBSD & OpenBSD support, OS fonticons
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatOneCalculator committed Dec 19, 2023
1 parent ed58b29 commit 142044d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 20 deletions.
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

![Screenshot](https://bunnyt1c.s3.us-east-005.backblazeb2.com/calckeysoc/a987b0b2-9cf4-4147-ac01-1753afcd62a3.png)

### Dependencies:
### Dependencies

- [Any nerdfonts font](https://www.nerdfonts.com/font-downloads)
- [Any Nerdfonts font](https://www.nerdfonts.com/font-downloads)
- Anything but Windows

### To install and run:
### To install and run

#### [Arch Linux](https://aur.archlinux.org/packages/nerdfetch/):

Expand All @@ -17,16 +17,16 @@ yay -S nerdfetch
nerdfetch
```

Make sure to replace `yay` with whatever AUR helper you use.
Make sure to replace `yay` with whatever AUR helper you use.

#### [yiffOS](https://packages.yiffos.gay/nerdfetch):
#### [yiffOS](https://packages.yiffos.gay/nerdfetch)

```sh
bulge install nerdfetch
nerdfetch
```

#### Manually:
#### Manually

Copy-paste this into your terminal:

Expand All @@ -36,7 +36,7 @@ sudo chmod +x /usr/bin/nerdfetch
nerdfetch
```

#### Android with Termux:
#### Android with Termux

Copy-paste this into Termux:

Expand All @@ -46,20 +46,23 @@ chmod a+x /data/data/com.termux/files/usr/bin/nerdfetch
nerdfetch
```

#### Run once:
#### Run once

Note that this will ***not*** install the program.

```sh
curl -fsSL https://codeberg.org/thatonecalculator/NerdFetch/raw/branch/master/nerdfetch | sh
```

### Features:
### Features

- Strong cross-OS compatability
- Not bloated
- Portable
- POSIX

### OSes supported:
### OSes supported

- Debian based Linux
- Ubuntu based Linux
- Arch based Linux
Expand All @@ -76,9 +79,10 @@ curl -fsSL https://codeberg.org/thatonecalculator/NerdFetch/raw/branch/master/ne
- yiffOS Linux
- Slackware Linux\*
- macOS 10.x + 11.x
- FreeBSD
- OpenBSD
- Android

### Known issues:
### Known issue(s)

- \*In Slackware Linux, make sure to have `/usr/sbin` in PATH
- In FreeBSD, no hostname and no uptime
- In OpenBSD, no hostname and no uptime, and no package count
64 changes: 57 additions & 7 deletions nerdfetch
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,55 @@
## OS/ENVIRONMENT INFO DETECTION

ostype="$(uname)"
osi=""

linuxtype=none
distrotype=none
if command -v getprop > /dev/null; then
linuxtype=android
distrotype=android
fi
kernel="$(echo $(uname -r) | cut -d'-' -f1-1)"
case $ostype in
*"Linux"*)
if [ $linuxtype = android ]; then
if [ $distrotype = android ]; then
host="$(hostname)"
USER=${USER:-$(id -un || printf %s "${HOME/*\/}")}
os="Android $(getprop ro.build.version.release)"
osi="󰀲"
else
host="$(cat /proc/sys/kernel/hostname)"
. /etc/os-release
if [ -f /bedrock/etc/bedrock-release ]; then
os="$(brl version)"
else
os="${PRETTY_NAME}"
case $(echo $ID | sed 's/ .*//') in
debian) osi="";;
arch) osi="󰣇";;
endeavouros) osi="";;
fedora) osi="";;
gentoo) osi="";;
rhel) osi="";;
slackware) osi="";;
void) osi="";;
alpine) osi="";;
nixos) osi="󱄅";;
artix) osi="";;
exherbo) osi="󰆚";;
mageia) osi="";;
manjaro) osi="";;
opensuse) osi="";;
solus) osi="";;
ubuntu) osi="";;
mint) osi="󰣭";;
trisquel) osi="";;
puppy) osi="";;
coreos) osi="";;
mx) osi="";;
vanilla) osi="";;
pop_os) osi="";;
raspbian) osi="";;
*) osi="";;
esac
fi
fi
shell=${SHELL##*/};;
Expand All @@ -34,7 +64,18 @@ case $ostype in
break;;
esac
done < /System/Library/CoreServices/SystemVersion.plist
os="macOS ${mac_version}";;
os="macOS ${mac_version}"
osi="";;
*"FreeBSD"*)
host="$(hostname)"
distrotype=bsd
os="FreeBSD $(freebsd-version | sed 's/-.*//')"
osi="";;
*"OpenBSD"*)
host="$(hostname)"
distrotype=bsd
os="OpenBSD $(uname -r)"
osi="";;
*)
os="Idk"
host="host"
Expand Down Expand Up @@ -68,15 +109,20 @@ case $manager in
eopkg) packages="$(eopkg li | wc -l)";;
/usr/sbin/slackpkg) packages="$(ls /var/log/packages | wc -l)";;
bulge) packages="$(bulge list | wc -l)";;
pkg_info) packages="$(pkg_info -A | wc -l)";;
*)
packages="$(ls /usr/bin | wc -l)"
manager="bin";;
esac

manager=$(echo $manager | sed "s/-query//; s/\/usr\/.*\///")

## UPTIME DETECTION

if [ $linuxtype = android ]; then
if [ $distrotype = android ]; then
uptime="$(echo $(uptime -p) | cut -c 4-)"
elif [ $distrotype = bsd ]; then
uptime="$(uptime | sed -e 's/.* up //; s/, [0-9]* user.*//')"
else
case $ostype in
*"Linux"*)
Expand Down Expand Up @@ -135,11 +181,15 @@ case $ostype in
EOF

mem_used=$((mem_used * 4 / 1024));;
*"BSD"*)
mem_full=$(($(sysctl -n hw.physmem) / 1024 / 1024))
mem_free=$(($(sysctl -n vm.stats.vm.v_free_count) * $(sysctl -n vm.stats.vm.v_page_size) / 1024 / 1024))
mem_used=$((mem_full - mem_free));;
*)
mem_full="idk"
mem_used="idk"
esac
memstat="${mem_used}/${mem_full} MB"
memstat="${mem_used}/${mem_full} MiB"
if which expr > /dev/null 2>&1; then
mempercent="($(expr $(expr ${mem_used} \* 100 / ${mem_full} ))%)"
fi
Expand Down Expand Up @@ -173,7 +223,7 @@ c2="${reset}${yellow}" # third color
cat <<EOF
${c0} ___ ${nc}${USER}${red}@${reset}${hn}${host}${reset}
${c0} (${c1}.. ${c0}\ ${lc} ${ic}${os}${reset}
${c0} (${c1}.. ${c0}\ ${lc}${osi} ${ic}${os}${reset}
${c0} (${c2}<> ${c0}| ${lc}${ic}${kernel}${reset}
${c0} /${c1}/ \\ ${c0}\\ ${lc}󰍛 ${ic}${RAM}${memstat} ${mempercent}
${c0} ( ${c1}| | ${c0}/| ${lc}󰏔 ${ic}${packages} (${manager})${reset}
Expand Down

0 comments on commit 142044d

Please sign in to comment.