Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to use this with Conky, but having some issues #13

Open
MostHated opened this issue Mar 15, 2021 · 6 comments
Open

Trying to use this with Conky, but having some issues #13

MostHated opened this issue Mar 15, 2021 · 6 comments

Comments

@MostHated
Copy link

Hey there,
I am sure I am doing something incorrectly, but I am new to LUA, so I am not quite sure what I am doing wrong.

Here is essentially what I am trying to do:

Code block using sh
function parts.cputemp(colorBg)
  -- local command = "zsh -c \'/home/mosthated/_dev/languages/sh/temps.zsh \"Tccd1\"'"
  -- local temp = _h.exec("zsh -c \'/home/mosthated/_dev/languages/sh/temps.zsh \"Tccd1\"'")
  -- local temp = sh.command(command)

  -- Trying to run this command to return a single numeric value (30.1, 35.6, etc)
  local temp = sh.command('zsh','-c', '/home/mosthated/_dev/languages/sh/temps.zsh', 'Tccd1')

  local cputemp = [[\
  -- Then I wanted to reuse that same value throughout the rest of the script block
${if_match ]].. temp .. [[<45}\
]] .. _h.value(temp .. '°C', ci.good) .. [[
${else}${if_match ]].. temp ..[[<55}\
]] .. _h.value(temp .. '°C', ci.degraded) .. [[
${else}${if_match  ]]..  temp ..[[>=55}\
]] .. _h.value(temp .. '°C', ci.bad) .. [[
${endif}${endif}${endif}\
]]
  return _h.common('', 'CPU', cputemp, colorBg)
end
Unfortunately, when I attempt to use that code, I get the following message: `attempt to concatenate a function value (local 'temp')` After looking over the instructions again, I attempted to try this:
${if_match ]].. temp() .. [[<45}\
]] .. _h.value(temp() .. '°C', ci.good) .. [[

That then gives me the message of : attempt to call a table value

I also attempted to do tostring(temp()) but I believe that gave a message of: Bad arguments: 'function: 0x55c917c53460' and '45'

Might anyone have any insight on what I might need to change in order to properly get back the numeric value?

Thanks!
-MH

@JBlaschke
Copy link

@MostHated Thanks to JBlaschke#1 @Frityet added the ability to concatenate the output from shell functions. You can give this fork a try (it's available as sh on luarocks)

@Frityet
Copy link

Frityet commented Dec 12, 2022

😎

@MostHated
Copy link
Author

While I definitely appreciate the effort, that was some time ago. As such, I was able to accomplish what I was after eventually in a different manner at the time. Since then I have mostly migrated from Conky to Eww, which uses Rust. I still do use Conky for a few things that I have just been too lazy to remake, and if I ever make any modifications to them, I will be sure to look into this again.

Thanks,
-MH

@StandingPadAnimations
Copy link

StandingPadAnimations commented Apr 28, 2023

@JBlaschke I know this is the wrong place to ask, but the fork doesn't have an Issues tab.

I've noticed that for some reason sh doesn't handle wildcards, nor does it handle certain variables. For instance, the following:

local img = find('"$HOME"/.config/hypr/wallpaper/{*.png,*.jpg}') : shuf() : head('-1')

Returns with the following error:

/bin/lua: /home/USER/.luarocks/share/lua/5.4/sh.lua:320: find: ‘"$HOME"/.config/hypr/wallpaper/{*.png,*.jpg}’: No such file or directory

stack traceback:
	[C]: in function 'error'
	/home/USER/.luarocks/share/lua/5.4/sh.lua:320: in global 'find'
	./wallpaper.lua:35: in main chunk
	[C]: in ?```

@Frityet
Copy link

Frityet commented Apr 29, 2023

@JBlaschke I know this is the wrong place to ask, but the fork doesn't have an Issues tab.

I've noticed that for some reason sh doesn't handle wildcards, nor does it handle certain variables. For instance, the following:

local img = find('"$HOME"/.config/hypr/wallpaper/{*.png,*.jpg}') : shuf() : head('-1')

Returns with the following error:

/bin/lua: /home/USER/.luarocks/share/lua/5.4/sh.lua:320: find: ‘"$HOME"/.config/hypr/wallpaper/{*.png,*.jpg}’: No such file or directory

stack traceback:
	[C]: in function 'error'
	/home/USER/.luarocks/share/lua/5.4/sh.lua:320: in global 'find'
	./wallpaper.lua:35: in main chunk
	[C]: in ?```

This is because any command is executed using popen, like creating a new process instead of just invoking the shell, of which * is a shell expression. its still possible to do though

@JBlaschke
Copy link

Huh! I never noticed that there wasn't an issues tab. I'll have to fix that.

@StandingPadAnimations what @Frityet said is exactly right. You can do this though: https://github.com/JBlaschke/luash/blob/101f3006cea281ff3af575f851aedf73c1dcb66e/example.lua#L42 and send the shell expression to bash (or whatever your favorite shell is).

I have been thinking of several features to release. Having a shell execution mode just made it on there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants