Code Monkey home page Code Monkey logo

wakatime-zsh-plugin's Introduction

wakatime-zsh-plugin

wemake.services Build Status GitHub Release

What does this plugin do?

This plugin provides zsh and wakatime integration. In other words, it tracks all time you spend in a terminal. Unlike other plugins, this one tries to keep all your spent time in the same wakatime's project.

Info

Prerequisites

Before we start you will need to run:

python3 -c "$(wget -q -O - https://raw.githubusercontent.com/wakatime/vim-wakatime/master/scripts/install_cli.py)"

This command will install Wakatime's CLI.

Installation

antigen

If you're using antigen, you can install this plugin with antigen bundle sobolevn/wakatime-zsh-plugin.

zgen

If you're using zgen, add this plugin to your init.zsh with zgen load sobolevn/wakatime-zsh-plugin.

Manual

cd ~/.oh-my-zsh/custom/plugins && git clone https://github.com/sobolevn/wakatime-zsh-plugin.git wakatime

Then set wakatime to the plugins list inside your .zshrc.

Official plugin documentation

Configuration

Wakatime supports configuration via ~/.wakatime.cfg. You will need to set your api_key.

There are number of options to set via your environment variables:

  • $WAKATIME_DO_NOT_TRACK: you can also disable tracking for some period of time by setting WAKATIME_DO_NOT_TRACK=1. defaults to false
  • $WAKATIME_TIMEOUT: to limit the time to sync with the wakatime servers, defaults to 5 seconds
  • $WAKATIME_DISABLE_OFFLINE: to disable wakatime in offline mode, defaults to false
  • $ZSH_WAKATIME_BIN: set a custom path for the wakatime cli, defaults to wakatime

Alternatives

There are several alternatives to this project:

  1. zsh-wakatime
  2. bash-wakatime
  3. fish-wakatime

See the full list here.

License

MIT. See LICENSE for more details.

wakatime-zsh-plugin's People

Contributors

alanhamlett avatar enricodeleo avatar gandarez avatar h4ckitt avatar julrich avatar modem7 avatar ronlut avatar sobolevn avatar squatto avatar tswestendorp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

wakatime-zsh-plugin's Issues

wakatime-cli not installed (Windows fix)

I use this plugin for Git Windows and the change for path in commit #15 breaks that support!

if (( ! $+commands[wakatime] )); then  <--- This works
if ! wakatime_loc="$(type -p "$wakatime_bin")"; then <--- This does not work

Maybe some type of else check using the old logic might work.

It seems that the type -p command does not actually work on windows.
So if you get questions about this in the future that might be the issue.

Include Git branch

wakatime-cli has functionality to automatically detect the Git branch that you're current working on, see here, here. However, the detection will only run if the heartbeat's entity is a file, see here.

For the ZSH plugin, I think it could be use useful to override that functionality by passing the current Git (or Mercurial?) branch in the current working directory (if existing) via --alternate-branch.

Brought up in the discussion at muety/wakapi#580 (reply in thread).

wakatime cli is not installed

When installing Wakatime via homebrew, it is accessible as wakatime-cli not wakatime (at least lately). Is it an expected behaviour? Should I link the binary in order to satisfy this plugin?

This is the terminal message:

wakatime cli is not installed, run:
$ pip install wakatime
Or check that wakatime is in PATH

Time is not tracked for now.

Whether the new cli is the go one.

wakatime cli is not installed Ubuntu

Hey guys,

When I install the plugin and set up ZSH, I get the following:

image

image

It works if I add this to my zsh config:

# Export Wakatime path
export ZSH_WAKATIME_BIN="/home/modem7/.wakatime/wakatime-cli"

this also works

# Export Wakatime path
export ZSH_WAKATIME_BIN="$HOME/.wakatime/wakatime-cli"

However this does not (still comes up with not installed):

# Export Wakatime path
export ZSH_WAKATIME_BIN="~/.wakatime/wakatime-cli"

Further testing: I've also added ls -la ~/.wakatime to my zsh config, and it properly outputs the .wakatime folder in my home directory.

Not quite sure where the issue is.

Would it be worthwhile changing the config from local wakatime_bin="${ZSH_WAKATIME_BIN:=~/.wakatime/wakatime-cli}" to local wakatime_bin="${ZSH_WAKATIME_BIN:=$HOME/.wakatime/wakatime-cli}"

Address review

User @romkatv provided a wonderful review of the code: https://www.reddit.com/r/zsh/comments/cajcni/wakatime_zsh_integration_track_how_much_time_you/eta6ti1/

You want to hook preexec, not precmd.
Don't define globals with names bound to clash. E.g., PLUGIN_NAME.
It's better to use : {X:=Y} instead of X=${X:-Y}. However, in your code it's even better to not modify WAKATIME_TIMEOUT at all.
That $() in _wakatime_call is not doing what you think it does. Remove the parens.
Use &! instead of & to avoid polluting jobs.
Forks are slow. Avoid them. E.g., something like _should_work_online is definitely not worth the cost of a fork.
There is ${foo:t} to get the basename of a directory.
To check whether wakatime command exists, use if $(( $+commands[wakatime] )); ....
Don't trap signals. Traps are global, it's rude to hog them for yourself.
Prefix your functions with your project name such as _wakatime_. Try to limit the number of functions you define.

Read project from `[projectmap]` in `.wakatime.cfg`, if set

Would be really nice, if the plugin could read the projectmap defined in .wakatime.cfg.
Could fall back / use the existing behaviour, if that doesn't exist.

As all the other IDEs I'm using (vim, VS Code, PHPStorm) already respect that entry, which results in consistent projects in wakatime, it would be really nice to match that. Because git repositories don't necessarily map to projects in a 1:1 manner.

Would be open to trying my hands on a PR, just not sure how fast I'd be... as I'm not really knowledgeable in zsh scripting.

wakatime: error: unrecognized arguments:

Hello,
after loading the plugin with

zplugin load sobolevn/wakatime-zsh-plugin

I'm seeing the following messages in the terminal:

usage: wakatime [-h] [--entity FILE] [--key KEY] [--write] [--plugin PLUGIN]
                [--time time] [--lineno LINENO] [--cursorpos CURSORPOS]
                [--entity-type ENTITY_TYPE] [--category CATEGORY]
                [--proxy PROXY] [--no-ssl-verify]
                [--ssl-certs-file SSL_CERTS_FILE] [--project PROJECT]
                [--alternate-project ALTERNATE_PROJECT] [--language LANGUAGE]
                [--local-file FILE] [--hostname HOSTNAME] [--disable-offline]
                [--hide-file-names] [--hide-project-names]
                [--hide-branch-names] [--exclude EXCLUDE]
                [--exclude-unknown-project] [--include INCLUDE]
                [--include-only-with-project-file] [--extra-heartbeats]
                [--log-file LOG_FILE] [--api-url API_URL] [--timeout TIMEOUT]
                [--sync-offline-activity SYNC_OFFLINE_ACTIVITY] [--today]
                [--config CONFIG] [--verbose] [--version]
wakatime: error: unrecognized arguments:

I didn't do any wakatime setup yet, i.e. there's no cfg file.

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.