dj95 / zjstatus

A configurable statusbar plugin for zellij
MIT License
358 stars 6 forks source link

Can't use the command_NAME widget #64

Closed ZauJulio closed 1 month ago

ZauJulio commented 1 month ago

Describe the bug Can't use the command_NAME widget

To Reproduce Steps to reproduce the behavior:

  1. Set layout:
layout {
    pane
    pane size=1 borderless=true {
        plugin location="https://github.com/dj95/zjstatus/releases/latest/download/zjstatus.wasm" {
            border_enabled  "true"
            border_char     "─"
            border_format   "#[fg=#6C7086]{char}"
            border_position "top"

            hide_frame_for_single_pane "true"

            mode_normal  "#[bg=blue] "
            mode_tmux    "#[bg=#ffc387] "

            tab_normal   "#[fg=#6C7086] {name} "
            tab_active   "#[fg=#9399B2,bold,italic] {name} "

            command_INFO_command  "bash -c \"echo CPU \\$(LC_ALL=C top -bn1 | grep 'Cpu(s)' | sed 's/.*, *\\\\([0-9.]*\\\\)%* id.*/\\\\1/' | awk '{print 100 - \\\\$1}')% RAM \\$(free -m | awk '/Mem:/ { printf(\\\\\"%3.1f%%\\\\\", \\\\$3/\\\\$2*100) }') TEMP \\$(sensors | grep 'Package id 0:' | awk '{print \\\\$4}')\""
            command_INFO_format   "#[fg=green] {stdout}" 
            command_INFO_interval "0.5"
            command_INFO_rendermode "dynamic"

            command_git_branch_command     "git rev-parse --abbrev-ref HEAD"
            command_git_branch_format      "#[fg=blue] {stdout} "
            command_git_branch_interval    "10"
            command_git_branch_rendermode  "static"

            datetime        "#[fg=#6C7086,bold] {format} "
            datetime_format "%H:%M:%S"
            datetime_timezone "America/Sao_Paulo"

            format_left   "{datetime} #[fg=#89B4FA,bold]"
            format_center "{tabs} {command_INFO}"
            format_right  "{command_git_branch}"
            format_space  ""
        }
    }
}

Command:

bash -c "echo CPU \$(LC_ALL=C top -bn1 | grep 'Cpu(s)' | sed 's/.*, *\\([0-9.]*\\)%* id.*/\\1/' | awk '{print 100 - \$1}')% RAM \$(free -m | awk '/Mem:/ { printf(\"%3.1f%%\", \$3/\$2*100) }') TEMP \$(sensors | grep 'Package id 0:' | awk '{print \$4}')"
  1. Reset z
  2. See error

I've tried formatting in several ways, but I only see {comand_INFO}

image

Expected behavior CPU 11.9% RAM 61.4% TEMP +54.0°C on center

Desktop (please complete the following information):

dj95 commented 1 month ago

Hi and thanks for the detailed bug report.

I think you've got a typo there: comand_INFO should be command_INFO.

Does that work for you?

ZauJulio commented 1 month ago

Sorry, I just typed it wrong in the issue, the layout is correct command_INFO

ZauJulio commented 1 month ago

I also tried the following layout/command

layout {
    pane
    pane size=1 borderless=true {
        plugin location="https://github.com/dj95/zjstatus/releases/latest/download/zjstatus.wasm" {
            border_enabled  "true"
            border_char     "─"
            border_format   "#[fg=#6C7086]{char}"
            border_position "top"

            hide_frame_for_single_pane "true"

            mode_normal  "#[bg=blue] "
            mode_tmux    "#[bg=#ffc387] "

            tab_normal   "#[fg=#6C7086] {name} "
            tab_active   "#[fg=#9399B2,bold,italic] {name} "

            command_INFO_command "bash -c \"cpu=$(LC_ALL=C top -bn1 | awk '/Cpu\\(s\\)// {print 100 - $8}') && ram=$(free -m | awk '/Mem:/ { printf(\"%3.1f%%\", $3/$2*100) }') && temp=$(sensors | awk '/Package id 0:/ {print $4}') && echo 'CPU $cpu% RAM $ram TEMP $temp'\""
            command_INFO_format   "#[fg=green] {stdout}" 
            command_INFO_interval "0.5"
            command_INFO_rendermode "dynamic"

            command_git_branch_command     "git rev-parse --abbrev-ref HEAD"
            command_git_branch_format      "#[fg=blue] {stdout} "
            command_git_branch_interval    "10"
            command_git_branch_rendermode  "static"

            datetime        "#[fg=#6C7086,bold] {format} "
            datetime_format "%H:%M:%S"
            datetime_timezone "America/Sao_Paulo"

            format_left   "{datetime} #[fg=#89B4FA,bold]"
            format_center "{tabs} {command_INFO}"
            format_right  "{command_git_branch}"
            format_space  ""
        }
    }
}

From:

bash -c "cpu=$(LC_ALL=C top -bn1 | awk '/Cpu\(s\)/ {print 100 - $8}') && ram=$(free -m | awk '/Mem:/ { printf("%3.1f%%", $3/$2*100) }') && temp=$(sensors | awk '/Package id 0:/ {print $4}') && echo \"CPU $cpu% RAM $ram TEMP $temp\""
ZauJulio commented 1 month ago

Or

command_INFO_command "bash -c \"cpu=$(LC_ALL=C top -bn1 | awk '/Cpu\\(s\\)/ {print 100 - $8}') && ram=$(free -m | awk '/Mem:/ { printf(\"%3.1f%%\", $3/$2*100) }') && temp=$(sensors | awk '/Package id 0:/ {print $4}') && echo \"CPU $cpu% RAM $ram TEMP $temp\"\""

Same result: Tab #1 {command_INFO}

image

dj95 commented 1 month ago

I think there are two problems:

ZauJulio commented 1 month ago

After renaming command_NAME, I moved the command to a shell script and everything worked fine. Thanks for the help @dj95

~/.config/zellij/layouts/default.kdl:

layout {
    pane
    pane size=1 borderless=true {
        plugin location="https://github.com/dj95/zjstatus/releases/latest/download/zjstatus.wasm" {
            border_enabled  "true"
            border_char     "─"
            border_format   "#[fg=#6C7086]{char}"
            border_position "top"

            hide_frame_for_single_pane "true"

            mode_normal  "#[bg=blue] "
            mode_tmux    "#[bg=#ffc387] "

            tab_normal   "#[fg=#6C7086] {name} "
            tab_active   "#[fg=#9399B2,bold,italic] {name} "

            command_info_command "bash -c ~/.config/zellij/plugins/info.sh"
            command_info_format   "#[fg=green] {stdout}"
            command_info_interval "2"
            command_info_rendermode "static"

            command_git_branch_command     "git rev-parse --abbrev-ref HEAD"
            command_git_branch_format      "#[fg=blue] {stdout} "
            command_git_branch_interval    "10"
            command_git_branch_rendermode  "static"

            datetime        "#[fg=#6C7086,bold] {format} "
            datetime_format "%H:%M:%S"
            datetime_timezone "America/Sao_Paulo"

            format_left   "{datetime} #[fg=#89B4FA,bold]"
            format_center "{tabs} | {command_info} #[fg=#89B4FA,bold]"
            format_right  "{command_git_branch}"
            format_space  ""
        }
    }
}

~/.config/zellij/plugins/info.sh:

#!/bin/bash

cpu=$(LC_ALL=C top -bn1 2>/dev/null | awk '/Cpu\(s\)/ {print 100 - $8}')
ram=$(free -m 2>/dev/null | awk '/Mem:/ { printf("%3.1f%%", $3/$2*100) }')
temp=$(sensors 2>/dev/null | awk '/Package id 0:/ {print $4}')
ac=$(cat /sys/class/power_supply/ACAD/online)

if [ "$ac" -eq "0" ]; then
    battery=$(upower -i $(upower -e | grep 'BAT') | grep "percentage" | awk '{print $2}')
    echo "[CPU $cpu% | RAM $ram | TC $temp | BATT $battery]"
else
    echo "[CPU $cpu% | RAM $ram | TC $temp]"
fi
dj95 commented 1 month ago

Thanks for sharing your script also! Maybe someone can get some inspiration from your config