Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/liljaylj/codestats.nvim
Code::Stats plugin for Neovim
https://github.com/liljaylj/codestats.nvim
Last synced: about 2 months ago
JSON representation
Code::Stats plugin for Neovim
- Host: GitHub
- URL: https://github.com/liljaylj/codestats.nvim
- Owner: liljaylj
- License: mit
- Created: 2023-03-06T09:55:42.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-01-21T07:38:57.000Z (12 months ago)
- Last Synced: 2024-08-02T18:37:28.408Z (5 months ago)
- Language: Lua
- Size: 49.8 KB
- Stars: 4
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- my-neovim-pluginlist - liljaylj/codestats.nvim - commit/liljaylj/codestats.nvim) ![](https://img.shields.io/github/commit-activity/y/liljaylj/codestats.nvim) (New features / RSS)
README
# Codestats.nvim
Neovim plugin that counts your keypresses and saves statistics to [Code::Stats](https://codestats.net), a free stats tracking service for programmers.
This is port of the [official plugin](https://gitlab.com/code-stats/code-stats-vim) written in Lua. It don't use pythonx interface (it is not a remote-plugin), instead it spawns curl process as luv asynchronous job and therefore it loads faster and don't interfere with interface rendering.
# Installation
## Requirements
- Neovim
- Curl
- [plenary.nvim](https://github.com/nvim-lua/plenary.nvim)## Setup
1) Get a Code::Stats account and copy your API key from the [Code::Stats machine page](https://codestats.net/my/machines).
2) Install and configure code-stats-nvim
```lua
-- Lazy.nvim
{
'liljaylj/codestats.nvim',
dependencies = { 'nvim-lua/plenary.nvim' },
event = { 'TextChanged', 'InsertEnter' },
cmd = { 'CodeStatsXpSend', 'CodeStatsProfileUpdate' },
config = function()
require('codestats').setup {
username = '', -- needed to fetch profile data
base_url = 'https://codestats.net', -- codestats.net base url
api_key = '',
send_on_exit = true, -- send xp on nvim exit
send_on_timer = true, -- send xp on timer
timer_interval = 60000, -- timer interval in milliseconds (minimum 1000ms to prevent DDoSing codestat.net servers)
curl_timeout = 5, -- curl request timeout in seconds
}
end,
}
```# Commands
- `:CodeStatsXpSend` — manually send XP to [Code::Stats](https://codestats.net)
- `:CodeStatsProfileUpdate` — manually pull profile data from [Code::Stats](https://codestats.net)# Events
- `CodeStatsXpSent` — triggers when XP is succesfully sent to [Code::Stats](https://codestats.net)
- `CodeStatsProfileUpdated` — triggers when profile data successfully pulled from [Code::Stats](https://codestats.net)# API
```lua
local codestats = require 'codestats'codestats.get_xp() -- get total xp for profile
codestats.get_xp() -- get xp for language of specified buffer
codestats.get_xp(0) -- get xp for language of current buffercodestats.get_level() -- get level for profile
codestats.get_level() -- get level for language of specified buffer
codestats.get_level(0) -- get level for language of current buffer-- utils
codestats.calculate_level() -- calculate level for given XP value
codestats.filetype_to_language() -- map language for given filetype
```## Tips
### Neovim native statusline
```lua
vim.opt.statusline:append [[%{luaeval("require'codestats'.get_xp()")}]] -- total xp
vim.opt.statusline:append [[%{luaeval("require'codestats'.get_xp(0)")}]] -- current buf language xp
vim.opt.statusline:append [[%{luaeval("require'codestats'.get_level()")}]] -- total level
vim.opt.statusline:append [[%{luaeval("require'codestats'.get_level(0)")}]] -- current buf language level
```### Lualine
```lua
local xp = function()
return codestats.get_xp(0) -- current buf language xp
endrequire('lualine').setup {
sections = {
lualine_x = {
'filetype',
{
xp,
fmt = function(s)
return s and (s ~= '0' or nil) and s .. 'xp'
end,
},
},
},
}
```