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

[POC] Use default editor to edit a note #44

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

Drarig29
Copy link

@Drarig29 Drarig29 commented Jun 2, 2021

I wanted to be able to edit the existing content of my note in Vim.

Usage:

gkeep notes edit --filter-title "<title>" --text

It uses click.edit() so no library added. The only thing is that to get the optional value feature for Click options (implemented in pallets/click#1618) I needed to upgrade the version of click.

So I added this in the requirements.

Note:

The function click.edit() detects the editor, and it uses the environment variable EDITOR.

So you can add export EDITOR=vim in your ~/.bashrc.

@Drarig29
Copy link
Author

Drarig29 commented Jun 2, 2021

There is a bug when I want to edit a note with checkboxes:

Traceback (most recent call last):
  File "/usr/bin/gkeep", line 33, in <module>
    sys.exit(load_entry_point('gkeep==1.0.0', 'console_scripts', 'gkeep')())
  File "/home/corentin/.local/lib/python3.9/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/home/corentin/.local/lib/python3.9/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/home/corentin/.local/lib/python3.9/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/corentin/.local/lib/python3.9/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/corentin/.local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/corentin/.local/lib/python3.9/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/home/corentin/.local/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/lib/python3.9/site-packages/gkeep-1.0.0-py3.9.egg/google_keep_tasks/notes.py", line 244, in edit_note
    setattr(note, param, value)
AttributeError: can't set attribute

I will try to fix this later.

@Drarig29 Drarig29 changed the title Use default editor to edit a note [WIP] Use default editor to edit a note Jun 3, 2021
@Drarig29 Drarig29 changed the title [WIP] Use default editor to edit a note [POC] Use default editor to edit a note Jun 5, 2021
@Drarig29
Copy link
Author

Drarig29 commented Jun 5, 2021

It does work now. The only thing not supported is reordering existing items because it was a bit harder to keep track of. Honestly, it was feasible but I lost the desire to use this CLI because of the slowness of the requests (the fault of a the unofficial API) and especially because Google always disconnects me on my phone because of the amount of requests I'm making while debugging.

Anyway. This is just a POC, maybe it could be added in the CLI or in the API.

Basically, when a note contains checkboxes, the following content is opened in your default editor:

1622893820837.80111263823      | - [ ] Run errands
179dc848061.5a20b8df26c0e61e   | - [ ] Go run errands
179dc85887a.fca1e7828db0241c   |   - [ ] Chocolate
179dc85887c.04bdf79980ae2c04   |   - [ ] Tomatoes
179dc85887d.cd07042d9a89787d   | - [x] Play video games
179dc85887d.3ae127911e2518ae   |   - [x] Don't die

I used Markdown checkboxes because it's easier to edit manually than the Unicode checkboxes.

The item IDs are needed to be able to keep track of the changes on each item, so that the changes can be done programmatically on each edited item.

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

Successfully merging this pull request may close these issues.

1 participant