Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/commands/view.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ nnote view

.. code-block:: text

nnote view <title> [-d <dir>]
nnote view <title> [-d <dir>] [--pager]

Print the contents of a note to stdout.

Use ``--pager`` to pipe the output through a pager (``$PAGER``, falling back
to ``less``). Useful for long notes.

.. code-block:: bash

nnote view todo
nnote view standup -d work
nnote view meeting-notes --pager
14 changes: 12 additions & 2 deletions nnote/commands/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,22 @@
help="Subdirectory within notes dir",
shell_complete=complete_directories,
)
def view(title, directory):
@click.option(
"--pager",
is_flag=True,
default=False,
help="Pipe output through $PAGER (defaults to less)",
)
def view(title, directory, pager):
"""Print the contents of a note."""
config = Config.load()
note_path = resolve_note_path(config, title, directory)

if not note_path.exists():
raise click.ClickException(f"Note not found: {note_path}")

click.echo(note_path.read_text(encoding="utf-8"), nl=False)
content = note_path.read_text(encoding="utf-8")
if pager:
click.echo_via_pager(content)
else:
click.echo(content, nl=False)