Compare commits

..

8 Commits

6 changed files with 77 additions and 37 deletions

View File

@ -4,34 +4,14 @@ root window (mostly I only see one window taking up the entire screen, with a
dmenu at the top, and another dmenu at the bottom that runs conky). I run conky dmenu at the top, and another dmenu at the bottom that runs conky). I run conky
in CLI mode only, and that's good enough for me. in CLI mode only, and that's good enough for me.
I pipe the output of conky through dmenu, which upates every two seconds. I I pipe the output of conky through dmenu, which upates every second. I also
also have custom formatting functions (see scripts.lua in this repository). have custom formatting functions (see scripts.lua in this repository). This
This ensures the output of conky has the same length, even if certain fields ensures the output of conky has the same length, even if certain fields within
within the string change. This is especially useful for the network bandwidth the string change. This is especially useful for the network bandwidth output,
output, which otherwise change length every two seconds as the bandwidth usage which otherwise change length every two seconds as the bandwidth usage
fluctuates between bytes (B), Kilobytes (KiB), and Megabytes (MiB). fluctuates between bytes (B), Kilobytes (KiB), and Megabytes (MiB).
TODO: My formatting function needs to be generalized. Essentially, I'm I have implemented `conky_printf`, a generalized function for printing conky
creating a conky-specific printf function. Right now, it's split into two data to the output string. It needs more testing, as I'm sure there are edge
functions, with calls to the Lua string.format function. One function takes cases where it doesn't work properly.
only one format specifier, and the other takes two.
The `fmt()` function takes the format string, and expects a single numerical
second argument. If the format string contains any format specifiers (see `man
sprintf` for details) that aren't numbers (e.g. `%s` for strings), fmt() will
fail with an error. I use this for the percentages of RAM, Swap, and CPU in
use.
The `fmt2()` function takes the format string, and expects two string arguments.
It is not necessarily an error if either or both of the arguments are numbers,
they will be cast to strings. I use this function to format the bandwidth
("Net:") display in conky, so the length of this segment doesn't shift around
(the Unicode arrow icons for up and down bandwidth stay in the same place).
Ideally these two functions would be combined into a `"conky_printf` function,
that could take an arbitrary format string with any number of format
specifiers, with the requisite number of numerical or string arguments. I know
how to do this with the `...`/`arg`/`unpack(arg)` table specification in Lua,
but numeric specifiers need to convert any strings passed to the function to
numeric values instead of strings. This is the challenging part, but should be
doable.

View File

@ -7,7 +7,7 @@
-- Please see LICENSE for details -- Please see LICENSE for details
-- Copyright (c) 2020-10-23 Trey Blancher -- Copyright (c) 2021 Trey Blancher
-- This program is free software: you can redistribute it and/or modify -- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by -- it under the terms of the GNU General Public License as published by
@ -32,18 +32,24 @@ conky.config = {
no_buffers = true, no_buffers = true,
update_interval = 1.0, update_interval = 1.0,
uppercase = false, uppercase = false,
use_spacer = 'right', use_spacer = "none",
pad_percents = 3, pad_percents = 3,
short_units = false, short_units = false,
}; };
conky.text = conky.text = [[\
[[\ ${lua_parse printf %-20s ${nodename_short}} \
RAM:${lua_parse printf %3.0f%% ${memperc}} \ RAM:${lua_parse printf %3.0f%% ${memperc}} \
Swap:${lua_parse printf %3.0f%% ${swapperc}} \ Swap:${lua_parse printf %3.0f%% ${swapperc}} \
CPU:${lua_parse printf %3.0f%% ${cpu cpu0}} \ CPU:${lua_parse printf %3.0f%% ${cpu cpu0}} \
/ ${fs_used /}/${fs_size /} \ / ${lua_parse printf %10s/%10s ${fs_used /} ${fs_size /}} \
${loadavg} \ ${loadavg} \
${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1} \ ${lua_parse printf %-20s ${top name 1}} \
${lua_parse printf %8d ${top pid 1}} \
${lua_parse printf %6.2f ${top cpu 1}} \
${lua_parse printf %6.2f ${top mem 1}} \
Net: ${lua_parse printf %10s▲%10s▼ ${upspeed wlp4s0} ${downspeed wlp4s0}} \ Net: ${lua_parse printf %10s▲%10s▼ ${upspeed wlp4s0} ${downspeed wlp4s0}} \
${exec ~/bin/core_temp.sh}${lua_parse printf %9s ${exec ~/bin/core_temp.sh -t}}^fg(\#ebdbb2) \
${exec ~/bin/nvme_temp.sh}${lua_parse printf %9s ${exec ~/bin/nvme_temp.sh -t}}^fg(\#ebdbb2) \
${exec ~/bin/virt_temp.sh}${lua_parse printf %9s ${exec ~/bin/virt_temp.sh -t}}^fg(\#ebdbb2) \
]]; ]];

18
core_temp.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/zsh
temp=$(sensors | grep 'Package id' | awk '{print $4}')
if [[ "${1}" == "-t" ]]; then
shift
echo -n "${temp}"
else
val=$(grep -Po '[\d.]+' <<< ${temp})
if [[ ${val} -le 30.0 ]]; then
printf "^fg(#0000cc)"
elif [[ ${val} -le 60.0 ]]; then
printf "^fg(#cc7700)"
elif [[ ${val} -gt 60.0 ]]; then
printf "^fg(#cc0000)"
fi
fi

17
nvme_temp.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/zsh
temp=$(sensors nvme-pci-3e00 | grep Composite | awk '{print $2}')
if [[ "${1}" == "-t" ]]; then
shift
echo -n "${temp}"
else
val=$(grep -Po '[\d.]+' <<< ${temp})
if [[ ${val} -le 30.0 ]]; then
printf "^fg(#0000cc)"
elif [[ ${val} -le 60.0 ]]; then
printf "^fg(#cc7700)"
elif [[ ${val} -gt 60.0 ]]; then
printf "^fg(#cc0000)"
fi
fi

View File

@ -19,7 +19,7 @@ function split_fmt(f)
in_spec = false in_spec = false
curr = "" curr = ""
elseif string.match(char, '[qs]') then elseif string.match(char, '[qs]') then
if string.match(curr, '^%%[0-9]*$') then if string.match(curr, '^%%%-?[0-9]*$') then
curr = curr .. char curr = curr .. char
table.insert(ret, curr) table.insert(ret, curr)
in_spec = false in_spec = false
@ -28,7 +28,7 @@ function split_fmt(f)
io.stderr:write("Invalid format: '" .. curr .. char .. "'\n") io.stderr:write("Invalid format: '" .. curr .. char .. "'\n")
return nil return nil
end end
elseif string.match(char, '[0-9%.]') then elseif string.match(char, '[0-9%.%-]') then
curr = curr .. char curr = curr .. char
elseif string.match(char, '%%') then elseif string.match(char, '%%') then
if string.match(curr, '^%%') then if string.match(curr, '^%%') then
@ -105,7 +105,7 @@ function conky_printf(format, ...)
end end
for i,fs in ipairs(formats) do for i,fs in ipairs(formats) do
if is_fmt_spec(fs) then -- we have a format specifier if is_fmt_spec(fs) then -- we have a format specifier
if string.match(fs, '[dEefgiouXx]$') then -- we have a numeric format specifier, convert value to number if string.match(fs, '[cdEefgiouXx]$') then -- we have a numeric format specifier, convert value to number
parsed_values[i] = tonumber(trim((parsed_values[i]))) parsed_values[i] = tonumber(trim((parsed_values[i])))
end end
end end

19
virt_temp.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/zsh
#!/bin/zsh
temp=$(sensors pch_skylake-virtual-0 | grep temp1 | awk '{print $2}')
if [[ "${1}" == "-t" ]]; then
shift
echo -n "${temp}"
else
val=$(grep -Po '[\d.]+' <<< ${temp})
if [[ ${val} -le 30.0 ]]; then
printf "^fg(#0000cc)"
elif [[ ${val} -le 60.0 ]]; then
printf "^fg(#cc7700)"
elif [[ ${val} -gt 60.0 ]]; then
printf "^fg(#cc0000)"
fi
fi