From 5e43cd756cfdac1d3805e5e34513ff5554b16540 Mon Sep 17 00:00:00 2001 From: Muhammad Herdiansyah Date: Sat, 8 Oct 2016 21:17:56 +0700 Subject: [PATCH 1/5] Added initial support for Haiku --- ascii/distro/haiku | 19 ++++++++ neofetch | 140 +++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 124 insertions(+), 35 deletions(-) create mode 100644 ascii/distro/haiku diff --git a/ascii/distro/haiku b/ascii/distro/haiku new file mode 100644 index 0000000..d0926c5 --- /dev/null +++ b/ascii/distro/haiku @@ -0,0 +1,19 @@ +"\ +${c2} :dc' + 'l:;'${c1},${c2}'ck. .;dc:. + co ${c1}..${c2}k. .;; ':o. + co ${c1}..${c2}k. ol ${c1}.${c2}0. + co ${c1}..${c2}k. oc ${c1}..${c2}0. + co ${c1}..${c2}k. oc ${c1}..${c2}0. +.Ol,. co ${c1}...''${c2}Oc;kkodxOdddOoc,. + ';lxxlxOdxkxk0kd${c1}oooll${c2}dl${c1}ccc:${c2}clxd; + ..${c1}oOolllllccccccc:::::${c2}od; + cx:ooc${c1}:::::::;${c2}cooolcX. + cd${c1}.${c2}''cloxdoollc' ${c1}...${c2}0. + cd${c1}......${c2}k;${c1}.${c2}xl${c1}.... .${c2}0. + .::c${c1};..${c2}cx;${c1}.${c2}xo${c1}..... .${c2}0. + '::c'${c1}...${c2}do${c1}..... .${c2}K, + cd,.${c1}....:${c2}O,${c1} + ':clod:'${c1} + ${c1} +" diff --git a/neofetch b/neofetch index 14ceea3..f2cb8f8 100755 --- a/neofetch +++ b/neofetch @@ -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 } @@ -253,6 +254,10 @@ getdistro() { esac distro="${distro/\(*}" ;; + + "Haiku") + distro="$(uname -sv | awk '{print $1 " " $2}')" + ;; esac # Get architecture @@ -303,51 +308,62 @@ 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/.*}" - ;; - esac + "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" + 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 "$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 "$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 + 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}" + uptime="${days:+$days, }${hours:+$hours, }${minutes}" + uptime="${uptime%', '}" + uptime="${uptime:-${seconds} seconds}" + ;; + esac # Make the output of uptime smaller. case "$uptime_shorthand" in @@ -461,6 +477,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 @@ -845,6 +865,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 @@ -1025,6 +1063,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 @@ -1085,6 +1127,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" @@ -1268,6 +1316,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%,*}" @@ -1715,6 +1771,11 @@ getlocalip() { "Windows") localip="$(ipconfig | awk -F ': ' '/IPv4 Address/ {printf $2}')" ;; + + "Haiku") + localip="$(ifconfig | awk -F ': ' '/Bcast/ {print $2}')" + localip="${localip/', Bcast'}" + ;; esac } @@ -1795,6 +1856,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 @@ -2556,6 +2622,10 @@ colors() { setcolors 1 2 4 3 ;; + "Haiku"*) + setcolors 2 0 + ;; + "Raspbian"* | *) setcolors 2 1 ;; From 085c45285ae3357939649ea051e00b04006362aa Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 5 Nov 2016 08:46:29 +1100 Subject: [PATCH 2/5] Haiku: Added battery support --- neofetch | 85 +++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/neofetch b/neofetch index f2cb8f8..c09d315 100755 --- a/neofetch +++ b/neofetch @@ -316,53 +316,54 @@ getuptime() { 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/,*}" + *) + # Get uptime in seconds + case "$os" in + "Linux" | "Windows") + seconds="$(< /proc/uptime)" + seconds="${seconds/.*}" + ;; - # Get current date in seconds - now="$(date +%s)" - seconds="$((now - boot))" - ;; + "Mac OS X" | "iPhone OS" | "BSD") + boot="$(sysctl -n kern.boottime)" + boot="${boot/'{ sec = '}" + boot="${boot/,*}" - "Solaris") - seconds="$(kstat -p unix:0:system_misc:snaptime | awk '{print $2}')" - seconds="${seconds/.*}" - ;; - esac + # 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/.*}" + ;; + esac - days="$((seconds / 60 / 60 / 24)) days" - hours="$((seconds / 60 / 60 % 24)) hours" - minutes="$((seconds / 60 % 60)) minutes" + 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 "$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 "$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 + 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}" - ;; + uptime="${days:+$days, }${hours:+$hours, }${minutes}" + uptime="${uptime%', '}" + uptime="${uptime:-${seconds} seconds}" + ;; esac # Make the output of uptime smaller. @@ -1736,6 +1737,12 @@ getbattery() { [ "$battery" ] && \ battery+="%" ;; + + "Haiku") + battery0full="$(awk -F '[^0-9]*' 'NR==2 {print $4}' /dev/power/acpi_battery/0)" + battery0now="$(awk -F '[^0-9]*' 'NR==5 {print $4}' /dev/power/acpi_battery/0)" + battery="$((battery0full / battery0now * 100))%" + ;; esac case "$battery_state" in From 1f77ae079eef3e82fcb778f13f63a6253f9b1019 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 5 Nov 2016 08:51:59 +1100 Subject: [PATCH 3/5] Haiku: Fix battery usage --- neofetch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neofetch b/neofetch index c09d315..bf92c8a 100755 --- a/neofetch +++ b/neofetch @@ -1739,8 +1739,8 @@ getbattery() { ;; "Haiku") - battery0full="$(awk -F '[^0-9]*' 'NR==2 {print $4}' /dev/power/acpi_battery/0)" - battery0now="$(awk -F '[^0-9]*' 'NR==5 {print $4}' /dev/power/acpi_battery/0)" + battery0full="$(awk -F '[^0-9]*' 'NR==5 {print $4}' /dev/power/acpi_battery/0)" + battery0now="$(awk -F '[^0-9]*' 'NR==2 {print $4}' /dev/power/acpi_battery/0)" battery="$((battery0full / battery0now * 100))%" ;; esac From 20f9ecabeac96b6cfda864990b9387979157ef21 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 5 Nov 2016 08:55:06 +1100 Subject: [PATCH 4/5] Haiku: Fix battery again --- neofetch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neofetch b/neofetch index bf92c8a..c09d315 100755 --- a/neofetch +++ b/neofetch @@ -1739,8 +1739,8 @@ getbattery() { ;; "Haiku") - battery0full="$(awk -F '[^0-9]*' 'NR==5 {print $4}' /dev/power/acpi_battery/0)" - battery0now="$(awk -F '[^0-9]*' 'NR==2 {print $4}' /dev/power/acpi_battery/0)" + battery0full="$(awk -F '[^0-9]*' 'NR==2 {print $4}' /dev/power/acpi_battery/0)" + battery0now="$(awk -F '[^0-9]*' 'NR==5 {print $4}' /dev/power/acpi_battery/0)" battery="$((battery0full / battery0now * 100))%" ;; esac From f49b2826bac5c29f3b81da7ef49195e917556c0f Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 5 Nov 2016 08:56:48 +1100 Subject: [PATCH 5/5] Disk: Disable disk in Haiku --- neofetch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neofetch b/neofetch index c09d315..ac46a84 100755 --- a/neofetch +++ b/neofetch @@ -1619,7 +1619,7 @@ getdisk() { esac ;; - "Mac OS X" | "BSD") + "Mac OS X" | "BSD" | "Haiku") case "$distro" in "FreeBSD"* | *"OS X"* | "Mac"* ) df_flags="-l -H /"