Giter Site home page Giter Site logo

codestats.nvim's Introduction

Codestats.nvim

Neovim plugin that counts your keypresses and saves statistics to Code::Stats, a free stats tracking service for programmers.

This is port of the official plugin 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

Setup

  1. Get a Code::Stats account and copy your API key from the Code::Stats machine page.

  2. Install and configure code-stats-nvim

-- Lazy.nvim
{
  'liljaylj/codestats.nvim',
  dependencies = { 'nvim-lua/plenary.nvim' },
  event = { 'TextChanged', 'InsertEnter' },
  cmd = { 'CodeStatsXpSend', 'CodeStatsProfileUpdate' },
  config = function()
    require('codestats').setup {
      username = '<your user name>',  -- needed to fetch profile data
      base_url = 'https://codestats.net',  -- codestats.net base url
      api_key = '<your 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
  • :CodeStatsProfileUpdate — manually pull profile data from Code::Stats

Events

  • CodeStatsXpSent — triggers when XP is succesfully sent to Code::Stats
  • CodeStatsProfileUpdated — triggers when profile data successfully pulled from Code::Stats

API

local codestats = require 'codestats'

codestats.get_xp()  -- get total xp for profile
codestats.get_xp(<buffer id>)  -- get xp for language of specified buffer
codestats.get_xp(0)  -- get xp for language of current buffer

codestats.get_level()  -- get level for profile
codestats.get_level(<buffer id>)  -- get level for language of specified buffer
codestats.get_level(0)  -- get level for language of current buffer

-- utils
codestats.calculate_level(<xp>)  -- calculate level for given XP value
codestats.filetype_to_language(<ft>)  -- map language for given filetype

Tips

Neovim native statusline

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

local xp = function()
  return codestats.get_xp(0)  -- current buf language xp
end

require('lualine').setup {
  sections = { 
    lualine_x = {
      'filetype',
      {
        xp,
        fmt = function(s)
          return s and (s ~= '0' or nil) and s .. 'xp'
        end,
      },
    },
  },
}

codestats.nvim's People

Contributors

liljaylj avatar aksh1618 avatar glowsquid avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.