-
-
Notifications
You must be signed in to change notification settings - Fork 642
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
Configuration for bitbar and plugins #88
Comments
How about environment variables?
|
+1 to a configuration file. Would prefer that to env variables. As can keep conf in dotfiles repo. |
Yeah, prefer config file based approach. @matryer can you add labels to the issues, so that we can triage must have features, so that people know what is needed? And, thanks for the awesome tool :) |
+1 for a configuration file as well ! |
Guys, an environment file could be a config file like below. What do you think?
Then in the plugin:
|
This would not really work for plugins that are not shell scripts (for example if you have a However, sourcing the With that in mind, i would prefer a conf file that is not a script (just a |
That approach is not suitable for non-shell scripts right. Something that a plugin can feed in to the scripts, say as arguments, would be great. And what BitBar feeds to a particular plugin should be based on some convention for how the configuration is saved. |
@jcaille - +1 to most of what you said. The approach could be similar to what git hooks receive from git. Any kind of script can run them. Many of the inputs are parameters or sent via STDIN. |
How about having a [myplugin.sh]
token=foobar
[otherplugin.rb]
password=hunter2 myplugin.sh: #!/usr/bin/env sh
echo $token #foobar otherplugin.rb: #!/usr/bin/env ruby
ENV["password"] #hunter2 |
I've actually gone ahead and implemented a I'd really like to try and implement this feature in the next few days / weeks, as it seems to be a prerequisite for more advanced features (plugin management, automatic plugins update, ...). I like @keithamus idea that Bitbar should handle the configuration file, and route relevant parameters to each script through the environment when running them. I just see a few wrinkles that we might need to work out. One of the problem that I ran into (and that we might have if we offer a standardised solution) is providing default values and discoverability for those parameters. What I mean by this is without reading the script, there is absolutely no way to discover what parameters are available, and what values are accepted or provided by default. I think there are multiple ways to address this
We could handle parameters discoverability through documentation. Plugins developper should provide documentation about what parameters are accepted, ideally in their plugin file or in some other documentation. This makes it easy to implement for us, and puts most of the work on the shoulder of plugins developers.
Another (more convoluted) solution that comes to my mind is to have a configuration setup similar to the one used by
When launching a script, we successively parse the files and populate the environnement with the relevant parameters. Off the top of my head, other problems might be :
What do you think ? Do you have ideas for handling those issues ? Do you see other problems that might arise ? If nobody has objections, i'll start by implementing the parsing and routing of parameters contains in a |
I think defaults can be done easily enough in userland, even in bash can do defaults.
What about passing an argument to a plugin on first run? e.g. when BitBar first detects my plugin (myscript.sh) it calls #!/usr/bin/env sh
if [ "$1" = "setup" ]
then
echo "option TOKEN"
exit 0
fi
... #!/usr/bin/env python
import sys
if sys.argv[1] == "setup"
print "option TOKEN"
sys.exit(0)
...
If we had an ini like I described:
Seems like, especially for a first pass, keeping things to Strings will be fine. Need an advanced config? Use serialised strings - like JSON. |
+1 to what you said. I like the A few questions to clear up my understanding :
This should keep the config file up to date with new and updated plugins. Downside is startup could be much longer, needing to run
This should allows the user to update the refresh period without breaking parameter integration. If there's no objections, i'll start implementing this over the weekend |
Personally I agree with everything you've said. But maybe wait for @matryer's approval before working on a PR? |
Good point |
@matryer Do you think this is a good idea to implement? |
Inline with configuration file discussion, is it ok to implement XDG base directories? |
Major +1 to configuration files. With variables-in-scripts, it makes staying in sync with master a nightmare. Without, end users are just a |
I concur with @mcchrish; XDG base directories would be a good idea |
👍 to a config file. I've played around with a "global" ~/.bitbarrc and it's working well for needs. However, I see the need for namespacing on a larger scale. Globals with the ability for a namespace to override seem like a potentially useful feature to reduce configuration sprawl. I'd also consider potentially offloading the burden of config parsing to the scripts. This will mean your proposed "config discovery" functionality is unnecessary. Build a configuration parser (can we just use JSON or YAML for the config file?) and pass relevant values (globals and namespaced) to the script as JSON. Allow the script to parse the values and throw intelligent errors if a value they expect is absent. |
I'm happy to do this - @keithamus do you want to suggest a final design from all the ideas posted here? |
Sure. Here's something close to a final design; I think @manojlds and @jcaille should critique this before we go head with anything though.
To provide an example user journey:
|
@keithamus thanks for writing that up! A few questions for you:
|
I think this can be solved in userland. If a value is removed from bitbar.conf, the next time a refresh (or initialisation) happens, the value wont be given to the script. If a script depends on a value, it should either provide a sensible default or fail with useful messages. To wit: #!/bin/bash
if [ "$1" = "setup" ];
then
echo "option PHRASE hello world"
exit 0
fi
if [ "$PHRASE" = "" ];
then
echo "PHRASE must be set"
exit 1
fi
echo $PHRASE
Same as above - if scripts add or remove values, they can simply check for existence of the new variables and warn the user.
Again, this is a userland thing. If a value is optional, plugins should provide sensible defaults. If it is required and the existing value doesn't satisfy, the plugin should exit with an explanation.
No, this is not a custom format. This is the INI standard. YAML, JSON, PLIST or other configuration formats could be used - but INI works well because it fits all of the requirements and nothing more. We need a key value store with namespacing, and comments would be nice. Ini format is key value with namespacing (sections) and comments. JSON is less readable than ini, and offers extras that we don't need (like deep nesting, arrays, numbers, etc). YAML is arguably more readable but offers loads more stuff that we don't need. |
Thanks for getting back so quickly! Proposal sounds good to me. Looking forward to code reviewing the PR :) |
I like this, especially having configuration passed in through environment, but I would vote for 2 changes.
Regarding the syntax from |
We already have plugin metadata. Why not just extended that? Then plugins don't have to implement a special # <bitbar.option>USERNAME</bitbar.option>
# <bitbar.option>PASSWORD</bitbar.option>
# <bitbar.option>I_LIKE_PIZZA</bitbar.option> If you want to allow specifying "type" you can either do |
@tresni right now, to my knowledge, the metadata is only used on the getbitbar website. We could repurpose it for option declaration, I suppose - personally I'm not the biggest fan of this idea though. I like @vogonistic's idea of |
I just want to throw in my vote for something as simple as a |
+1 for simple. Perfect may be getting in the way of good here. |
There's nothing saying that a GUI couldn't manage |
I wanted a way to separate configuration from code, so this is an attempt to do so. Reads configuration from a `config.json` file in the bitbar plugin directory, and loads it into the environment of the script so that it's available to plugins. This is probably the most lines of Objective-C I've ever written in one sitting. Feel free to critique.
I just filed a pull request that should be at least a start on this one. It just reads config from a
Those become environment variables you can access from within scripts, like this:
I know almost nothing about ObjectiveC, so I kind of threw it together. It doesn't auto-update the environment when you refresh your plugins, so you need to quit and restart BitBar to update your variables. But it works for my needs, and it's simple, which is what I was looking for. |
I found a creative workaround that works for stock BitBar. If you follow the instructions in this StackOverflow question and create an |
Also using that now. Works! |
Guys, you a wasting time. It is easy to set environment variables in the way, such BitBar plugins will see them. Just do:
And restart BitBar. |
Since this is still open I'd like to add my vote for XDG support. I also have another suggestion regarding sensitive data. Like other people, I have accidentally committed a Github access token to a repository. In my case it was because I am not only using an XDG setup but, I also keep my ~/.config in a github repository so that I can keep it in sync across the different machines that I use. (I keep my sensitive tokens in some files under ~/.ssh./ Adding support for XDG would include using its XDG_CONFIG_DIRS which is just what I need as long as Bitbar doesn't stop looking when it finds one configuration file. Rather, I like to see it look through all of the XDG_CONFIG_DIRS and read every matching configuration file it finds applying each of them, such that later definitions overwrite earlier ones. This would allow keeping secure data such as Github tokens and sensitive data such as passwords in a location that is not (backed up/stored as) part of common application configuration. (This is not defined by the XDG spec. but, I am trying to have it added.) My setup is, of course, a bit of a pain because many applications do not support XDG or otherwise segment their machine specific configuration (window geometry, cache files) from the machine agnostic configuration (app. behavior). I handle this differently for different apps. when moving between machines. For some apps. I don't commit their configuration, for others I merge the diffs, etc. |
Is this closed with a fix? |
@astrostl This issue was automatically closed. xbar is the reboot for BitBar that just entered beta, it has Variables support which might help here. There's an example here. |
@matryer In that case, if we have a plugin made for bitbar that uses one of the workarounds detailed in this thread above, is it advised to go and make a pull request in the xbar repo to use the new variables support? |
@EricAndrechek Once xbar v2.0.0 is released (following extensive beta testing), I would like all plugins that are configurable in some way to see if Variables is the right answer. As you can see, xbar presents a nice UI to help the end-user input the right things. |
Read config from something like
~/.bitbarrc
. This should also enable plugins to hook into it.For example, for the jenkins plugin, within
~/.bitbarrc
:If not for this approach, some config management will be of use.
The text was updated successfully, but these errors were encountered: