Can't use the command_NAME widget
ZauJulio opened this issue · comments
Describe the bug
Can't use the command_NAME widget
To Reproduce
Steps to reproduce the behavior:
- 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}')"
- Reset z
- See error
I've tried formatting in several ways, but I only see {comand_INFO}
Expected behavior
CPU 11.9% RAM 61.4% TEMP +54.0°C
on center
Desktop (please complete the following information):
- OS: EndeavourOS
- Zellij version: zellij 0.40.1
- Version: 0.14.1
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?
Sorry, I just typed it wrong in the issue, the layout is correct command_INFO
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\""
I think there are two problems:
- widgets must be named completely lowercase. Can you please try to use
{command_info}
? This shows the widget on my side. There might be some other problem with escaping, since it does not render the sequence for me. - The interval must be integers, not floating points
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
Thanks for sharing your script also! Maybe someone can get some inspiration from your config