summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--github-contributions-widget/README.md42
-rw-r--r--github-contributions-widget/github-contributions-widget.lua96
-rw-r--r--github-contributions-widget/screenshot.jpgbin0 -> 14613 bytes
-rw-r--r--github-contributions-widget/screenshot1.jpgbin0 -> 10879 bytes
-rw-r--r--github-contributions-widget/screenshot2.jpgbin0 -> 6164 bytes
5 files changed, 138 insertions, 0 deletions
diff --git a/github-contributions-widget/README.md b/github-contributions-widget/README.md
new file mode 100644
index 0000000..328b22e
--- /dev/null
+++ b/github-contributions-widget/README.md
@@ -0,0 +1,42 @@
+# Github Contributions Widget
+
+Shows the contribution graph, similar to the one on the github profile page:
+
+![screenshot](./screenshot.jpg)
+
+## Customization
+
+It is possible to customize the widget by providing a table with all or some of the following config parameters:
+
+| Name | Default | Description |
+|---|---|---|
+| `username` | 'streetturtle' | Username |
+| `days` | `365` | Number of days in the past, more days - wider the widget |
+| `empty_color` | `beautiful.bg_normal` | Color of the days with no contributions |
+| `with_border` | `true` | Should the graph contains border or not |
+| `margin_top` | `1` | Top margin |
+
+Few more screenshots:
+
+1000 days:
+![screenshot1](./screenshot1.jpg)
+
+No borders:
+![screenshot2](./screenshot2.jpg)
+
+
+## Installation
+
+Clone/download repo under **~/.config/awesome** and use widget in **rc.lua**:
+
+```lua
+local github_contributions_widget = require("awesome-wm-widgets.github-contributions-widget.github-contributions-widget")
+...
+s.mytasklist, -- Middle widget
+ { -- Right widgets
+ layout = wibox.layout.fixed.horizontal,
+ ...
+ -- default
+ github_contributions_widget({username = '<your username>'}),
+ ...
+```
diff --git a/github-contributions-widget/github-contributions-widget.lua b/github-contributions-widget/github-contributions-widget.lua
new file mode 100644
index 0000000..3025d17
--- /dev/null
+++ b/github-contributions-widget/github-contributions-widget.lua
@@ -0,0 +1,96 @@
+-------------------------------------------------
+-- Github Contributions Widget for Awesome Window Manager
+-- Shows the contributions graph
+-- More details could be found here:
+-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/github-contributions-widget
+
+-- @author Pavel Makhov
+-- @copyright 2020 Pavel Makhov
+-------------------------------------------------
+
+local awful = require("awful")
+local wibox = require("wibox")
+local beautiful = require("beautiful")
+
+local GET_CONTRIBUTIONS_CMD = [[bash -c "curl -s https://github-contributions.now.sh/api/v1/%s | jq -r '[.contributions[] | select ( .date | strptime(\"%%Y-%%m-%%d\") | mktime < now)][:%s]| .[].color'"]]
+-- in case github-contributions.now.sh stops working contributions can be scrapped from the github.com with the command below. Note that the order is reversed.
+local GET_CONTRIBUTIONS_CMD_FALLBACK = [[bash -c "curl -s https://github.com/users/%s/contributions | grep -o '\" fill=\"\#[0-9a-fA-F]\{6\}\" da' | grep -o '\#[0-9a-fA-F]\{6\}'"]]
+
+local github_contributions_widget = wibox.widget{
+ reflection = {
+ horizontal = true,
+ vertical = true,
+ },
+ widget = wibox.container.mirror
+}
+
+local function worker(args)
+
+ local args = args or {}
+
+ local username = args.username or 'streetturtle'
+ local days = args.days or 365
+ local empty_color = args.empty_color or beautiful.bg_normal
+ local with_border = args.with_border
+ local margin_top = args.margin_top or 1
+
+ if with_border == nil then with_border = true end
+
+ local function hex2rgb(hex)
+ if hex == '#ebedf0' then hex = empty_color end
+ hex = tostring(hex):gsub("#","")
+ return tonumber("0x" .. hex:sub(1, 2)),
+ tonumber("0x" .. hex:sub(3, 4)),
+ tonumber("0x" .. hex:sub(5, 6))
+ end
+
+ local function get_square(color)
+ local r, g, b = hex2rgb(color)
+
+ return wibox.widget{
+ fit = function(self, context, width, height)
+ return 3, 3
+ end,
+ draw = function(self, context, cr, width, height)
+ cr:set_source_rgb(r/255, g/255, b/255)
+ cr:rectangle(0, 0, with_border and 2 or 3, with_border and 2 or 3)
+ cr:fill()
+ end,
+ layout = wibox.widget.base.make_widget
+ }
+ end
+
+ local col = {layout = wibox.layout.fixed.vertical}
+ local row = {layout = wibox.layout.fixed.horizontal}
+ local a = 5 - os.date('%w')
+ for i = 0, a do
+ table.insert(col, get_square('#ebedf0'))
+ end
+
+ local update_widget = function(widget, stdout, _, _, _)
+ for colors in stdout:gmatch("[^\r\n]+") do
+ if a%7 == 0 then
+ table.insert(row, col)
+ col = {layout = wibox.layout.fixed.vertical}
+ end
+ table.insert(col, get_square(colors))
+ a = a + 1
+ end
+ github_contributions_widget:setup(
+ {
+ row,
+ top = margin_top,
+ layout = wibox.container.margin
+ }
+ )
+ end
+
+ awful.spawn.easy_async(string.format(GET_CONTRIBUTIONS_CMD, username, days),
+ function(stdout, stderr)
+ update_widget(github_contributions_widget, stdout)
+ end)
+
+ return github_contributions_widget
+end
+
+return setmetatable(github_contributions_widget, { __call = function(_, ...) return worker(...) end })
diff --git a/github-contributions-widget/screenshot.jpg b/github-contributions-widget/screenshot.jpg
new file mode 100644
index 0000000..15ad456
--- /dev/null
+++ b/github-contributions-widget/screenshot.jpg
Binary files differ
diff --git a/github-contributions-widget/screenshot1.jpg b/github-contributions-widget/screenshot1.jpg
new file mode 100644
index 0000000..d1eeb44
--- /dev/null
+++ b/github-contributions-widget/screenshot1.jpg
Binary files differ
diff --git a/github-contributions-widget/screenshot2.jpg b/github-contributions-widget/screenshot2.jpg
new file mode 100644
index 0000000..5ce47f2
--- /dev/null
+++ b/github-contributions-widget/screenshot2.jpg
Binary files differ