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

[Feature Request] Shell / text provider #75

Open
robertmoelker opened this issue Aug 6, 2024 · 5 comments · May be fixed by #160
Open

[Feature Request] Shell / text provider #75

robertmoelker opened this issue Aug 6, 2024 · 5 comments · May be fixed by #160
Assignees
Labels
help wanted Extra attention is needed type: feature New feature or request

Comments

@robertmoelker
Copy link

Summary

Request to add support for reading from text files and/or executing scripts at scheduled intervals in Zebar.

Description

I've used GlazeWM v2 to display time tracking information from Toggl. I've created a shell script to output the status of a CLI to a text file, which was then read by the status bar. A cronjob on my local machine ran the script every two minutes to keep it up-to-date. Can Zebar include a feature to read from a text file or possibly execute a script at scheduled intervals?

Use Case

This feature would be useful for displaying dynamic and real-time information from various sources, such as time tracking tools, system monitoring scripts, or any other data that can be output to a text file or script.


PS: I've just installed the new version of GlazeWM & Zebar and it works great!

@lars-berger
Copy link
Member

lars-berger commented Aug 18, 2024

100% agree this would be a nice feature. Perhaps a config like this?

providers:
  - type: 'shell'
    alias: 'music'
    command: 'node music_player_backend.js'
    update_method:
      continuous: false
      interval: 5000
template: |
  {{ music.output }}
  {{ music.prevOutputs }}

An idea is to expose a shell.exec({ commandOverride?: string }) function to explicitly run it and even override the command so that different flags could be passed.

Edit (Dec. 2024): the suggested config snippet above was for Zebar v2, which has since been overhauled to a new format/architecture.

@robertmoelker
Copy link
Author

100% agree this would be a nice feature. Perhaps a config like this?

providers:
  - type: 'shell'
    alias: 'music'
    command: 'node music_player_backend.js'
    update_method:
      continuous: false
      interval: 5000
template: |
  {{ music.output }}
  {{ music.prevOutputs }}

An idea is to expose a shell.exec({ commandOverride?: string }) function to explicitly run it and even override the command so that different flags could be passed.

That sounds perfect to me!

@HeyItsGilbert
Copy link

Parsing a text file would be handy. Then users could script in whatever language they want and write to a file. Personally I'd want to exec PowerShell, but I'm perfectly happy writing to a file and having zebar read it.

@robertmoelker
Copy link
Author

I was really missing the feature, so I made the following workaround for myself that works.
Maybe if someone is searching for something similar, this could help.

It's a simple GET request on an webserver and within the webserver i'm calling an CLI script.

function App() {
 ......
 const [commandOutput, setCommandOutput] = useState('Timer isn\'t set.');

 useEffect(() => {
   .....

   const interval = setInterval(fetchCommandOutput, 20000); // Refresh every 2 minutes
   return () => clearInterval(interval);
 }, []);

 const fetchCommandOutput = async () => {
   try {
     const response = await fetch('http://localhost:9999/time-tracking');
     const text = await response.text()

     setCommandOutput(text);
   } catch (error) {
     setCommandOutput('Unable to fetch timer.')
   }
 }
<div className="right">
  <div className="time-tracking">
    {commandOutput === 'off' ? (
      <>
        <i className="nf nf-md-timer_off" /> No active timer
      </>
    ) : (
      <>
        <i className="nf nf-md-timer_check" /> {commandOutput}
      </>
    )}
  </div>

  .....

@blurm
Copy link

blurm commented Nov 26, 2024

Has the new version of GlazeWM and ZeBar resolved the issue of reading local files? Which version is it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed type: feature New feature or request
Projects
Status: 📋 Available
4 participants