Skip to content

Commit

Permalink
feat: ✨ Allow switching between font variants
Browse files Browse the repository at this point in the history
Closes #51
  • Loading branch information
ThatOneCalculator committed Jan 22, 2024
1 parent 1913f02 commit 046f787
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 82 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
A POSIX \*nix (Linux, macOS, Android, BSD, etc) fetch script using Nerdfonts

![Screenshot](https://github.com/ThatOneCalculator/NerdFetch/assets/44733677/0bc8872f-70b0-485f-a5f5-cc45bb2dac79)
![Phosphor](https://github.com/ThatOneCalculator/NerdFetch/assets/44733677/fa620df5-af93-4145-adbf-d2c0be279851)
![Cozette](https://github.com/ThatOneCalculator/NerdFetch/assets/44733677/f7999fb1-53c3-4427-91cc-5aa3e42aeb41)

### Dependencies

- [Any Nerdfonts font](https://www.nerdfonts.com/font-downloads)
- [Any Nerdfonts font](https://www.nerdfonts.com/font-downloads), [Cozette](https://github.com/slavfox/Cozette), or [Phosphor](https://github.com/phosphor-icons/homepage/releases/tag/v2.0.0)
- POSIX-compliant shell
- `which`
- Anything but Windows
Expand All @@ -14,6 +16,12 @@

[![Packaging status](https://repology.org/badge/vertical-allrepos/nerdfetch.svg)](https://repology.org/project/nerdfetch/versions)

#### How to switch fonts

- Nerdfonts is used by default
- Use `-c` for Cozette
- Use `-p` for Phosphor

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

```sh
Expand Down
230 changes: 149 additions & 81 deletions nerdfetch
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,38 @@
## OS/ENVIRONMENT INFO DETECTION

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

version=8.0.0
font=nerd
distrotype=none
osi=""
ki=""
ri="󰍛"
pi="󰏔"
ui="󰅶"
ci=""

case $1 in
"-p")
font=phosphor;
osi="";
ki=""
ri=""
pi=""
ui=""
ci="";;
"-c")
font=cozette
ki=""
ri=""
pi=""
ui=""
ci="";;
"-v") echo "NerdFetch $version"; exit;;
"-h") echo "-p: Phosphor font
-c: Cozette font
-v: Version"; exit;;
esac

if command -v getprop 1> /dev/null; then
distrotype=android
Expand All @@ -17,47 +46,70 @@ case $ostype in
host="$(hostname)"
USER=${USER:-$(id -un || printf %s "${HOME/*\/}")}
os="Android $(getprop ro.build.version.release)"
osi="󰀲"
if [ $font = phosphor ]; then
osi=""
else
osi="󰀲"
fi
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="";;
deepin) osi="";;
almalinux) osi="";;
garuda) osi="";;
centos) osi="";;
rocky) osi="";;
*) osi="";;
esac
if [ $font = nerd ]; then
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="";;
deepin) osi="";;
almalinux) osi="";;
garuda) osi="";;
centos) osi="";;
rocky) osi="";;
esac
elif [ $font = cozette ]; then
case $(echo $ID | sed 's/ .*//') in
debian) osi="";;
arch) osi="";;
fedora) osi="";;
gentoo) osi="";;
slackware) osi="";;
void) osi="";;
alpine) osi="";;
nixos) osi="";;
mageia) osi="";;
manjaro) osi="";;
opensuse) osi="";;
ubuntu) osi="";;
mint) osi="";;
coreos) osi="";;
centos) osi="";;
esac
fi
fi
fi
shell=$(basename "$SHELL");;
Expand All @@ -66,22 +118,38 @@ case $ostype in
mac_product="$(/usr/libexec/PlistBuddy -c "Print:ProductName" /System/Library/CoreServices/SystemVersion.plist)"
mac_version="$(/usr/libexec/PlistBuddy -c "Print:ProductVersion" /System/Library/CoreServices/SystemVersion.plist)"
os="${mac_product} ${mac_version}"
osi="";;
case $font in
nerd) osi="";;
phosphor) osi="";;
cozette) osi="";;
esac;;
*"FreeBSD"*)
host="$(hostname)"
distrotype=bsd
os="FreeBSD $(freebsd-version | sed 's/-.*//')"
osi="";;
case $font in
nerd) osi="";;
phosphor) osi="";;
cozette) osi="";;
esac;;
*"OpenBSD"*)
host="$(hostname)"
distrotype=bsd
os="OpenBSD $(uname -r)"
osi="";;
case $font in
nerd) osi="";;
phosphor) osi="";;
cozette) osi="";;
esac;;
*"NetBSD"*)
host="$(hostname)"
distrotype=bsd
distrotype=netbsd
os="NetBSD $(uname -r)"
osi="󰉀";;
case $font in
nerd) osi="󰉀";;
phosphor) osi="";;
cozette) osi="";;
esac;;
*)
os="Unix-like"
host="host"
Expand All @@ -91,7 +159,7 @@ esac

MANAGER=$(which nix-env pkg yum zypper dnf rpm dpkg-query brew port pacman xbps-query emerge cave apk kiss pmm /usr/sbin/slackpkg bulge yay paru pacstall cpm pmm eopkg getprop 2>/dev/null)
manager=$(basename "$MANAGER")
if [ $osi = "󰉀" ]; then
if [ $distrotype = netbsd ]; then
manager="pkg_info-netbsd"
fi
case $manager in
Expand Down Expand Up @@ -140,43 +208,43 @@ manager=$(echo $manager | sed "s/-query//; s/\/usr\/.*\///")
## UPTIME DETECTION

if [ $distrotype = android ]; then
uptime="$(echo $(uptime -p) | cut -c 4-)"
elif [ $distrotype = bsd ]; then
uptime="$(echo $(uptime -p) | cut -c 4-)"
elif [ $distrotype = bsd ] || [ $distrotype = netbsd ]; then
uptime="$(uptime | sed -e 's/.* up //; s/, [0-9]* user.*//')"
else
case $ostype in
*"Linux"*)
IFS=. read -r s _ < /proc/uptime;;
*"NetBSD"*)
s=$(/sbin/sysctl -n kern.boottime)
s=${s#*=}
s=${s%,*}
s=$(($(date +%s) - s));;
*)
s=$(sysctl -n kern.boottime)
s=${s#*=}
s=${s%,*}
s=$(($(date +%s) - s));;
esac
d="$((s / 60 / 60 / 24))"
h="$((s / 60 / 60 % 24))"
m="$((s / 60 % 60))"
# Plurals
[ "$d" -gt 1 ] && dp=s
[ "$h" -gt 1 ] && hp=s
[ "$m" -gt 1 ] && mp=s
[ "$s" -gt 1 ] && sp=s
# Hide empty fields.
[ "$d" = 0 ] && d=
[ "$h" = 0 ] && h=
[ "$m" = 0 ] && m=
[ "$m" != "" ] && s=
# Make the output of uptime smaller.
[ "$d" ] && uptime="$d day$dp, "
[ "$h" ] && uptime="$uptime$h hour$hp, "
[ "$m" ] && uptime="$uptime$m min$mp"
[ "$s" ] && uptime="$uptime$s sec$sp"
uptime=${uptime%, }
case $ostype in
*"Linux"*)
IFS=. read -r s _ < /proc/uptime;;
*"NetBSD"*)
s=$(/sbin/sysctl -n kern.boottime)
s=${s#*=}
s=${s%,*}
s=$(($(date +%s) - s));;
*)
s=$(sysctl -n kern.boottime)
s=${s#*=}
s=${s%,*}
s=$(($(date +%s) - s));;
esac
d="$((s / 60 / 60 / 24))"
h="$((s / 60 / 60 % 24))"
m="$((s / 60 % 60))"
# Plurals
[ "$d" -gt 1 ] && dp=s
[ "$h" -gt 1 ] && hp=s
[ "$m" -gt 1 ] && mp=s
[ "$s" -gt 1 ] && sp=s
# Hide empty fields.
[ "$d" = 0 ] && d=
[ "$h" = 0 ] && h=
[ "$m" = 0 ] && m=
[ "$m" != "" ] && s=
# Make the output of uptime smaller.
[ "$d" ] && uptime="$d day$dp, "
[ "$h" ] && uptime="$uptime$h hour$hp, "
[ "$m" ] && uptime="$uptime$m min$mp"
[ "$s" ] && uptime="$uptime$s sec$sp"
uptime=${uptime%, }
fi

## RAM DETECTION
Expand Down Expand Up @@ -253,9 +321,9 @@ cat <<EOF
${c0} ___ ${nc}${USER}${red}@${reset}${hn}${host}${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}
${c2} _${c0}/\\ ${c1}__)${c0}/${c2}_${c0}) ${lc}󰅶 ${ic}${uptime}${reset}
${c2} \/${c0}-____${c2}\/${reset} ${lc} ${red}███${green}███${yellow}███${blue}███${magenta}███${cyan}███${reset}
${c0} (${c2}<> ${c0}| ${lc}${ki} ${ic}${kernel}${reset}
${c0} /${c1}/ \\ ${c0}\\ ${lc}${ri} ${ic}${RAM}${memstat} ${mempercent}
${c0} ( ${c1}| | ${c0}/| ${lc}${pi} ${ic}${packages} (${manager})${reset}
${c2} _${c0}/\\ ${c1}__)${c0}/${c2}_${c0}) ${lc}${ui} ${ic}${uptime}${reset}
${c2} \/${c0}-____${c2}\/${reset} ${lc}${ci} ${red}███${green}███${yellow}███${blue}███${magenta}███${cyan}███${reset}
EOF

0 comments on commit 046f787

Please sign in to comment.