improvements
This commit is contained in:
1 parent
3d122b5022
commit
bf1dca3bc4
12 files changed
+303
-103
No files matched your search
Binary file not shown.
+88
-15
@@ -5,7 +5,8 @@ import yaml
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
from datetime import datetime
|
||||
import datetime
|
||||
import builtins
|
||||
from pathlib import Path
|
||||
import re
|
||||
from typing import List, Union, Optional, Dict, Any
|
||||
@@ -50,6 +51,7 @@ class OnyxCLI:
|
||||
vault_path = self._get_vault_path(vault_name)
|
||||
return vault_name, vault_path
|
||||
|
||||
|
||||
def _get_daily_note_settings(self, vault_path: Path) -> Dict[str, Any]:
|
||||
"""
|
||||
Get daily note settings from Periodic Notes plugin (if enabled),
|
||||
@@ -298,13 +300,13 @@ class OnyxCLI:
|
||||
# Use ISO week number
|
||||
year_format = 'yyyy' if 'yyyy' in settings['format'] else ('YYYY' if 'YYYY' in settings['format'] else 'yy')
|
||||
if year_format == 'yyyy' or year_format == 'YYYY':
|
||||
year = datetime.now().strftime('%G') # ISO year (4 digits)
|
||||
year = datetime.datetime.now().strftime('%G') # ISO year (4 digits)
|
||||
else:
|
||||
year = datetime.now().strftime('%g') # ISO year (2 digits)
|
||||
week = datetime.now().strftime('%V') # ISO week number
|
||||
year = datetime.datetime.now().strftime('%g') # ISO year (2 digits)
|
||||
week = datetime.datetime.now().strftime('%V') # ISO week number
|
||||
filename = f"{year}-W{week}"
|
||||
else:
|
||||
filename = datetime.now().strftime(date_format)
|
||||
filename = datetime.datetime.now().strftime(date_format)
|
||||
|
||||
# Get template content if specified
|
||||
content = ""
|
||||
@@ -443,6 +445,11 @@ class OnyxCLI:
|
||||
if not note_path.suffix:
|
||||
note_path = note_path.with_suffix('.md')
|
||||
|
||||
if not note_path.exists():
|
||||
matches = list(vault_path.rglob(f"{note_name}.md"))
|
||||
if matches:
|
||||
note_path = matches[0]
|
||||
|
||||
if not note_path.exists():
|
||||
raise click.UsageError(f"Note {note_name} does not exist")
|
||||
|
||||
@@ -468,6 +475,11 @@ class OnyxCLI:
|
||||
if not note_path.suffix:
|
||||
note_path = note_path.with_suffix('.md')
|
||||
|
||||
if not note_path.exists():
|
||||
matches = list(vault_path.rglob(f"{note_name}.md"))
|
||||
if matches:
|
||||
note_path = matches[0]
|
||||
|
||||
if not note_path.exists():
|
||||
raise click.UsageError(f"Note {note_name} does not exist")
|
||||
|
||||
@@ -495,6 +507,11 @@ class OnyxCLI:
|
||||
if not note_path.suffix:
|
||||
note_path = note_path.with_suffix('.md')
|
||||
|
||||
if not note_path.exists():
|
||||
matches = list(vault_path.rglob(f"{note_name}.md"))
|
||||
if matches:
|
||||
note_path = matches[0]
|
||||
|
||||
if not note_path.exists():
|
||||
raise click.UsageError(f"Note {note_name} does not exist")
|
||||
|
||||
@@ -513,6 +530,11 @@ class OnyxCLI:
|
||||
if not note_path.suffix:
|
||||
note_path = note_path.with_suffix('.md')
|
||||
|
||||
if not note_path.exists():
|
||||
matches = list(vault_path.rglob(f"{note_name}.md"))
|
||||
if matches:
|
||||
note_path = matches[0]
|
||||
|
||||
if not note_path.exists():
|
||||
raise click.UsageError(f"Note {note_name} does not exist")
|
||||
|
||||
@@ -558,14 +580,30 @@ class OnyxCLI:
|
||||
|
||||
@click.group(name='ob-cli')
|
||||
def cli():
|
||||
"""Onyx CLI - Interact with Obsidian from the command line"""
|
||||
"""Onyx CLI - Interact with Obsidian vaults from the command line
|
||||
|
||||
Manage your Obsidian notes, frontmatter, and periodic notes directly from the terminal.
|
||||
|
||||
EXAMPLES:
|
||||
ob-cli open "my-note"
|
||||
ob-cli daily
|
||||
ob-cli frontmatter "my-note" --view --key "tags"
|
||||
ob-cli --version
|
||||
|
||||
For more help on a specific command:
|
||||
ob-cli COMMAND --help
|
||||
"""
|
||||
pass
|
||||
|
||||
@cli.command()
|
||||
@click.argument('vault_name')
|
||||
@click.option('--path', help="Path to the vault directory")
|
||||
def set_default(vault_name, path):
|
||||
"""Set the default vault for future operations"""
|
||||
"""Set or switch the default vault
|
||||
|
||||
USAGE:
|
||||
ob-cli set-default VAULT_NAME --path /path/to/vault
|
||||
"""
|
||||
# Convert Windows backslashes to forward slashes if needed
|
||||
if path:
|
||||
path = str(Path(path))
|
||||
@@ -573,20 +611,29 @@ def set_default(vault_name, path):
|
||||
|
||||
@cli.command()
|
||||
def print_default():
|
||||
"""Print the current default vault and its path"""
|
||||
"""Display the currently configured default vault and its path"""
|
||||
OnyxCLI().print_default()
|
||||
|
||||
@cli.command()
|
||||
@click.argument('note_name')
|
||||
@click.option('--vault', help="Vault name (if not using default)")
|
||||
def open(note_name, vault):
|
||||
"""Open a note in Obsidian"""
|
||||
"""Open a note in Obsidian
|
||||
|
||||
Searches for the note in the vault and opens it in Obsidian. Supports nested directories.
|
||||
|
||||
USAGE:
|
||||
ob-cli open "my-note"
|
||||
ob-cli open "folder/my-note"
|
||||
"""
|
||||
OnyxCLI().open_note(note_name, vault)
|
||||
|
||||
@cli.command()
|
||||
@click.option('--vault', help="Vault name (if not using default)")
|
||||
def daily(vault):
|
||||
"""Create or open today's daily note"""
|
||||
"""Create or open today's daily note
|
||||
|
||||
Uses Obsidian's daily notes plugin settings (format, folder, template) if configured."""
|
||||
OnyxCLI().daily_note(vault)
|
||||
|
||||
@cli.command()
|
||||
@@ -621,14 +668,19 @@ def yearly(vault):
|
||||
@click.option('--append', is_flag=True, help="Append to existing note")
|
||||
@click.option('--open', 'open_after', is_flag=True, help="Open note after creation")
|
||||
def create(note_name, content, vault, overwrite, append, open_after):
|
||||
"""Create a new note in the vault"""
|
||||
"""Create or modify a note in the vault
|
||||
|
||||
USAGE:
|
||||
ob-cli create "my-note"
|
||||
ob-cli create "my-note" --content "Some content" --open
|
||||
"""
|
||||
OnyxCLI().create_note(note_name, content, vault, overwrite, append, open_after)
|
||||
|
||||
@cli.command()
|
||||
@click.argument('note_name')
|
||||
@click.option('--vault', help="Vault name (if not using default)")
|
||||
def print_note(note_name, vault):
|
||||
"""Print the contents of a note"""
|
||||
"""Display the full contents of a note in the terminal"""
|
||||
OnyxCLI().print_note(note_name, vault)
|
||||
|
||||
@cli.command()
|
||||
@@ -637,14 +689,21 @@ def print_note(note_name, vault):
|
||||
@click.option('--vault', help="Vault name (if not using default)")
|
||||
@click.option('--open', 'open_after', is_flag=True, help="Open note after moving")
|
||||
def move(current_path, new_path, vault, open_after):
|
||||
"""Move/rename a note and update all internal links"""
|
||||
"""Move or rename a note and auto-update internal links
|
||||
|
||||
Automatically updates all [[links]] pointing to this note in other vault files.
|
||||
|
||||
USAGE:
|
||||
ob-cli move "old-name" "new-name"
|
||||
ob-cli move "old-folder/note" "new-folder/note"
|
||||
"""
|
||||
OnyxCLI().move_note(current_path, new_path, vault, open_after)
|
||||
|
||||
@cli.command()
|
||||
@click.argument('note_path')
|
||||
@click.option('--vault', help="Vault name (if not using default)")
|
||||
def delete(note_path, vault):
|
||||
"""Delete a note"""
|
||||
"""Permanently delete a note from the vault"""
|
||||
OnyxCLI().delete_note(note_path, vault)
|
||||
|
||||
@cli.command(name='frontmatter')
|
||||
@@ -657,7 +716,15 @@ def delete(note_path, vault):
|
||||
@click.option('--value', help="Value to set or check for")
|
||||
@click.option('--vault', help="Vault name (if not using default)")
|
||||
def frontmatter_command(note_name, edit, view, clear, delete, key, value, vault):
|
||||
"""Manage note frontmatter"""
|
||||
"""Manage YAML frontmatter in notes
|
||||
|
||||
Must specify exactly one action: --edit, --view, --clear, or --delete
|
||||
|
||||
USAGE:
|
||||
ob-cli frontmatter "my-note" --view --key "tags"
|
||||
ob-cli frontmatter "my-note" --edit --key "tags" --value "project,work"
|
||||
ob-cli frontmatter "my-note" --delete --key "date"
|
||||
"""
|
||||
cli = OnyxCLI()
|
||||
if sum([edit, view, clear, delete]) != 1:
|
||||
raise click.UsageError("Exactly one of --edit, --view, --clear, or --delete must be specified")
|
||||
@@ -671,5 +738,11 @@ def frontmatter_command(note_name, edit, view, clear, delete, key, value, vault)
|
||||
elif delete:
|
||||
cli.frontmatter_delete(note_name, key, vault)
|
||||
|
||||
@cli.command()
|
||||
@click.version_option(version='0.0.1', prog_name='onyx')
|
||||
def version():
|
||||
"""Display version information"""
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
cli()
|
||||
Reference in new issue
Block a user