notes.sh
Version:
CLI and local web note-taking, bookmarking, and archiving with encryption, search, Git-backed versioning and syncing, tagging, and more in a single portable script.
1,933 lines (1,475 loc) • 265 kB
Markdown
<p align="center"></p><!-- spacer -->
<div align="center">
<img src="https://raw.githubusercontent.com/xwmx/nb/master/docs/assets/images/nb.png"
alt="nb"
width="200">
</div>
<p align="center"></p><!-- spacer -->
<div align="center">
<a href="https://github.com/xwmx/nb/actions" rel="nofollow">
<img src="https://img.shields.io/github/actions/workflow/status/xwmx/nb/tests.yml?branch=master"
alt="Build Status"
style="max-width:100%;">
</a>
</div>
<div align="center"> </div><!-- spacer -->
<br/>
`nb` is a command line and local web
note‑taking, bookmarking, archiving,
and knowledge base application
with:
- plain text data storage,
- [encryption](#password-protected-encrypted-notes-and-bookmarks),
- [filtering](#listing--filtering), [pinning](#-pinning), [#tagging](#-tagging), and [search](#-search),
- [Git](https://git-scm.com/)-backed [versioning](#-revision-history) and [syncing](#-git-sync),
- [Pandoc](https://pandoc.org/)-backed [conversion](#%EF%B8%8F-import--export),
- <a href="#-linking">[[wiki-style linking]]</a>,
- terminal and GUI web [browsing](#-browsing),
- inline [images](#-images),
- [todos](#-todos) with [tasks](#%EF%B8%8F-tasks),
- global and local [notebooks](#-notebooks),
- organization with [folders](#-folders),
- customizable [color themes](#-color-themes),
- extensibility through [plugins](#-plugins),
and more, in a single portable script.
`nb` creates notes in text-based formats like
[Markdown](https://en.wikipedia.org/wiki/Markdown),
[Org](https://orgmode.org/),
[LaTeX](https://www.latex-project.org/),
and [AsciiDoc](https://asciidoc.org/),
can work with files in any format,
can import and export notes to many document formats,
and can create private, password-protected encrypted notes and bookmarks.
With `nb`, you can write notes using
Vim,
Emacs,
VS Code,
Sublime Text,
and any other text editor you like,
as well as terminal and GUI web browsers.
`nb` works in any standard Linux / Unix environment,
including macOS and Windows via WSL.
[Optional dependencies](#optional) can be installed to enhance functionality,
but `nb` works great without them.
<div align="center">
<img src="https://xwmx.github.io/misc/nb/images/nb-theme-nb-home.png"
alt="home"
width="450">
</div>
`nb` is also a powerful [bookmarking](#-bookmarks) system featuring:
- locally-served, text-centric, distraction-free bookmark [browsing](#-browsing)
in terminal and GUI web browsers,
- local full-text search of cached page content with regular expression support,
- convenient filtering and listing,
- [Internet Archive Wayback Machine](https://archive.org/web/) snapshot lookup
for broken links,
- tagging, pinning, linking, and full integration with other `nb` features.
Page information is
downloaded,
cleaned up,
structured,
and saved
into normal Markdown documents made for humans,
so bookmarks are easy to view and edit just like any other note.
<div align="center">
<img src="https://xwmx.github.io/misc/nb/images/gui-terminal-browse.png"
alt="nb browse"
width="500">
</div>
`nb` uses [Git](https://git-scm.com/) in the background to
automatically record changes and sync notebooks with remote repositories.
`nb` can also be configured to
sync notebooks using a general purpose syncing utility like Dropbox
so notes can be edited in other apps on any device.
<div align="center">
<img src="https://xwmx.github.io/misc/nb/images/terminal-empty.png"
alt="nb list empty"
width="450">
</div>
`nb` is designed to be portable, future-focused, and vendor independent,
providing a full-featured and intuitive experience within
a highly composable multimodal user-centric text interface.
The entire program is contained within
a single [well-tested](#tests) shell script
that can be
installed, copied, or `curl`ed almost anywhere and just work,
using a strategy inspired by
[progressive enhancement](https://en.wikipedia.org/wiki/Progressive_enhancement)
for various experience improvements in more capable environments.
`nb` works great whether you have one notebook with just a few notes
or dozens of notebooks containing thousands of notes, bookmarks, and other items.
`nb` makes it easy to incorporate other tools, writing apps, and workflows.
`nb` can be used a little, a lot, once in a while, or for just a subset of features.
`nb` is flexible.
<div align="center"> </div><!-- spacer -->
<div align="center">
<sub>
📝
🔖
🔍
🌍
🔒
✅
🔄
🎨
📚
📌
📂
🌄
</sub>
</div>
<p align="center"> </p><!-- spacer -->
<div align="center">
<h1 align="center" id="nb"><code>nb</code></h1>
</div>
<div align="center">
<a href="#installation">Installation</a> ·
<a href="#overview">Overview</a>
</div>
<p align="center"></p><!-- spacer -->
<div align="center">
<a href="#-help">Help</a>
</div>
<p align="center"></p><!-- spacer -->
<div align="center">
<a href="#top"> ↑ </a>
</div>
### Installation
#### Dependencies
##### Required
- [Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell))
- `nb` works perfectly with Zsh, fish, and any other shell
set as your primary login shell,
the system just needs to have Bash available on it.
- [Git](https://git-scm.com/)
- A text editor with command line support, such as:
- [Vim](https://en.wikipedia.org/wiki/Vim_\(text_editor\)),
- [Emacs](https://en.wikipedia.org/wiki/Emacs),
- [Visual Studio Code](https://code.visualstudio.com/),
- [Sublime Text](https://www.sublimetext.com/),
- [micro](https://github.com/zyedidia/micro),
- [nano](https://en.wikipedia.org/wiki/GNU_nano),
- [Atom](https://atom.io/),
- [TextMate](https://macromates.com/),
- [MacDown](https://macdown.uranusjr.com/),
- [some of these](https://github.com/topics/text-editor),
- [and many of these.](https://en.wikipedia.org/wiki/List_of_text_editors)
##### Optional
`nb` leverages standard command line tools
and works in standard Linux / Unix environments.
`nb` also checks the environment for some additional optional tools and
uses them to enhance the experience whenever they are available.
Recommended:
- [`bat`](https://github.com/sharkdp/bat)
- [`ncat`](https://nmap.org/ncat/)
- [`pandoc`](https://pandoc.org/)
- [`rg`](https://github.com/BurntSushi/ripgrep)
- [`tig`](https://github.com/jonas/tig)
- [`w3m`](https://en.wikipedia.org/wiki/W3m)
Also supported for various enhancements:
[Ack](https://beyondgrep.com/),
[`afplay`](https://ss64.com/osx/afplay.html),
[`asciidoctor`](https://asciidoctor.org/),
[The Silver Searcher (`ag`)](https://github.com/ggreer/the_silver_searcher),
[`catimg`](https://github.com/posva/catimg),
[Chafa](https://github.com/hpjansson/chafa),
[`exa`](https://github.com/ogham/exa),
[`ffplay`](https://ffmpeg.org/ffplay.html),
[ImageMagick](https://imagemagick.org/),
[GnuPG](https://en.wikipedia.org/wiki/GNU_Privacy_Guard),
[`highlight`](http://www.andre-simon.de/doku/highlight/en/highlight.php),
[`imgcat`](https://www.iterm2.com/documentation-images.html),
[`joshuto`](https://github.com/kamiyaa/joshuto),
[kitty's `icat` kitten](https://sw.kovidgoyal.net/kitty/kittens/icat.html),
[Links](https://en.wikipedia.org/wiki/Links_(web_browser)),
[Lynx](https://en.wikipedia.org/wiki/Lynx_(web_browser)),
[Midnight Commander (`mc`)](https://en.wikipedia.org/wiki/Midnight_Commander),
[`mpg123`](https://en.wikipedia.org/wiki/Mpg123),
[MPlayer](https://en.wikipedia.org/wiki/MPlayer),
[ncat](https://nmap.org/ncat/),
[note-link-janitor](https://github.com/andymatuschak/note-link-janitor)
(via [plugin](https://github.com/xwmx/nb/blob/master/plugins/backlink.nb-plugin)),
[`pdftotext`](https://en.wikipedia.org/wiki/Pdftotext),
[Pygments](https://pygments.org/),
[Ranger](https://ranger.github.io/),
[readability-cli](https://gitlab.com/gardenappl/readability-cli),
[`rga` / ripgrep-all](https://github.com/phiresky/ripgrep-all),
[`sc-im`](https://github.com/andmarti1424/sc-im),
[`term-image`](https://github.com/AnonymouX47/term-image),
[`termpdf.py`](https://github.com/dsanson/termpdf.py),
[Tidy-Viewer (`tv`)](https://github.com/alexhallam/tv),
[`timg`](https://github.com/hzeller/timg),
[vifm](https://vifm.info/),
[`viu`](https://github.com/atanunq/viu),
[VisiData](https://www.visidata.org/)
#### macOS / Homebrew
```bash
brew install xwmx/taps/nb
```
Installing `nb` with Homebrew also installs
the recommended dependencies above
and completion scripts for Bash, Zsh, and Fish.
Install the latest development version from the respository with:
```bash
brew install xwmx/taps/nb --head
```
`nb` is also available in
[homebrew-core](https://github.com/Homebrew/homebrew-core).
Installing it together with the `bash` formula is recommended:
```bash
brew install nb bash
```
#### Ubuntu, Windows WSL, and others
##### npm
```bash
npm install -g nb.sh
```
After `npm` installation completes, run
`sudo "$(which nb)" completions install`
to install Bash and Zsh completion scripts (recommended).
On Ubuntu and WSL, you can
run [`sudo "$(which nb)" env install`](#env)
to install the optional dependencies.
*`nb` is also available under its original package name,
[notes.sh](https://www.npmjs.com/package/notes.sh),
which comes with an extra `notes` executable wrapping `nb`.*
##### Download and Install
To install as an administrator,
copy and paste one of the following multi-line commands:
```bash
# install using wget
sudo wget https://raw.github.com/xwmx/nb/master/nb -O /usr/local/bin/nb &&
sudo chmod +x /usr/local/bin/nb &&
sudo nb completions install
# install using curl
sudo curl -L https://raw.github.com/xwmx/nb/master/nb -o /usr/local/bin/nb &&
sudo chmod +x /usr/local/bin/nb &&
sudo nb completions install
```
On Ubuntu and WSL, you can
run [`sudo nb env install`](#env) to install the optional dependencies.
###### User-only Installation
To install with just user permissions, simply
add the `nb` script to your `$PATH`.
If you already have a `~/bin` directory, for example, you can
use one of the following commands:
```bash
# download with wget
wget https://raw.github.com/xwmx/nb/master/nb -O ~/bin/nb && chmod +x ~/bin/nb
# download with curl
curl -L https://raw.github.com/xwmx/nb/master/nb -o ~/bin/nb && chmod +x ~/bin/nb
```
Installing with just user permissions doesn't include
the optional dependencies or completions,
but `nb` core functionality works without them.
If you have `sudo` access and want
to install the completion scripts and dependencies, run the following command:
```bash
sudo nb env install
```
##### Make
To install with [Make](https://en.wikipedia.org/wiki/Make_(software)),
clone this repository, navigate to the clone's root directory, and run:
```bash
sudo make install
```
This will also install the completion scripts on all systems and
the recommended dependencies on Ubuntu and WSL.
##### bpkg
To install with [bpkg](https://github.com/bpkg/bpkg):
```bash
bpkg install xwmx/nb
```
##### basher
To install with [basher](https://www.basher.it/):
```bash
basher install xwmx/nb
```
#### Tab Completion
Bash, Fish, and Zsh tab completion should be enabled
when `nb` is installed using the methods above,
assuming you have the appropriate system permissions or installed with `sudo`.
If completion isn't working after installing `nb`, see the
[completion installation instructions](https://github.com/xwmx/nb/tree/master/etc).
#### Updating
When `nb` is installed using a package manager like npm or Homebrew,
use the package manager's upgrade functionality to update `nb` to
the latest version.
When installed via other methods,
`nb` can be updated to the latest version using
the [`nb update`](#update) subcommand.
## Overview
<div align="center">
<a href="#-notes"><code>📝</code> Notes</a> ·
<a href="#adding">Adding</a> ·
<a href="#listing--filtering">Listing</a> ·
<a href="#editing">Editing</a> ·
<a href="#viewing">Viewing</a> ·
<a href="#deleting">Deleting</a> ·
<a href="#-bookmarks"><code>🔖</code> Bookmarks</a> ·
<a href="#-todos"><code>✅</code> Todos</a> ·
<a href="#%EF%B8%8F-tasks"><code>✔️</code> Tasks</a> ·
<a href="#-tagging"><code>🏷</code> Tagging</a> ·
<a href="#-linking"><code>🔗</code> Linking</a> ·
<a href="#-browsing"><code>🌍</code> Browsing</a> ·
<a href="#-images"><code>🌄</code> Images</a> ·
<a href="#-zettelkasten"><code>🗂</code> Zettelkasten</a> ·
<a href="#-folders"><code>📂</code> Folders</a> ·
<a href="#-pinning"><code>📌</code> Pinning</a> ·
<a href="#-search"><code>🔍</code> Search</a> ·
<a href="#-moving--renaming"><code>↔</code> Moving & Renaming</a> ·
<a href="#-revision-history"><code>🗒</code> History</a> ·
<a href="#-notebooks"><code>📚</code> Notebooks</a> ·
<a href="#-git-sync"><code>🔄</code> Git Sync</a> ·
<a href="#%EF%B8%8F-import--export"><code>↕️</code> Import / Export</a> ·
<a href="#%EF%B8%8F-set--settings"><code>⚙️</code><code>set</code>&<code>settings</code></a> ·
<a href="#-color-themes"><code>🎨</code> Color Themes</a> ·
<a href="#-plugins"><code>🔌</code> Plugins</a> ·
<a href="#-selectors"><code>:/</code> Selectors</a> ·
<a href="#01-metadata"><code>01</code> Metadata</a> ·
<a href="#-interactive-shell"><code>❯</code> Shell</a> ·
<a href="#shortcut-aliases">Shortcuts</a> ·
<a href="#-help"><code>?</code> Help</a> ·
<a href="#-variables"><code>$</code> Variables</a> ·
<a href="#specifications">Specifications</a> ·
<a href="#tests">Tests</a>
</div>
<p align="center"></p><!-- spacer -->
<div align="center">
<a href="#nb"> ↑ </a>
</div>
<p align="center"></p><!-- spacer -->
To get started, simply run:
```bash
nb
```
`nb` sets up your initial `home` notebook the first time it runs.
By default, notebooks and notes are global (at `~/.nb`),
so they are always available to `nb`
regardless of the current working directory.
`nb` also supports [local notebooks](#global-and-local-notebooks).
### 📝 Notes
#### Adding
<p>
<sup>
<a href="#overview">↑</a> ·
<a href="#add"><code>nb add</code></a>,
<a href="#browse"><code>nb browse add</code></a>
</sup>
</p>
Use [`nb add`](#add) (shortcuts: [`nb a`](#add), [`nb +`](#add))
to create new notes:
```bash
# create a new note in your text editor
nb add
# create a new note with the filename "example.md"
nb add example.md
# create a new note containing "This is a note."
nb add "This is a note."
# create a new note with piped content
echo "Note content." | nb add
# create a new password-protected, encrypted note titled "Secret Document"
nb add --title "Secret Document" --encrypt
# create a new note in the notebook named "example"
nb example:add "This is a note."
# create a new note in the folder named "sample"
nb add sample/
```
[`nb add`](#add) with no arguments or input will open the new, blank note
in your environment's preferred text editor.
You can change your editor using
the `$EDITOR` environment variable
or [`nb set editor`](#editor).
`nb` files are [Markdown](https://daringfireball.net/projects/markdown/)
files by default. The default file type can be changed to
whatever you like
using [`nb set default_extension`](#default_extension).
[`nb add`](#add) has intelligent argument parsing
and behaves differently depending on the types of arguments it receives.
When a filename with extension is specified,
a new note with that filename is opened in the editor:
```bash
nb add example.md
```
When a string is specified, a new note is immediately created
with that string as the content and without opening the editor:
```bash
❯ nb add "This is a note."
Added: [1] 20200101000000.md
```
[`nb add <string>`](#add) is useful for quickly jotting down notes directly
via the command line. Quoting content is optional, but recommended.
When no filename is specified, [`nb add`](#add) uses the current datetime as
the filename.
[`nb add`](#add) can also receive piped content, which behaves the same as
[`nb add <string>`](#add):
```bash
# create a new note containing "Note content."
❯ echo "Note content." | nb add
Added: [6] 20200101000100.md
# create a new note containing the clipboard contents on macOS
❯ pbpaste | nb add
Added: [7] 20200101000200.md
# create a new note containing the clipboard contents using xclip
❯ xclip -o | nb add
Added: [8] 20200101000300.md
```
Content can be passed with the [`--content <content>`](#add) option,
which also creates a new note without opening the editor:
```bash
nb add --content "Note content."
```
When content is piped,
specified with [`--content <content>`](#add),
or passed as a string argument,
use the [`--edit`](#add) flag to open the file in the editor
before the change is committed.
The title, filename, and content can also be specified with long and
short options:
```bash
❯ nb add --filename "example.md" -t "Example Title" -c "Example content."
Added: [9] example.md "Example Title"
```
The [`-t <title>`](#add) / [`--title <title>`](#add) option also
sets the filename to the title,
lowercased with spaces and non-filename characters replaced with underscores:
```bash
❯ nb add --title "Example Title" "Example content."
Added: [10] example_title.md "Example Title"
```
Tags can be added with the [`--tags <tag1>,<tag2>...`](#add) option, which
takes a comma separated list of tags,
converts them to [#hashtags](#-tagging),
and inserts them between the title and content:
```bash
❯ nb add "Example content." --title "Tagged Example" --tags tag1,tag2
Added: [11] tagged_example.md "Tagged Example"
❯ nb show 11 --print
# Tagged Example
#tag1 #tag2
Example content.
```
[Search](#-search) for tagged items with
[`nb search`](#search) / [`nb q`](#search):
```bash
# search for items tagged with "#tag1"
nb search --tag tag1
# search for items tagged with "#tag1" AND "#tag2", short options
nb q -t tag1 -t tag2
# search for items tagged with "#tag1" OR "#tag2", arguments
nb q \#tag1 --or \#tag2
```
Files can be created with any file type by specifying the extension either
in the filename (`example.md`),
the extension by itself (`.md`),
or via the [`--type <type>`](#add) option (`--type md`):
```bash
# open a new Org file in the editor
nb add example.org
# open a new reStructuredText file in the editor
nb add --type rst
# open a new JavaScript file in the editor
nb add .js
```
Combining a type argument with piped clipboard content provides
a very convenient way to save code snippets using a clipboard utility such as
`pbpaste`,
`xclip`,
or [`pb`](https://github.com/xwmx/pb):
```bash
# save the clipboard contents as a JavaScript file in the current notebook
pb | nb add .js
# save the clipboard contents as a Rust file in the "rust" notebook
# using the shortcut alias `nb a`
pb | nb a rust: .rs
# save the clipboard contents as a Haskell file named "example.hs" in the
# "snippets" notebook using the shortcut alias `nb +`
pb | nb + snippets: example.hs
```
Use [`nb show`](#show) and [`nb browse`](#browse) to view code snippets
with automatic syntax highlighting and
use [`nb edit`](#edit) to open in your editor.
The [`clip` plugin](#clip) can also be used to
create notes from clipboard content.
Piping,
[`--title <title>`](#add),
[`--tags <tag-list>`](#add),
[`--content <content>`](#add),
and content passed in an argument
can be combined as needed
to create notes with content from multiple input methods and sources
using a single command:
```bash
❯ pb | nb add "Argument content." \
--title "Sample Title" \
--tags tag1,tag2 \
--content "Option content."
Added: [12] sample_title.md "Sample Title"
❯ nb show 12 --print
# Sample Title
#tag1 #tag2
Argument content.
Option content.
Clipboard content.
```
For a full list of options available for [`nb add`](#add), run
[`nb help add`](#add).
##### Password-Protected Encrypted Notes and Bookmarks
Password-protected notes and [bookmarks](#-bookmarks) are
created with the [`-e`](#add) / [`--encrypt`](#add) flag and
encrypted with AES-256 using OpenSSL by default.
GPG is also supported and can be configured with
[`nb set encryption_tool`](#encryption_tool).
Each protected note and bookmark is
encrypted individually with its own password.
When an encrypted item is viewed, edited, or opened,
`nb` will simply prompt for the item's password before proceeding.
After an item is edited,
`nb` automatically re-encrypts it and saves the new version.
Encrypted notes can be decrypted
using the OpenSSL and GPG command line tools directly, so
you aren't dependent on `nb` to decrypt your files.
##### Shortcut Aliases: `nb a`, `nb +`
`nb` includes shortcuts for many commands, including
[`nb a`](#add) and [`nb +`](#add) for [`nb add`](#add):
```bash
# create a new note in your text editor
nb a
# create a new note with the filename "example.md"
nb a example.md
# create a new note containing "This is a note."
nb + "This is a note."
# create a new note containing the clipboard contents with xclip
xclip -o | nb +
# create a new note in the notebook named "example"
nb example:a
```
##### Other Aliases: `nb create`, `nb new`
[`nb add`](#add) can also be invoked with
[`nb create`](#add) and [`nb new`](#add) for convenience:
```bash
# create a new note containing "Example note content."
nb new "Example note content."
# create a new note with the title "Example Note Title"
nb create --title "Example Note Title"
```
##### Adding with `nb browse`
Items can also be added within terminal and GUI web browsers using
[`nb browse add`](#browse) / [`nb b a`](#browse):
```bash
❯ nb browse add
❯nb · home : +
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[add]
```
Pass a filename, relative path, and / or notebook name to
create a new note at that location:
```bash
# open the add form in the browser to create the file "file.md" in the folder "example"
nb browse add "example/file.md"
```
[`nb browse add`](#browse) includes options for quickly
pre-populating new notes with content:
```bash
❯ nb browse add --title "Example Title" --content "Example content." --tags tag1,tag2
❯nb · home : +
[# Example Title ]
[ ]
[#tag1 #tag2 ]
[ ]
[Example content. ]
[ ]
[ ]
[ ]
[ ]
[ ]
[add]
```
[`nb browse add`](#browse) can also be opened with
[`nb add --browse`](#add) / [`nb a -b`](#add).
For more information, see [Browsing](#-browsing).
#### Listing & Filtering
<p>
<sup>
<a href="#overview">↑</a> ·
<a href="#ls"><code>nb ls</code></a>,
<a href="#list"><code>nb list</code></a>,
<a href="#browse"><code>nb browse</code></a>
</sup>
</p>
To list notes and notebooks, run [`nb ls`](#ls) (shortcut alias: `nb`):
<div align="center">
<img src="https://xwmx.github.io/misc/nb/images/nb-theme-utility-home.png"
alt="nb ls"
width="450">
</div>
Notebooks are listed above the line,
with the current notebook highlighted and/or underlined,
depending on terminal capabilities.
[`nb ls`](#ls) also includes a footer with example commands for easy reference.
The notebook header and command footer can be configured or hidden with
[`nb set header`](#header) and
[`nb set footer`](#footer).
```bash
❯ nb ls
home
----
[3] example.md · "Example content."
[2] sample.md · "Sample content."
[1] demo.md · "- Demo list item one."
```
Notes from the current notebook are listed in the order they were last modified.
By default, each note is listed with its
id, filename, and an excerpt from the first line of the note.
When a note has a title, the title is displayed
instead of the filename and first line.
Markdown titles can be defined within a note using
[either Markdown `h1` style](https://daringfireball.net/projects/markdown/syntax#header)
or [YAML front matter](#front-matter):
```markdown
# Example Title
```
```markdown
Sample Title
============
```
```markdown
---
title: Demo Title
---
```
[Org](https://orgmode.org/),
[LaTeX](https://www.latex-project.org/),
and [AsciiDoc](https://asciidoc.org/)
titles are recognized in `.org`,`.latex`, and `.asciidoc` / `.adoc` files:
```text
#+TITLE: Example Org Title
```
```latex
\title{Example LaTeX Title}
```
```asciidoc
= Example AsciiDoc Title
```
Once defined, titles are displayed in place of the filename and first line
in the output of [`nb ls`](#ls):
```bash
❯ nb ls
home
----
[3] Example Title
[2] Sample Title
[1] Demo Title
```
Pass an id, filename, or title to view the listing for that note:
```bash
❯ nb ls Sample\ Title
[2] Sample Title
❯ nb ls 3
[3] Example Title
```
If there is no exact match, `nb` will list items with
titles and filenames that fuzzy match the query:
```bash
❯ nb ls exa
[3] Example Title
❯ nb ls ample
[3] Example Title
[2] Sample Title
```
Multiple words act like an `OR` filter, listing any
titles or filenames that match any of the words:
```bash
❯ nb ls example demo
[3] Example Title
[1] Demo Title
```
When multiple words are quoted, filter titles and filenames for that phrase:
```bash
❯ nb ls "example title"
[3] Example Title
```
For full text search, see [Search](#-search).
To view excerpts of notes, use the [`--excerpt`](#ls) or [`-e`](#ls) option,
which optionally accepts a length:
```bash
❯ nb ls 3 --excerpt
[3] Example Title
-----------------
# Example Title
This is an example excerpt.
❯ nb ls 3 -e 8
[3] Example Title
-----------------
# Example Title
This is an example excerpt.
More example content:
- one
- two
```
Several classes of file types are represented with emoji
[indicators](#indicators) to make them easily identifiable in lists.
For example, bookmarks and encrypted notes are listed with `🔖` and `🔒`:
```bash
❯ nb ls
home
----
[4] Example Note
[3] 🔒 encrypted-note.md.enc
[2] 🔖 Example Bookmark (example.com)
[1] 🔖 🔒 encrypted.bookmark.md.enc
```
File types include:
```text
🔉 Audio
📖 Book
🔖 Bookmark
🔒 Encrypted
📂 Folder
🌄 Image
📄 PDF, Word, or Open Office document
📹 Video
```
By default, items are listed starting with the most recently modified.
To reverse the order, use the [`-r`](#ls) or [`--reverse`](#ls) flag:
```bash
❯ nb ls
home
----
[2] Todos
[3] Example Title
[1] Ideas
❯ nb ls --reverse
[1] Ideas
[3] Example Title
[2] Todos
```
Notes can be sorted with the [`-s`](#ls) / [`--sort`](#ls) flag,
which can be combined with [`-r`](#ls) / [`--reverse`](#ls):
```bash
❯ nb ls
home
----
[2] Sample Title
[3] Example Title
[1] Demo Title
❯ nb ls --sort
[1] Demo Title
[2] Sample Title
[3] Example Title
❯ nb ls --sort --reverse
[3] Example Title
[2] Sample Title
[1] Demo Title
```
`nb` with no subcommand behaves like an alias for [`nb ls`](#ls),
so the examples above can be run without the `ls`:
```bash
❯ nb
home
----
[2] Sample Title
[3] Example Title
[1] Demo Title
❯ nb example
[3] Example Title
❯ nb 3 --excerpt
[3] Example Title
-----------------
# Example Title
This is an example excerpt.
❯ nb 3 -e 8
[3] Example Title
-----------------
# Example Title
This is an example excerpt.
More example content:
- one
- two
❯ nb --sort
[1] Demo Title
[2] Sample Title
[3] Example Title
❯ nb --sort --reverse
[3] Example Title
[2] Sample Title
[1] Demo Title
```
Short options can be combined for brevity:
```bash
# equivalent to `nb --sort --reverse --excerpt 2` and `nb -s -r -e 2`:
❯ nb -sre 2
[3] Example Title
-----------------
# Example Title
[2] Sample Title
----------------
Sample Title
============
[1] Demo Title
--------------
---
title: Demo Title
```
`nb` and [`nb ls`](#ls) display the 15 most recently modified items.
The default limit can be changed with [`nb set limit <number>`](#limit).
To list a different number of items on a per-command basis, use the
[`-n <limit>`](#ls),
[`--limit <limit>`](#ls),
[`--<limit>`](#ls),
[`-a`](#ls),
and [`--all`](#ls)
flags:
```bash
❯ nb -n 1
home
----
[5] Example Five
4 omitted. 5 total.
❯ nb --limit 2
home
----
[5] Example Five
[4] Example Four
3 omitted. 5 total.
❯ nb --3
home
----
[5] Example Five
[4] Example Four
[3] Example Three
2 omitted. 5 total.
❯ nb --all
home
----
[5] Example Five
[4] Example Four
[3] Example Three
[2] Example Two
[1] Example One
```
Lists can be paginated with
[`-p <number>`](#ls) / [`--page <number>`](#ls),
which paginates by the value of [`nb set limit`](#limit) by
default, or the value of
[`-n <limit>`](#ls),
[`--limit <limit>`](#ls),
or [`--<limit>`](#ls)
when present:
```bash
❯ nb
home
----
[6] Example Six
[5] Example Five
[4] Example Four
[3] Example Three
[2] Example Two
[1] Example One
❯ nb set limit 3
NB_LIMIT set to 3
❯ nb --page 1
[6] Example Six
[5] Example Five
[4] Example Four
❯ nb -p 2
[3] Example Three
[2] Example Two
[1] Example One
❯ nb -p 2 --limit 2
[4] Example Four
[3] Example Three
❯ nb -p 3 --2
[2] Example Two
[1] Example One
```
List [#tagged](#tagging) items by passing `\#escaped` or `"#quoted"` hashtags
or tags specified with the [`--tags`](#ls) option. Multiple tags perform an
`AND` query:
```bash
# list items in the current notebook tagged with "#tag1", escaped
nb \#tag1
# list items in the "example" notebook tagged with "#tag2", quoted
nb example: "#tag2"
# list items in all notebooks tagged with "#tag1", long option
nb \#tag1 --all
# list items in the current notebook tagged with "#tag1" AND "#tag2"
nb \#tag1 "#tag2"
# list items in all notebooks tagged with "#tag2" AND "#tag3", short option
nb --tags tag2,tag3 -a
```
[`nb ls`](#ls) is a combination of
[`nb notebooks`](#notebooks) and [`nb list`](#list)
in one view and accepts the same arguments as [`nb list`](#list),
which lists only notes without the notebook list and with no limit by default:
```bash
❯ nb list
[100] Example One Hundred
[99] Example Ninety-Nine
[98] Example Ninety-Eight
... lists all notes ...
[2] Example Two
[1] Example One
```
For more information about options for listing notes, run
[`nb help ls`](#ls)
and
[`nb help list`](#list).
##### Listing with `browse`
Items can be listed within terminal and GUI web browsers using
[`nb browse`](#browse) / [`nb b`](#browse):
```bash
❯ nb browse example:sample/demo/
❯nb · example : sample / demo / +
search: [ ]
[example:sample/demo/7] Title Seven
[example:sample/demo/6] Title Six
[example:sample/demo/5] Title Five
[example:sample/demo/4] Title Four
[example:sample/demo/3] Title Three
next ❯
```
For more information, see [Browsing](#-browsing).
#### Editing
<p>
<sup>
<a href="#overview">↑</a> ·
<a href="#edit"><code>nb edit</code></a>,
<a href="#browse"><code>nb browse edit</code></a>
</sup>
</p>
You can edit an item in your editor with
[`nb edit`](#edit) (shortcut: [`nb e`](#edit)):
```bash
# edit note by id
nb edit 3
# edit note by filename
nb edit example.md
# edit note by title
nb edit "A Document Title"
# edit note 12 in the notebook named "example"
nb edit example:12
# edit note 12 in the notebook named "example", alternative
nb example:12 edit
# edit note 12 in the notebook named "example", alternative
nb example:edit 12
```
[`edit`](#edit) and other subcommands that take an identifier
can be called with the identifier and subcommand name reversed:
```bash
# edit note by id
nb 3 edit
```
[`nb edit`](#edit) can also receive piped content, which it
appends to the specified note without opening the editor:
```bash
echo "Content to append." | nb edit 1
```
Content can be passed with the [`--content <content>`](#edit) option,
which also appends the content without opening the editor:
```bash
nb edit 1 --content "Content to append."
```
Use the [`--overwrite`](#edit) option to overwrite existing file content
and the [`--prepend`](#edit) option to prepend the new content before existing content.
When content is piped or specified with [`--content <content>`](#edit),
use the [`--edit`](#edit) flag to open the file in the editor
before the change is committed.
##### Editing Encrypted Notes
When a note is encrypted,
[`nb edit`](#edit) prompts you for the note password,
opens the unencrypted content in your editor,
and then automatically reencrypts the note when you are done editing.
##### Shortcut Alias: `nb e`
[`nb edit`](#edit) can be called by the shortcut alias, [`nb e`](#edit):
```bash
# edit note by id
nb e 3
# edit note by filename
nb e example.md
# edit note by title
nb e "A Document Title"
# edit note by id, alternative
nb 3 e
# edit note 12 in the notebook named "example"
nb e example:12
# edit note 12 in the notebook named "example", alternative
nb example:12 e
# edit note 12 in the notebook named "example", alternative
nb example:e 12
```
For [`nb edit`](#edit) help information, run [`nb help edit`](#edit).
##### Editing with `browse`
Items can be edited within terminal and GUI web browsers using
[`nb browse edit`](#browse) / [`nb b e`](#browse):
```bash
❯ nb browse edit text:formats/markdown/123
❯nb · text : formats / markdown / 123 · ↓ · editing · - | +
[# Daring Fireball: Markdown (daringfireball.net) ]
[ ]
[<https://daringfireball.net/projects/markdown/> ]
[ ]
[## Related ]
[ ]
[- <https://en.wikipedia.org/wiki/Markdown> ]
[ ]
[## Comments ]
[ ]
[See also: ]
[ ]
[- [[text:formats/org]] ]
[- [[cli:apps/nb]] ]
[ ]
[## Tags ]
[ ]
[save] · last: 2021-01-01 01:00:00
```
For more information, see
[`browse edit`](#browse-edit) and [Browsing](#-browsing).
#### Viewing
<p>
<sup>
<a href="#overview">↑</a> ·
<a href="#show"><code>nb show</code></a>,
<a href="#browse"><code>nb browse</code></a>,
<a href="#open"><code>nb open</code></a>,
<a href="#peek"><code>nb peek</code></a>
</sup>
</p>
Notes and other items can be viewed using
[`nb show`](#show) (shortcut: [`nb s`](#show)):
```bash
# show note by id
nb show 3
# show note by filename
nb show example.md
# show note by title
nb show "A Document Title"
# show note by id, alternative
nb 3 show
# show note 12 in the notebook named "example"
nb show example:12
# show note 12 in the notebook named "example", alternative
nb example:12 show
# show note 12 in the notebook named "example", alternative
nb example:show 12
```
By default, [`nb show`](#show) opens notes in
[`less`](https://linux.die.net/man/1/less),
with syntax highlighting if
[`bat`](https://github.com/sharkdp/bat),
[`highlight`](http://www.andre-simon.de/doku/highlight/en/highlight.php),
or
[Pygments](https://pygments.org/)
is installed.
You can navigate in `less` using the following keys:
```text
Key Function
--- --------
mouse scroll Scroll up or down
arrow up or down Scroll one line up or down
f Jump forward one window
b Jump back one window
d Jump down one half window
u Jump up one half window
/<query> Search for <query>
n Jump to next <query> match
q Quit
```
*If `less` scrolling isn't working in [iTerm2](https://www.iterm2.com/),
go to*
"Settings"
-> "Advanced"
-> "Scroll wheel sends arrow keys when in alternate screen mode"
*and change it to* "Yes".
*[More Info](https://stackoverflow.com/a/37610820)*
Use the [`-p`](#show) / [`--print`](#show) option
to print to standard output with syntax highlighting:
```bash
❯ nb show 123 --print
# Example Title
Example content:
- one
- two
- three
```
Use [`nb show --print --no-color`](#show) to print without syntax highlighting.
When [Pandoc](https://pandoc.org/) is available,
use the [`-r`](#show) / [`--render`](#show) option to
render the note to HTML and open it in your terminal browser:
```bash
nb show example.md --render
# opens example.md as an HTML page in w3m, links, or lynx
```
[`nb show`](#show) also supports previewing other file types in the terminal,
depending on the tools available in the environment. To prefer specific tools
for certain file types, `nb` provides configuration variables that can be
set in your `~/.nbrc` file,
which can be opened in your editor with [`nb settings edit`](#settings).
Supported file types and tools include:
- PDF files:
- [`termpdf.py`](https://github.com/dsanson/termpdf.py)
with [kitty](https://sw.kovidgoyal.net/kitty/)
- [`pdftotext`](https://en.wikipedia.org/wiki/Pdftotext)
- Audio files ([`$NB_AUDIO_TOOL`](#nb_audio_tool)):
- [`mplayer`](https://en.wikipedia.org/wiki/MPlayer)
- [`afplay`](https://ss64.com/osx/afplay.html)
- [`mpg123`](https://en.wikipedia.org/wiki/Mpg123)
- [`ffplay`](https://ffmpeg.org/ffplay.html)
- [Images](#-images) ([`$NB_IMAGE_TOOL`](#nb_image_tool)):
- [`catimg`](https://github.com/posva/catimg)
- [Chafa](https://github.com/hpjansson/chafa)
- [ImageMagick](https://imagemagick.org/) with a terminal that
supports [sixels](https://en.wikipedia.org/wiki/Sixel)
- [`imgcat`](https://www.iterm2.com/documentation-images.html) with
[iTerm2](https://www.iterm2.com/)
- [kitty's `icat` kitten](https://sw.kovidgoyal.net/kitty/kittens/icat.html)
- [`term-image`](https://github.com/AnonymouX47/term-image)
- [`timg`](https://github.com/hzeller/timg)
- [`viu`](https://github.com/atanunq/viu)
- Folders, Directories, Notebooks ([`$NB_DIRECTORY_TOOL`](#nb_directory_tool)):
- [`exa`](https://github.com/ogham/exa)
- [`joshuto`](https://github.com/kamiyaa/joshuto)
- [Midnight Commander (`mc`)](https://en.wikipedia.org/wiki/Midnight_Commander)
- [`ranger`](https://ranger.github.io/)
- [`vifm`](https://vifm.info/)
- Word Documents:
- [Pandoc](https://pandoc.org/) with
[`w3m`](https://en.wikipedia.org/wiki/W3m) or
[`links`](https://en.wikipedia.org/wiki/Links_(web_browser))
- Excel, CSV, TSV, and data files ([`$NB_DATA_TOOL`](#nb_data_tool)):
- [VisiData](https://www.visidata.org/)
- [`sc-im`](https://github.com/andmarti1424/sc-im)
- [Tidy-Viewer (`tv`)](https://github.com/alexhallam/tv)
- EPUB ebooks:
- [Pandoc](https://pandoc.org/) with
[`w3m`](https://en.wikipedia.org/wiki/W3m) or
[`links`](https://en.wikipedia.org/wiki/Links_(web_browser))
When using [`nb show`](#show) with other file types or
if the above tools are not available,
[`nb show`](#show) opens files in
your system's preferred application for each type.
[`nb show`](#show) also provides [options](#show) for
querying information about an item. For example, use the
[`--added`](#show) / [`-a`](#show) and [`--updated`](#show) / [`-u`](#show)
flags to print the date and time that an item was added or updated:
```bash
❯ nb show 2 --added
2020-01-01 01:01:00 -0700
❯ nb show 2 --updated
2020-02-02 02:02:00 -0700
```
[`nb show`](#show) is primarily intended for viewing items within the terminal.
To view a file in the system's preferred GUI application, use
[`nb open`](#open).
To [browse](#-browsing) rendered items in terminal and GUI web browsers, use
[`nb browse`](#browse).
For full [`nb show`](#show) usage information, run [`nb help show`](#show).
##### Shortcut Alias: `nb s`
[`nb show`](#show) can be called using the shortcut alias [`nb s`](#show):
```bash
# show note by id
nb s 3
# show note by filename
nb s example.md
# show note by title
nb s "A Document Title"
# show note by id, alternative
nb 3 s
# show note 12 in the notebook named "example"
nb s example:12
# show note 12 in the notebook named "example", alternative
nb example:12 s
# show note 12 in the notebook named "example", alternative
nb example:s 12
```
##### Alias: `nb view`
[`nb show`](#show) can also be invoked with [`nb view`](#show) for convenience:
```bash
# show note by id
nb view 3
# show note by filename
nb view example.md
# show note by title
nb view "A Document Title"
# show note by id, alternative
nb 3 view
```
##### Viewing with `browse`
Items can be viewed within terminal and GUI web browsers using
[`nb browse`](#browse) / [`nb b`](#browse):
```bash
❯ nb browse text:formats/markdown/123
❯nb · text : formats / markdown / 123 · ↓ · edit | +
Daring Fireball: Markdown (daringfireball.net)
https://daringfireball.net/projects/markdown/
Related
• https://en.wikipedia.org/wiki/Markdown
Comments
See also:
• [[text:formats/org]]
• [[cli:apps/nb]]
Tags
#markup #plain-text
Content
Daring Fireball: Markdown
Download
Markdown 1.0.1 (18 KB) — 17 Dec 2004
Introduction
Markdown is a text-to-HTML conversion tool for web writers. Markdown allows
you to write using an easy-to-read, easy-to-write plain text format, then
convert it to structurally valid XHTML (or HTML).
```
For more information, see [Browsing](#-browsing).
#### Deleting
<p>
<sup>
<a href="#overview">↑</a> ·
<a href="#delete"><code>nb delete</code></a>,
<a href="#browse"><code>nb browse delete</code></a>
</sup>
</p>
To delete one or more notes, pass any number of
ids, filenames, titles, and other [selectors](#-selectors)
to [`nb delete`](#delete) (shortcuts: [`nb d`](#delete), [`nb -`](#delete)):
```bash
# delete item by id
nb delete 3
# delete item by filename
nb delete example.md
# delete item by title
nb delete "A Document Title"
# delete item by id, alternative
nb 3 delete
# delete item 12 in the notebook named "example"
nb delete example:12
# delete item 12 in the notebook named "example", alternative
nb example:12 delete
# delete item 12 in the notebook named "example", alternative
nb example:delete 12
# delete item 345 in the folder named "example"
nb delete example/345
# delete items with the ids 89, 56, and 21
nb delete 89 56 21
```
By default, [`nb delete`](#delete) will display a confirmation prompt.
To skip, use the [`--force`](#delete) / [`-f`](#delete) option:
```bash
nb delete 3 --force
```
##### Shortcut Aliases: `nb d`, `nb -`
[`nb delete`](#delete) has the aliases [`nb d`](#delete) and [`nb -`](#delete):
```bash
# delete note by id
nb d 3
# delete note by filename
nb d example.md
# delete note by title
nb - "A Document Title"
# delete note by id, alternative
nb 3 d
# delete note 12 in the notebook named "example"
nb - example:12
# delete note 12 in the notebook named "example", alternative
nb example:12 d
# delete note 12 in the notebook named "example", alternative
nb example:d 12
```
For [`nb delete`](#delete) help information, run [`nb help delete`](#delete).
##### Deleting with `nb browse`
Items can be deleted within terminal and GUI web browsers using
[`nb browse delete`](#browse) / [`nb b d`](#browse):
```bash
❯ nb browse delete example:4
❯nb · example : 4 · ↓ · edit · - | +
deleting
[4] example_file.md "Example Title"
[delete]
```
For more information, see [Browsing](#-browsing).
### 🔖 Bookmarks
<p>
<sup>
<a href="#overview">↑</a> ·
<a href="#nb-help"><code>nb <url></code></a>,
<a href="#browse"><code>nb browse</code></a>,
<a href="#bookmark"><code>nb bookmark</code></a>,
<a href="#open"><code>nb open</code></a>,
<a href="#peek"><code>nb peek</code></a>,
<a href="#show"><code>nb show</code></a>
</sup>
</p>
`nb` includes a bookmarking system to conveniently
create, annotate, view, search, [browse](#-browsing), and manage
collections of bookmarks.
<div align="center">
<img src="https://xwmx.github.io/misc/nb/images/nb-bookmarks-gui-gui-terminal.png"
alt="nb bookmarks"
width="450">
</div>
Bookmarks in `nb` are stored as
[simple structured Markdown files](#nb-markdown-bookmark-file-format)
containing information extracted from the bookmarked pages.
To create a new bookmark, pass a URL as the first argument to `nb`:
```bash
nb https://example.com
```
`nb` automatically generates a bookmark using information from the page:
```markdown
# Example Title (example.com)
<https://example.com>
## Description
Example description.
## Content
Example Title
=============
This domain is for use in illustrative examples in documents. You may
use this domain in literature without prior coordination or asking for
permission.
[More information\...](https://www.iana.org/domains/example)
```
`nb` embeds the page content in the bookmark, making it available for
[full text search](#-search) with [`nb search`](#search) and
locally-served, distraction-free [reading and browsing](#-browsing)
with [`nb browse`](#browse).
When [Pandoc](https://pandoc.org/) is installed,
the HTML page content is converted to Markdown.
When [readability-cli](https://gitlab.com/gardenappl/readability-cli)
is installed, markup is cleaned up to focus on content.
In addition to caching the page content,
you can also include a quote from the page in a
[`## Quote`](#-quote) section
using the
[`-q <quote>`](#bookmark) / [`--quote <quote>`](#bookmark) option:
```bash
nb https://example.com --quote "Example quote line one.
Example quote line two."
```
```markdown
# Example Title (example.com)
<https://example.com>
## Description
Example description.
## Quote
> Example quote line one.
>
> Example quote line two.
## Content
Example Title
=============
This domain is for use in illustrative examples in documents. You may
use this domain in literature without prior coordination or asking for
permission.
[More information\...](https://www.iana.org/domains/example)
```
Add a comment in a [`## Comment`](#-comment) section using the
[`-c <comment>`](#bookmark) / [`--comment <comment>`](#bookmark) option:
```bash
nb https://example.com --comment "Example comment."
```
```markdown
# Example Title (example.com)
<https://example.com>
## Description
Example description.
## Comment
Example comment.
## Content
Example Title
=============
This domain is for use in illustrative examples in documents. You may
use this domain in literature without prior coordination or asking for
permission.
[More information\...](https://www.iana.org/domains/example)
```
Add related URLs and [linked](#-linking) [selectors](#-selectors)
to a [`## Related`](#-related) section using the
[`-r (<url> | <selector>)`](#bookmark) /
[`--related (<url> | <selector>)`](#bookmark)
option:
```bash
nb https://example.com --related example:123 -r https://example.net
```
```markdown
# Example Title (example.com)
<https://example.com>
## Description
Example description.
## Related
- [[example:123]]
- <https://example.net>
## Content
Example Title
=============
This domain is for use in illustrative examples in documents. You may
use this domain in literature without prior coordination or asking for
permission.
[More information\...](https://www.iana.org/domains/example)
```
Bookmarks can be tagged using the
[`-t <tag1>,<tag2>...`](#bookmark) /
[`--tags <tag1>,<tag2>...`](#bookmark) option.
Tags are converted into [#hashtags](#-tagging) and
added to a [`## Tags`](#-tags) section:
```bash
nb https://example.com --tags tag1,tag2
```
```markdown
# Example Title (example.com)
<https://example.com>
## Description
Example description.
## Tags
#tag1 #tag2
## Content
Example Title
=============
This domain is for use in illustrative examples in documents. You may
use this domain in literature without prior coordination or asking for
permission.
[More information\...](https://www.iana.org/domains/example)
```
[Search](#-search) for tagged bookmarks with
[`nb search`](#search) / [`nb q`](#search):
```bash
nb search --tag tag1
nb q -t tag1
nb q \#tag1
```
[`nb search`](#search) / [`nb q`](#search)
automatically searches archived page content:
```bash
❯ nb q "example query"
[10] 🔖 example.bookmark.md "Example Bookmark (example.com)"
------------------------------------------------------------
5:Lorem ipsum example query.
```
Bookmarks can also be encrypted:
```bash
# create a new password-protected, encrypted bookmark
nb https://example.com --encrypt
```
Encrypted bookmarks require a password before they can be viewed or
opened.
#### Listing and Filtering Bookmarks
<div align="center">
<img src="https://xwmx.github.io/misc/nb/images/nb-bookmarks-gui-terminal-terminal.png"
alt="nb bookmark lists"
width="500">
</div>
Bookmarks are included in
`nb`,
[`nb ls`](#ls),
[`nb list`](#list),
and [`nb browse`](#browse)
along with items of other types.
[`nb bookmark`](#bookma