Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
julrich opened this issue Jun 3, 2021 · 10 comments
Open

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

julrich opened this issue Jun 3, 2021 · 10 comments

Comments

@julrich
Copy link
Contributor

julrich commented Jun 3, 2021

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.

@sobolevn
Copy link
Owner

sobolevn commented Jun 3, 2021

It might be a problem, awk is a good tool try here!

@julrich
Copy link
Contributor Author

julrich commented Jun 3, 2021

Found this for reading .ini-files in zsh: https://github.com/zdharma/zsh-string-lib/blob/master/%40str-read-ini

Another aspect: It needs to regexp-match against the array of regexps given in projectmap:
https://github.com/wakatime/wakatime#configuring
https://github.com/wakatime/komodo-wakatime/blob/master/components/wakatime/projects/projectmap.py#L2-L21

Might suck to handle / escape those regexps given as keys in .wakatime.cfg, too :/.

At least that's how it's working for the other IDE-plugins so far.

So all in all, a bit more involved. But would be really nice to have :).

@sobolevn
Copy link
Owner

sobolevn commented Jun 3, 2021

Can we parse it via wakatime CLI somehow?

@julrich
Copy link
Contributor Author

julrich commented Jun 3, 2021

Huh, that might work. Haven't look at the CLI options admittedly. Could look around how others are doing this in other plugins, too!
Will try my hands on this in the next days!

@julrich
Copy link
Contributor Author

julrich commented Jun 4, 2021

Looks like that may even be the default behavior, if the folder is not explicitly given to the CLI?

  --project PROJECT     optional project name
  --alternate-project ALTERNATE_PROJECT
                        optional alternate project name; auto-discovered
                        project takes priority

from: https://wakatime.com/help/creating-plugin#sending-file-to-wakatime-cli:executing-background-process

So possibly this part is duplicating default behaviour of the CLI?
https://github.com/sobolevn/wakatime-zsh-plugin/blob/master/wakatime.plugin.zsh#L31-L38

But I'm not sure if that behavior is restricted to entity-type file. Which would mean altering the plugin even further... would probably have to send the current path as file, with entity-type set to file. That should then enable the "default" detection described here:
https://wakatime.com/faq#rename-projects (re: one of four ways)

Any idea if that would have other, unintended consequences? Like in the way logged time is displayed inside the wakatime dashboard?

@alanhamlett
Copy link
Contributor

Looks like that may even be the default behavior, if the folder is not explicitly given to the CLI?

That's correct, but you'll need to use --alternate-project instead of --project in your clone of this zsh plugin. You will also need the new Go wakatime-cli since Python had a bug around alternate project that might cause it to be used instead of the auto-detected project.

@squatto
Copy link
Contributor

squatto commented Jun 30, 2021

Could we also add a check for a .wakatime-project file to get the project name? Based on get_project_info in wakatime and WithDetection in wakatime-cli, it takes precedence over the git folder name:

First looks for a .wakatime-project file. Second, uses the --project arg.
Third, uses the folder name from a revision control repository. Last, uses
the --alternate-project arg.

It's definitely much easier to parse than projectmap too: the first line is the project name, the optional second line is the branch name. If the branch name isn't in the file, it will try to get it from rev control (while still using the project name from the file).

Thanks!


EDIT: I submitted PR #13 to add support for the .wakatime-project file 👍🏻

@sobolevn
Copy link
Owner

PRs are welcome 🙂

@julrich
Copy link
Contributor Author

julrich commented Jun 30, 2021

Would expect the wakatime-cli to also respect .wakatime-project-files, right?
Will try my hand on a PR if I get the time, but can't promise anything right now!

@squatto
Copy link
Contributor

squatto commented Jun 30, 2021

@sobolevn I'd love to help! Time to reach into that tiny corner of my brain where I stuff my shell script knowledge 😂


Would expect the wakatime-cli to also respect .wakatime-project-files, right?
Will try my hand on a PR if I get the time, but can't promise anything right now!

@julrich yep it does check it first. Those two links in my last comment are where wakatime and wakatime-cli check for a .wakatime-project file (it's the first check so it has #1 priority):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants