take-note-cli 1.2.2__tar.gz → 2.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: take-note-cli
3
- Version: 1.2.2
3
+ Version: 2.1.0
4
4
  Summary: Create and open notes in your favourite editor.
5
5
  Home-page: https://github.com/wsinned/take-note
6
6
  License: MIT
@@ -21,27 +21,47 @@ Classifier: Programming Language :: Python :: 3.10
21
21
  Classifier: Programming Language :: Python :: 3.11
22
22
  Classifier: Programming Language :: Python :: 3.12
23
23
  Classifier: Topic :: Utilities
24
+ Requires-Dist: confuse (>=2.0,<3.0)
24
25
  Project-URL: Repository, https://github.com/wsinned/take-note
25
26
  Description-Content-Type: text/markdown
26
27
 
27
28
  # Take Note
28
29
 
29
- **Create and open notes in your favourite editor.**
30
+ **Create, organise and open notes in your favourite editor.**
31
+
32
+ I like having a quick, reliable and repeatable way of taking notes. If I have to open an editor, navigate to the correct file, or create one in the correct place when it doesn't exist, then I find that I end up taking notes in random places. With Take Note, I have a few simple aliases set up so that typing thisWeek in my shell gets me to the right place in my DropBox with a new file, created from a template so that eveything is consistent, if needed. This really scratches my itch. If it works for you great! If not, create your own solution.
30
33
 
31
34
  ## Features
32
35
 
33
- - Written in Python with no runtime dependencies.
34
- - Works on Python 3.8 - 3.11.
36
+ - Written in Python with minimal runtime dependencies. Initially there were none, but I recently added Confuse (in v2.0.0) to allow a config file to do some of the heavy lifting that made aliases cumbersome.
37
+ - Works on Python 3.8 - 3.13.
35
38
  - Open notes files for specified week using the `code` command line for VS Code.
36
39
  - --thisWeek, --lastWeek and --nextWeek are supported.
37
40
  - Organises notes in a date based folder structure from your root notes folder, e.g. 2023/08
38
- - The default folder is $HOME/Notes
41
+ - The default folder is $HOME/Notes. I prefer to keep them in Google Drive or DropBox so I can access from mobile, tablet or my spare laptop.
39
42
  - set the root notes folder using --notesFolder
40
43
  - Choose which editor to use with --editor
44
+ - VSCode and Obsidian are supported with dedicated handlers
45
+ - Fallback generic handler will open anything ou can call from the terminal e.g. vi, emacs.
41
46
  - Specify a VS Code workspace to open along with the note file with --workspace
42
- - This will override the --editor setting to `code`
47
+ - This will automatically override the --editor setting to `code`. I have my default workspace set up with:
48
+ - Zen mode
49
+ - Word wrap
43
50
  - Specify a template file relative to the root notes folder to use when a new file is created using --template. This also performs a simple replacement of the text HEADER_DATE with the date formatted as "%A %d %B %Y" to use in the document title.
44
51
  - Support for batch creation of files in advance. This is useful if you use a device where you can edit files, but can't easily create them. Use --batch 5 along with any of the --*Week options to create that week and the following 4 weeks too.
52
+ - Config file allows base options to be set and reduce command line arguments needed.
53
+
54
+ ### Obsidian Integration
55
+
56
+ Support for opening using [Obsidian application uris](https://help.obsidian.md/Extending+Obsidian/Obsidian+URI):
57
+
58
+ ```bash
59
+ xdg-open "obsidian://open?path=/home/wsinned/Documents/Personal/WorkNotes/2024/11/2024-11-11-Weekly-log.md
60
+
61
+ ```
62
+ This handler opens the vault 'Personal' and the note file in the WorkNotes/2024/11/ folder of the vault.
63
+
64
+ The command called adapts according to `sys.platform` e.g. `open`, `start` or `xdg-open`.
45
65
 
46
66
  ## Future features
47
67
 
@@ -63,9 +83,23 @@ pipx install git+https://github.com/wsinned/take-note
63
83
 
64
84
  ## Usage
65
85
 
86
+ ### Config File
87
+
88
+ A basic config file will be created in ~/.config/TakeNote/config.yaml if it doesn't already exist. Specifying default values here simplifies use of the command line by reducing the number of options needed to be supplied or added to an alias.
89
+
90
+ #### Config File Default Options
91
+
92
+ - notesFolder: Notes
93
+ - editor: code
94
+ - workspace:
95
+ - template:
96
+ - batch:
97
+ - verbose: False
98
+
66
99
  ### Command Line
67
100
 
68
- Specify a folder using the --notesFolder option, otherwise $HOME/Notes will be used
101
+ Command line arguments will override any specified in the config file.
102
+ Specify a folder using the --notesFolder option.
69
103
  A week option must be supplied from --thisWeek, --lastWeek or --nextWeek
70
104
 
71
105
  ```bash
@@ -137,6 +171,9 @@ ruff . --config pyproject.toml
137
171
  # run the tests without activating a shell
138
172
  poetry run pytest
139
173
 
174
+ # run the installed app
175
+ poetry run take-note-cli --thisWeek
176
+
140
177
  # exit the shell
141
178
  exit
142
179
  ```
@@ -1,21 +1,40 @@
1
1
  # Take Note
2
2
 
3
- **Create and open notes in your favourite editor.**
3
+ **Create, organise and open notes in your favourite editor.**
4
+
5
+ I like having a quick, reliable and repeatable way of taking notes. If I have to open an editor, navigate to the correct file, or create one in the correct place when it doesn't exist, then I find that I end up taking notes in random places. With Take Note, I have a few simple aliases set up so that typing thisWeek in my shell gets me to the right place in my DropBox with a new file, created from a template so that eveything is consistent, if needed. This really scratches my itch. If it works for you great! If not, create your own solution.
4
6
 
5
7
  ## Features
6
8
 
7
- - Written in Python with no runtime dependencies.
8
- - Works on Python 3.8 - 3.11.
9
+ - Written in Python with minimal runtime dependencies. Initially there were none, but I recently added Confuse (in v2.0.0) to allow a config file to do some of the heavy lifting that made aliases cumbersome.
10
+ - Works on Python 3.8 - 3.13.
9
11
  - Open notes files for specified week using the `code` command line for VS Code.
10
12
  - --thisWeek, --lastWeek and --nextWeek are supported.
11
13
  - Organises notes in a date based folder structure from your root notes folder, e.g. 2023/08
12
- - The default folder is $HOME/Notes
14
+ - The default folder is $HOME/Notes. I prefer to keep them in Google Drive or DropBox so I can access from mobile, tablet or my spare laptop.
13
15
  - set the root notes folder using --notesFolder
14
16
  - Choose which editor to use with --editor
17
+ - VSCode and Obsidian are supported with dedicated handlers
18
+ - Fallback generic handler will open anything ou can call from the terminal e.g. vi, emacs.
15
19
  - Specify a VS Code workspace to open along with the note file with --workspace
16
- - This will override the --editor setting to `code`
20
+ - This will automatically override the --editor setting to `code`. I have my default workspace set up with:
21
+ - Zen mode
22
+ - Word wrap
17
23
  - Specify a template file relative to the root notes folder to use when a new file is created using --template. This also performs a simple replacement of the text HEADER_DATE with the date formatted as "%A %d %B %Y" to use in the document title.
18
24
  - Support for batch creation of files in advance. This is useful if you use a device where you can edit files, but can't easily create them. Use --batch 5 along with any of the --*Week options to create that week and the following 4 weeks too.
25
+ - Config file allows base options to be set and reduce command line arguments needed.
26
+
27
+ ### Obsidian Integration
28
+
29
+ Support for opening using [Obsidian application uris](https://help.obsidian.md/Extending+Obsidian/Obsidian+URI):
30
+
31
+ ```bash
32
+ xdg-open "obsidian://open?path=/home/wsinned/Documents/Personal/WorkNotes/2024/11/2024-11-11-Weekly-log.md
33
+
34
+ ```
35
+ This handler opens the vault 'Personal' and the note file in the WorkNotes/2024/11/ folder of the vault.
36
+
37
+ The command called adapts according to `sys.platform` e.g. `open`, `start` or `xdg-open`.
19
38
 
20
39
  ## Future features
21
40
 
@@ -37,9 +56,23 @@ pipx install git+https://github.com/wsinned/take-note
37
56
 
38
57
  ## Usage
39
58
 
59
+ ### Config File
60
+
61
+ A basic config file will be created in ~/.config/TakeNote/config.yaml if it doesn't already exist. Specifying default values here simplifies use of the command line by reducing the number of options needed to be supplied or added to an alias.
62
+
63
+ #### Config File Default Options
64
+
65
+ - notesFolder: Notes
66
+ - editor: code
67
+ - workspace:
68
+ - template:
69
+ - batch:
70
+ - verbose: False
71
+
40
72
  ### Command Line
41
73
 
42
- Specify a folder using the --notesFolder option, otherwise $HOME/Notes will be used
74
+ Command line arguments will override any specified in the config file.
75
+ Specify a folder using the --notesFolder option.
43
76
  A week option must be supplied from --thisWeek, --lastWeek or --nextWeek
44
77
 
45
78
  ```bash
@@ -111,6 +144,9 @@ ruff . --config pyproject.toml
111
144
  # run the tests without activating a shell
112
145
  poetry run pytest
113
146
 
147
+ # run the installed app
148
+ poetry run take-note-cli --thisWeek
149
+
114
150
  # exit the shell
115
151
  exit
116
152
  ```
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "take-note-cli"
3
- version = "1.2.2"
3
+ version = "2.1.0"
4
4
  description = "Create and open notes in your favourite editor."
5
5
  license = "MIT"
6
6
  authors = [
@@ -27,6 +27,7 @@ packages = [
27
27
 
28
28
  [tool.poetry.dependencies]
29
29
  python = "^3.8"
30
+ confuse = "^2.0"
30
31
 
31
32
  [tool.poetry.group.dev.dependencies]
32
33
  pytest = "^7.4.3"
@@ -0,0 +1,6 @@
1
+ notesFolder: Notes
2
+ editor: code
3
+ workspace:
4
+ template:
5
+ batch:
6
+ verbose: False
@@ -0,0 +1,11 @@
1
+ from pathlib import Path
2
+ from subprocess import call
3
+
4
+
5
+ def create_handler(config, file_path:Path):
6
+ args = [config["editor"], file_path]
7
+
8
+ if config["verbose"]:
9
+ print(f"Opening file with args: {args}")
10
+
11
+ return lambda: call(args)
@@ -12,7 +12,10 @@ from take_note_cli.utils.dates import (
12
12
  get_weeks_delta,
13
13
  )
14
14
  from take_note_cli.utils.args import process_args
15
- from subprocess import call
15
+ from take_note_cli.utils.config import process_config
16
+
17
+ from take_note_cli.core import generic_editor_handler, obsidian_handler
18
+ from take_note_cli.core import vscode_handler
16
19
 
17
20
 
18
21
  def calculate_week_offset(options, parser):
@@ -48,53 +51,64 @@ def get_path_for_file(week: date, folder_path):
48
51
 
49
52
 
50
53
  def create_batch_of_files(options, week, template_path):
54
+ verbose = options["verbose"]
55
+ batch = options["batch"]
56
+ notesFolder = options["notesFolder"]
51
57
  initial_note_path = None
52
- if options.batch is not None:
53
- for i in range(options.batch):
58
+
59
+ if batch is not None:
60
+ for i in range(batch):
54
61
  batch_week = week + get_weeks_delta(i)
55
- note_path, file_exists = get_path_for_file(batch_week, options.notesFolder)
62
+ note_path, file_exists = get_path_for_file(batch_week, notesFolder)
56
63
  if i == 0:
57
64
  initial_note_path = note_path
58
65
 
59
66
  if not file_exists:
60
- if options.verbose:
67
+ if verbose:
61
68
  print(f"Creating file: {note_path}")
62
69
  create_file(note_path, template_path, batch_week)
63
70
  else:
64
- initial_note_path, file_exists = get_path_for_file(week, options.notesFolder)
71
+ initial_note_path, file_exists = get_path_for_file(week, notesFolder)
65
72
  if not file_exists:
66
- if options.verbose:
73
+ if verbose:
67
74
  print(f"Creating file: {initial_note_path}")
68
75
  create_file(initial_note_path, template_path, week)
69
76
 
70
77
  return initial_note_path
71
78
 
72
79
 
73
- def open_file(folder_path, editor, note_file, verbose, workspace=None):
74
- args = [editor, note_file]
75
- if workspace:
76
- args.append(folder_path.joinpath(workspace))
77
-
78
- if verbose:
79
- print(f"Opening file with args: {args}")
80
-
81
- call(args)
80
+ def open_file(handler):
81
+ handler()
82
82
 
83
83
 
84
84
  def main(argv):
85
85
  template_path = None
86
86
  options, parser = process_args(argv)
87
+ config = process_config(options)
87
88
 
88
- if options.verbose:
89
+ if config["verbose"]:
89
90
  print("Welcome to take-note-cli")
90
- print(options)
91
+ print(f"options: {options}")
92
+ print(f"config: {config}")
91
93
 
92
94
  delta = calculate_week_offset(options, parser)
93
95
  week = get_monday(date.today()) + delta
94
96
 
95
- if options.template is not None:
96
- template_path = generate_template_path(options.notesFolder, options.template)
97
+ if config["template"] is not None:
98
+ template_path = generate_template_path(
99
+ config["notesFolder"], config["template"]
100
+ )
97
101
 
98
- note_path = create_batch_of_files(options, week, template_path)
102
+ if config["verbose"]:
103
+ print(f"Working Config: {config}")
104
+
105
+ note_path = create_batch_of_files(config, week, template_path)
106
+
107
+ if config["editor"] == "obsidian":
108
+ handler = obsidian_handler.create_handler(config, note_path)
109
+ elif config["editor"] == "code":
110
+ handler = vscode_handler.create_handler(config, note_path)
111
+ else:
112
+ handler = generic_editor_handler.create_handler(config, note_path)
99
113
 
100
- open_file(options.notesFolder, options.editor, note_path, options.verbose, options.workspace)
114
+ open_file(handler)
@@ -0,0 +1,22 @@
1
+ from subprocess import call
2
+ import sys
3
+
4
+ import urllib
5
+
6
+
7
+ def create_handler(config, note_path):
8
+ if sys.platform == "linux":
9
+ app = "xdg-open"
10
+ elif sys.platform == "darwin":
11
+ app = "open"
12
+ else:
13
+ app = "start"
14
+
15
+ command = f"obsidian://open?path={note_path}"
16
+ url = urllib.parse.quote(command, safe="/:?=&", encoding=None, errors=None)
17
+ args = [app, url]
18
+
19
+ if config["verbose"]:
20
+ print(f"Opening file with args: {args}")
21
+
22
+ return lambda: call(args)
@@ -0,0 +1,13 @@
1
+ from subprocess import call
2
+
3
+
4
+ def create_handler(config, file_path):
5
+ args = [config["editor"], file_path]
6
+
7
+ if config["workspace"] is not None:
8
+ args.append(config["notesFolder"].joinpath(config["workspace"]))
9
+
10
+ if config["verbose"]:
11
+ print(f"Opening file with args: {args}")
12
+
13
+ return lambda: call(args)
@@ -1,5 +1,4 @@
1
1
  import argparse
2
- import pathlib
3
2
  import importlib.metadata
4
3
 
5
4
  __version__ = importlib.metadata.version("take-note-cli")
@@ -24,15 +23,14 @@ def init_argparse() -> argparse.ArgumentParser:
24
23
  )
25
24
  parser.add_argument(
26
25
  "--notesFolder",
27
- default=pathlib.Path.home().joinpath("Notes"),
28
- type=pathlib.Path,
26
+ default=None,
29
27
  help="""The root path for the notes folder.
30
28
  If not supplied this defaults to the Notes
31
29
  folder in the users home folder.""",
32
30
  )
33
31
  parser.add_argument(
34
32
  "--editor",
35
- default="code",
33
+ default=None,
36
34
  help="""The editor to open the notes with.
37
35
  If not supplied this defaults 'code' for Visual Studio Code""",
38
36
  )
@@ -83,7 +81,4 @@ def process_args(args):
83
81
  parser = init_argparse()
84
82
  options = parser.parse_args(args)
85
83
 
86
- if options.workspace is not None:
87
- options.editor = "code"
88
-
89
84
  return options, parser
@@ -0,0 +1,45 @@
1
+ import pathlib
2
+ import confuse
3
+
4
+ template = {
5
+ "notesFolder": confuse.Path(cwd=pathlib.Path.home()),
6
+ "editor": None,
7
+ "workspace": None,
8
+ "template": None,
9
+ "batch": None,
10
+ "verbose": False,
11
+ }
12
+
13
+
14
+ def check_for_config_file():
15
+ config = confuse.Configuration("TakeNote")
16
+
17
+ if not config.keys():
18
+ config_filename = pathlib.Path.joinpath(
19
+ pathlib.Path(config.config_dir()), confuse.CONFIG_FILENAME
20
+ )
21
+
22
+ template_filename = pathlib.Path("./src/take_note_cli/config/config.yaml")
23
+
24
+ with open(template_filename, "r") as t:
25
+ with open(config_filename, "w") as f:
26
+ f.writelines(t.readlines())
27
+
28
+ config = check_for_config_file()
29
+
30
+ return config
31
+
32
+
33
+ def process_config(options):
34
+ config = check_for_config_file()
35
+ config.set_args(options)
36
+ valid_config = config.get(template)
37
+ workspace = None
38
+
39
+ if valid_config["workspace"] is not None:
40
+ workspace = valid_config["workspace"]
41
+
42
+ if workspace is not None:
43
+ valid_config.editor = "code"
44
+
45
+ return valid_config
File without changes