Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thomas-maurice/gowerline
Pluggable Go server to generate Powerline segments
https://github.com/thomas-maurice/gowerline
daemon golang http-api powerline powerline-status
Last synced: 5 days ago
JSON representation
Pluggable Go server to generate Powerline segments
- Host: GitHub
- URL: https://github.com/thomas-maurice/gowerline
- Owner: thomas-maurice
- License: mit
- Created: 2021-07-03T09:37:52.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-11-27T01:09:16.000Z (12 months ago)
- Last Synced: 2024-10-07T17:36:36.828Z (about 1 month ago)
- Topics: daemon, golang, http-api, powerline, powerline-status
- Language: Go
- Homepage:
- Size: 2.64 MB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gowerline
Because Python is hard and I've always wanted to write my segments in Go.
![Example](https://github.com/thomas-maurice/gowerline/blob/master/_assets/demo.gif)
## What is this ?
This is a deamon that generates and returns Powerline segments as [described in the docs](https://powerline.readthedocs.io/en/master/develop/segments.html).
This project has 2 parts:
* The daemon that runs your go code and exposes an HTTP API
* The powerline compatible code that glues it with the `powerline-daemon`## Quick install
You can grab the latest version of gowerline by running the following (needs curl, jq, tar and wget)```
curl -sSfL https://raw.githubusercontent.com/thomas-maurice/gowerline/master/install.sh | bash
```Then install the latest version of the python extension by running
```
pip install -U gowerline
```
## How does it work ?
This is a pluggable segment generating system. Essentially a very simple powerline "segment" in the sense
of the python class, will call a Go server that will be in charge of generating the actual segments. It allows you
to generate data that would be too long to generate if it had to be called every time you pop a shell,
for instance do API calls to your favourite stock ticker or for example check the validity of an auth token
every other minute.## Available plugins
Every plugin has a `README.md` file at the root of their directory detailing what they do and how they work
| Plugin name | Plugin description |
|-------|-------|
| [Bash](https://github.com/thomas-maurice/gowerline/blob/master/plugins/bash/README.md) | Renders segments that are the result of bash commands ran on a schedule |
| [Finnhub](https://github.com/thomas-maurice/gowerline/blob/master/plugins/finnhub/README.md) | Displays financial infos about a stock ticker (or many!) that you are interested in |
| [Vault](https://github.com/thomas-maurice/gowerline/blob/master/plugins/vault/README.md) | Gives you information about your current Hashicorp Vault token (display name, validity TTL & co) |
| [Colourenv](https://github.com/thomas-maurice/gowerline/blob/master/plugins/colourenv/README.md) | Renders environment variables in your terminal with different colourschemes depending on values (useful to not wreck production by mistake) |
| [Network](https://github.com/thomas-maurice/gowerline/blob/master/plugins/network/README.md) | Displays information about how your network connexion is doing |## How does it work (on my system) ?
You have two parts to it:
* The powerline extension, that bridges between poweline and the Go server
* The Go server that will bridge between the python extension and the plugins.Essentially, everytime you open a prompt, Powerline will call the various extensions of the server to
fetch segments to render, it's as simple as this.## How do I install it ?
```bash
$ make install # Will install the python extension and the go binary
$ make install-systemd # Will install the userland systemd service to start the server
$ make install-full # will do both
# this will remove it
$ make uninstall
```You might also need to `pip install -r requirements.txt`
## How do I use it ?
### Add the segment to powerline
This will use the `time` plugin. In your powerline theme, add the following:
```json
{
"function": "gowerline.gowerline.gwl",
"priority": 10,
"args": {
"function": "time"
}
}
```Every plugin exposes one or more `function` that you have to reference in your powerline config. This will effectively
be passed down to the Go code, as long as every other variable you add in this JSON.The Gowerline config itself lives in `~/.gowerline/server.yaml`
```yaml
debug: false
listen:
# use port to listen over HTTP, this is
# not the recommended, use the socket instead
# port: 6666
unix: ~/.gowerline/server.sock
plugins:
- name: time
config:
# no config needed
- name: network
config:
ipService: https://checkip.amazonaws.com/
- name: finnhub
# toggle to true to actually load the plugin
disabled: true
config:
token: YOUR_FINHUB_TOKEN
tickers:
- CFLT
- AAPL
- FB
- name: vault
config:
# no config needed
- name: colourenv
config:
variables:
ENV:
- regex: stag
highlightGroup: "information:priority"
- regex: devel
highlightGroup: "information:regular"
- regex: prod
highlightGroup: "warning:regular"
- name: bash
config:
commands:
date:
cmd: "date"
interval: 30
highlightGroup: "information:regular"
kubeContext:
cmd: "kubectl config get-contexts --no-headers | grep '*' | awk '{ print $3 }'"
interval: 5
highlightGroup: "gwl:kube_context"
```## The command line
The `gowerline` binary is also a commandline tool that allows you to interract with the server.
You need to add the binary to your path like so:
```bash
export PATH=${PATH}:${HOME}/.gowerline/bin
```You can list plugins and get help about a specific plugin like so:
```
$ gowerline plugin list
+-----------+--------------------------------+--------------------------------+---------+
| NAME | DESCRIPTION | AUTHOR | VERSION |
+-----------+--------------------------------+--------------------------------+---------+
| bash | Executes bash commands on | Thomas Maurice | 0.0.1 |
| | a schedule and returns the | | |
| | result | | |
| colourenv | Displays the content of env | Thomas Maurice | 0.0.1 |
| | vars with colours depending on | | |
| | matched regexes | | |
| finnhub | Returns information about the | Thomas Maurice | 0.0.1 |
| | stock price of certain tickers | | |
| network | Gather information about your | Thomas Maurice | devel |
| | network connectivity | | |
| time | Shows time, it is a debug | Thomas Maurice | 0.0.1 |
| | segment | | |
| vault | Gathers information about | Thomas Maurice | 0.0.1 |
| | the current Vault token and | | |
| | formats the result | | |
+-----------+--------------------------------+--------------------------------+---------+
```You can also get help about a specific plugin, it will tell you what functions ship with a plugin and the arguments to include in your powerline json config:
```
./bin/gowerline-v0.0.3-15-2d4a3be-dirty-thomas_linux_amd64 plugin functions bash
+---------------+--------------------------------+----------+----------------------------+
| FUNCTION NAME | DESCRIPTION | ARGUMENT | ARGUMENT HELP |
+---------------+--------------------------------+----------+----------------------------+
| bash | Runs bash functions at regular | | |
| | intervals and displays the | | |
| | output | | |
| | | cmd | Name of the command to run |
+---------------+--------------------------------+----------+----------------------------+
```You can also test what is going to be returned, instead of messing with a cURL command:
```
./bin/gowerline-v0.0.3-15-2d4a3be-dirty-thomas_linux_amd64 plugin run-function bash -a cmd=kubeContext -o json
[
{
"contents": "kubernetes",
"highlight_groups": [
"gwl:kube_context",
"information:regular"
]
}
]
```## How do I extend it ?
Go have a look at the [example plugin](https://github.com/thomas-maurice/gowerline/blob/master/plugins/sample_plugin/README.md). It should
be easy to understand. Feel free to copy it in the `plugins/` directory and fill in the blanks.The `Makefile` is designed so that if you run `make plugins` your new source will be picked up and compiled to `bin/plugins/`
The plugins are complied as Go plugins (essentialy `.so` libraries) that are loaded by the main daemon.