This commit is contained in:
Dylan Araps 2016-11-05 11:46:08 +11:00
parent 30af9bc68f
commit f637bbfe7b
3 changed files with 589 additions and 39 deletions

148
neofetch
View file

@ -30,6 +30,7 @@ getos() {
*"BSD" | "DragonFly" | "Bitrig") os="BSD" ;;
"CYGWIN"*) os="Windows" ;;
"SunOS") os="Solaris" ;;
"Haiku") os="Haiku" ;;
*) printf "%s\n" "Unknown OS detected: $(uname)"; exit 1 ;;
esac
}
@ -247,6 +248,10 @@ getdistro() {
esac
distro="${distro/\(*}"
;;
"Haiku")
distro="$(uname -sv | awk '{print $1 " " $2}')"
;;
esac
# Get architecture
@ -297,52 +302,63 @@ getkernel() {
# Uptime {{{
getuptime() {
# Get uptime in seconds
# Since Haiku's uptime cannot be fetched in seconds, a case outside
# the usual case is needed
case "$os" in
"Linux" | "Windows")
seconds="$(< /proc/uptime)"
seconds="${seconds/.*}"
"Haiku")
uptime="$(uptime -u)"
uptime="${uptime/up }"
;;
*)
# Get uptime in seconds
case "$os" in
"Linux" | "Windows")
seconds="$(< /proc/uptime)"
seconds="${seconds/.*}"
;;
"Mac OS X" | "iPhone OS" | "BSD")
boot="$(sysctl -n kern.boottime)"
boot="${boot/'{ sec = '}"
boot="${boot/,*}"
"Mac OS X" | "iPhone OS" | "BSD")
boot="$(sysctl -n kern.boottime)"
boot="${boot/'{ sec = '}"
boot="${boot/,*}"
# Get current date in seconds
now="$(date +%s)"
seconds="$((now - boot))"
;;
# Get current date in seconds
now="$(date +%s)"
seconds="$((now - boot))"
;;
"Solaris")
seconds="$(kstat -p unix:0:system_misc:snaptime | awk '{print $2}')"
seconds="${seconds/.*}"
;;
"Solaris")
seconds="$(kstat -p unix:0:system_misc:snaptime | awk '{print $2}')"
seconds="${seconds/.*}"
;;
esac
days="$((seconds / 60 / 60 / 24)) days"
hours="$((seconds / 60 / 60 % 24)) hours"
minutes="$((seconds / 60 % 60)) minutes"
case "$days" in
"0 days") unset days ;;
"1 days") days="${days/s}" ;;
esac
case "$hours" in
"0 hours") unset hours ;;
"1 hours") hours="${hours/s}" ;;
esac
case "$minutes" in
"0 minutes") unset minutes ;;
"1 minutes") minutes="${minutes/s}" ;;
esac
uptime="${days:+$days, }${hours:+$hours, }${minutes}"
uptime="${uptime%', '}"
uptime="${uptime:-${seconds} seconds}"
;;
esac
days="$((seconds / 60 / 60 / 24)) days"
hours="$((seconds / 60 / 60 % 24)) hours"
minutes="$((seconds / 60 % 60)) minutes"
case "$days" in
"0 days") unset days ;;
"1 days") days="${days/s}" ;;
esac
case "$hours" in
"0 hours") unset hours ;;
"1 hours") hours="${hours/s}" ;;
esac
case "$minutes" in
"0 minutes") unset minutes ;;
"1 minutes") minutes="${minutes/s}" ;;
esac
uptime="${days:+$days, }${hours:+$hours, }${minutes}"
uptime="${uptime%', '}"
uptime="${uptime:-${seconds} seconds}"
# Make the output of uptime smaller.
case "$uptime_shorthand" in
"on")
@ -455,6 +471,10 @@ getpackages() {
[ -d "/cygdrive/c/ProgramData/chocolatey/lib" ] && \
packages="$((packages+=$(ls -1 /cygdrive/c/ProgramData/chocolatey/lib | wc -l)))"
;;
"Haiku")
packages="$(ls -1 /boot/system/package-links | wc -l)"
;;
esac
[ "$packages" == "0" ] && unset packages
@ -839,6 +859,24 @@ getcpu() {
cpu="$cpu @ ${speed}GHz"
;;
"Haiku")
cpu="$(sysinfo -cpu | awk -F '\\"' '/CPU #0/ {print $2}')"
cpu="${cpu/@*}"
speed="$(sysinfo -cpu | awk '/running at/ {print $NF; exit}')"
speed="${speed/MHz}"
speed="$((speed / 100))"
cores="$(sysinfo -cpu | grep -c 'CPU #')"
# Fix for speed under 1ghz
if [ -z ] "${speed:1}"; then
speed="0.${speed}"
else
speed="${speed:0:1}.${speed:1}"
fi
cpu="$cpu @ ${speed}GHz"
;;
esac
# Remove uneeded patterns from cpu output
@ -1019,6 +1057,10 @@ getgpu() {
gpu="$(wmic path Win32_VideoController get caption /value)"
gpu="${gpu/Caption'='}"
;;
"Haiku")
gpu="$(listdev | grep -A2 -e 'device Display controller' | awk -F':' '/device beef/ {print $2}')"
;;
esac
if [ "$gpu_brand" == "off" ]; then
@ -1079,6 +1121,12 @@ getmemory() {
memfree="$(($(sar -r 1 1 | tail -1 | awk 'BEGIN {FS=" "} {print $2}') / 1024))"
memused="$((memtotal - memfree))"
;;
"Haiku")
memtotal=$(($(sysinfo -mem | head -n1 | cut -d'/' -f3 | tr -d ' ' | tr -d ')') / 1024 / 1024))
memused="$(sysinfo -mem | awk -F '\\/|)' '{print $2; exit}')"
memused="$((${memused/max} / 1024 / 1024))"
;;
esac
memory="${memused}MB / ${memtotal}MB"
@ -1262,6 +1310,14 @@ getresolution() {
[ "$width" ] && \
resolution="${width}x${height}"
;;
"Haiku")
resolution="$(screenmode | awk -F ' |, ' '{printf $2 "x" $3 " @ " $6 $7}')"
case "$refresh_rate" in
"off") resolution="${resolution/ @*}" ;;
esac
;;
esac
resolution="${resolution%,*}"
@ -1714,6 +1770,11 @@ getlocalip() {
"Windows")
localip="$(ipconfig | awk -F ': ' '/IPv4 Address/ {printf $2}')"
;;
"Haiku")
localip="$(ifconfig | awk -F ': ' '/Bcast/ {print $2}')"
localip="${localip/', Bcast'}"
;;
esac
}
@ -1794,6 +1855,11 @@ getbirthday() {
birthday="$(ls -alct --full-time /var/sadm/system/logs/install_log | awk '{printf $6 " " $7}')"
date_cmd="$(date -d"$birthday" "$birthday_format")"
;;
"Haiku")
birthday="$(ls -alctd --full-time /boot | awk '{printf $6 " " $7}')"
date_cmd="$(date -d"$birthday" "$birthday_format")"
;;
esac
# Strip seconds from time output
@ -2555,6 +2621,10 @@ colors() {
setcolors 1 2 4 3
;;
"Haiku"*)
setcolors 2 0
;;
"Raspbian"*)
setcolors 2 1
;;