tmux-plugins / tmux-cpu

Plug and play cpu percentage and icon indicator for Tmux.
MIT License
444 stars 69 forks source link

OpenBSD support for iostat #14

Closed dpremy closed 8 years ago

dpremy commented 8 years ago

OpenBSD isn't detected and the unknown iostat warning is displayed.

Simply copying FreeBSD's checks and command will work to support OpenBSD 6.0 amd64.

diff --git a/scripts/cpu_percentage.sh b/scripts/cpu_percentage.sh
index e0679fd..366a5d4 100755
--- a/scripts/cpu_percentage.sh
+++ b/scripts/cpu_percentage.sh
@@ -13,6 +13,8 @@ print_cpu_percentage() {
                        iostat -c 2 disk0 | tail -n 1 | awk '{usage=100-$6} END {printf("%5.1f%%", usage)}'
                elif is_freebsd; then
                        iostat -c 2 | tail -n 1 | awk '{usage=100-$NF} END {printf("%5.1f%%", usage)}'
+               elif is_openbsd; then
+                       iostat -c 2 | tail -n 1 | awk '{usage=100-$NF} END {printf("%5.1f%%", usage)}'
                else
                        echo "Unknown iostat version please create an issue"
                fi
diff --git a/scripts/helpers.sh b/scripts/helpers.sh
index fce995c..032e802 100644
--- a/scripts/helpers.sh
+++ b/scripts/helpers.sh
@@ -17,6 +17,10 @@ is_freebsd() {
        [ $(uname) == "FreeBSD" ]
 }

+is_openbsd() {
+       [ $(uname) == "OpenBSD" ]
+}
+
 is_linux() {
        [ $(uname) == "Linux" ]
 }

I'll try to make a pull request if I have some time later on.

ctjhoa commented 8 years ago

Thanks for the report. If it's the same code than the freebsd one you could write it like that:

elif is_freebsd || is_openbsd; then
iostat -c 2 | tail -n 1 | awk '{usage=100-$NF} END {printf("%5.1f%%", usage)}'

I let the issue open and wait for a PR :)

dpremy commented 8 years ago

I don't have any FreeBSD to verify, but it should have the same tools, in which case iostat never gives a decimal output for cpu usage. This means the iostat awk gives the cpu status with one decimal place added, but it will always be ".0".

Possibly for BSD flavors we change the iostat line to the following to still keep the spacing, but trim out the unused decimal? iostat -c 2 | tail -n 1 | awk '{usage=100-$NF} END {printf("%5.0f%%", usage)}'

ctjhoa commented 8 years ago

@dpremy decimal is for consistency between systems. For example, in ArchLinux iostat return decimal. I try to avoid most of OS specific code for maintenance.

ctjhoa commented 8 years ago

It should work now, don't hesitate to open a new issue if there's still a problem