# nb
**Repository Path**: yinmoyu/nb
## Basic Information
- **Project Name**: nb
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: AGPL-3.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-10-14
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
`nb` is a command line note-taking, bookmarking, archiving,
and knowledge base application with:
- plain-text data storage,
- [encryption](#password-protected-encrypted-notes-and-bookmarks),
- [filtering](#listing-notes) 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),
- global and local [notebooks](#-notebooks),
- customizable [color themes](#-color-themes),
- extensibility through [plugins](#-plugins),
and more, all in a single portable, user-friendly script.
`nb` creates notes in text-based formats like
[Markdown](https://en.wikipedia.org/wiki/Markdown),
[Emacs Org mode](https://orgmode.org/),
and [LaTeX](https://www.latex-project.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. `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.
`nb` is also a powerful text-based CLI bookmarking system that includes:
- local full-text search of cached page content with regular expression support,
- tagging,
- convenient filtering and listing,
- [Internet Archive Wayback Machine](https://archive.org/web/) snapshot lookup for
broken links,
- easy viewing of bookmarked pages in the terminal and your regular web browser.
Page information is automatically downloaded, compiled, and saved into normal Markdown
documents made for humans, so bookmarks are easy to edit just like any other note.
`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.
`nb` is designed to be portable, future-focused, and vendor independent,
providing a full-featured and intuitive experience within a highly composable
user-centric text interface.
The entire program is a single well-tested shell script that can be installed,
copied, or `curl`ed almost anywhere and just work, using
[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.
π
π
π
π
π
nb
Installation β’
Overview β’
Help
### 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)
- [Pandoc](https://pandoc.org/)
- [`rg` / ripgrep](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),
[Ag - The Silver Searcher](https://github.com/ggreer/the_silver_searcher),
[`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),
[kitty's `icat` kitten](https://sw.kovidgoyal.net/kitty/kittens/icat.html),
[Lynx](https://en.wikipedia.org/wiki/Lynx_(web_browser)),
[Midnight Commander](https://en.wikipedia.org/wiki/Midnight_Commander),
[`mpg123`](https://en.wikipedia.org/wiki/Mpg123),
[MPlayer](https://en.wikipedia.org/wiki/MPlayer),
[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),
[`termpdf.py`](https://github.com/dsanson/termpdf.py)
#### macOS / Homebrew
To install with [Homebrew](https://brew.sh/):
```bash
brew tap xwmx/taps
brew install nb
```
Installing `nb` with Homebrew also installs the recommended dependencies
above and completion scripts for Bash and Zsh.
#### Ubuntu, Windows WSL, and others
##### npm
To install with [npm](https://www.npmjs.com/package/nb.sh):
```bash
npm install -g nb.sh
```
After `npm` installation completes, run `sudo nb completions install` to
install Bash and Zsh completion scripts (recommended).
On Ubuntu and WSL, you can run [`sudo 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` 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
```
#### Tab Completion
Bash 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
Notes β’
Adding β’
Listing β’
Editing β’
Viewing β’
Deleting β’
Bookmarks β’
Search β’
History β’
Notebooks β’
Git Sync β’
Import / Export β’
set & Settings β’
Color Themes β’
Plugins β’
Shell β’
Shortcuts β’
Help β’
Specifications β’
Tests
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 Notes
Use [`nb add`](#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."
```
`nb 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` behaves differently depending on the type of argument 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 the editor is not opened:
```bash
> nb add "This is a note."
Added: [5] 20200101000000.md
```
`nb add ` is useful for quickly jotting down notes directly
via the command line.
When no filename is specified, `nb add` uses the current datetime as
the filename.
`nb add` can also recieve piped content, which behaves the same as
`nb 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` option, which will also
create a new note without opening the editor:
```bash
nb add --content "Note content."
```
When content is piped, specified with `--content`, or passed as a
string argument, use the `--edit` 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 ` option will also set 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"
```
Files can be created with any file type either by specifying the
extension in the filename or via the `--type ` option:
```bash
# open a new org mode file in the editor
nb add example.org
# open a new reStructuredText file in the editor
nb add --type rst
```
Notes can be tagged simply by adding hashtags anywhere in the document:
```text
#tag1 #tag2
```
Search for tagged notes and bookmarks with [`nb search` / `nb q`](#search):
```bash
nb search "#tag1"
nb q "#tag2"
```
For a full list of options available for `nb add`, run [`nb help add`](#add).
##### Password-Protected Encrypted Notes and Bookmarks
Password-protected notes and [bookmarks](#-bookmarks) are created with
the `-e` / `--encrypt` flag and are 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 also be decrypted using the OpenSSL and GPG command
line tools directly, so you aren't dependent on `nb` to decrypt your
files.
##### Shortcut Alias: `a`
`nb` includes single-character shortcuts for many commands, including
`a` for `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 a "This is a note."
# create a new note containing the clipboard contents with xclip
xclip -o | nb a
# create a new note in the notebook named "example"
nb example:a
```
##### Other Aliases: `create`, `new`
`nb add` can also be invoked with `nb create` and `nb new` 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"
```
#### Listing Notes
To list notes and notebooks, run [`nb ls`](#ls):
```bash
> nb ls
home
----
[3] example.md Β· "Example content."
[2] todos.md Β· "Todos:"
[1] ideas.md Β· "- Example idea one."
```
Notebooks are listed above the line, with the current notebook
highlighted and/or underlined, depending on terminal capabilities.
`nb 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).
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.
Titles can be defined within a note using
[either Markdown `h1` style](https://daringfireball.net/projects/markdown/syntax#header)
or [YAML front matter](https://jekyllrb.com/docs/front-matter/):
```markdown
# Example Title
```
```markdown
Todos
=====
```
```markdown
---
title: Ideas
---
```
Once defined, titles will be displayed in place of the filename and first line
in the output of `nb ls`:
```bash
> nb ls
home
----
[3] Example Title
[2] Todos
[1] Ideas
```
Pass an id, filename, or title to view the listing for that note:
```bash
> nb ls Todos
[2] Todos
```
```bash
> nb ls 3
[3] Example Title
```
If there is no immediate match, `nb` will list items with titles and
filenames that fuzzy match the query:
```bash
> nb ls "idea"
[1] Ideas
```
A case-insensitive regular expression can also be used to filter
filenames and titles:
```bash
> nb ls "^example.*"
[3] Example Title
```
Multiple words act like an `OR` filter, listing any titles or filenames that
match any of the words:
```bash
> nb ls example ideas
[3] Example Title
[1] Ideas
```
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` or `-e` 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
- three
```
Several classes of file types are represented with emoji 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` or `--reverse` 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` / `--sort` flag, which can be combined
with `-r` / `--reverse`:
```bash
> nb ls
home
----
[2] Todos
[3] Example Title
[1] Ideas
> nb ls --sort
[1] Ideas
[2] Todos
[3] Example Title
> nb ls --sort --reverse
[3] Example Title
[2] Todos
[1] Ideas
```
`nb` with no subcommand behaves like an alias for `nb ls`, so the examples
above can be run without the `ls`:
```bash
> nb
home
----
[2] Todos
[3] Example Title
[1] Ideas
> 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
- three
> nb --sort
[1] Ideas
[2] Todos
[3] Example Title
> nb --sort --reverse
[3] Example Title
[2] Todos
[1] Ideas
```
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] Todos
---------
Todos
=====
[1] Ideas
---------
---
title: Ideas
```
`nb` and `nb ls` display the 20 most recently modified items. The default
limit can be changed with [`nb set limit `](#limit).
To list a different number of items on a per-command basis, use the
`-n `, `--limit `, `--`, `-a`, or `--all` 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
```
`nb ls` is a combination of [`nb notebooks`](#notebooks) and [`nb list`](#list)
in one view and accepts the same arguments as `nb 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).
#### Editing Notes
You can edit a note in your editor by passing its id, filename, or title
to [`nb edit`](#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` 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` can also receive piped content, which it will append to the
specified note without opening the editor:
```bash
echo "Content to append." | nb edit 1
```
Content can be passed with the `--content` option, which will also
append the content without opening the editor:
```bash
nb edit 1 --content "Content to append."
```
When content is piped or specified with `--content`, use the `--edit`
flag to open the file in the editor before the change is committed.
##### Editing Encrypted Notes
When a note is encrypted, `nb edit` will prompt you for the note password,
open the unencrypted content in your editor, and then automatically reencrypt
the note when you are done editing.
##### Shortcut Alias: `e`
Like `add`, `edit` has a shortcut alias, `e`:
```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` help information, run [`nb help edit`](#edit).
#### Viewing Notes
Notes can be viewed using [`nb show`](#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` will open the note 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
/ Search for
n Jump to next 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)*
When [Pandoc](https://pandoc.org/) is available, use the `-r` / `--render`
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 or lynx
```
`nb show` also supports previewing other file types in the terminal,
depending on the tools available in the environment. 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:
- [`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:
- [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)
- Folders / Directories:
- [`ranger`](https://ranger.github.io/)
- [Midnight Commander (`mc`)](https://en.wikipedia.org/wiki/Midnight_Commander)
- Word Documents:
- [Pandoc](https://pandoc.org/)
- EPUB ebooks:
- [Pandoc](https://pandoc.org/) with
[`w3m`](https://en.wikipedia.org/wiki/W3m) or
[`lynx`](https://en.wikipedia.org/wiki/Lynx_(web_browser))
When using `nb show` with other file types or if the above tools are not
available, `nb show` will open files in your system's preferred application
for each type.
`nb show` also provides [options](#show) for querying information about an
item. For example, use the `--added` / `-a` and `--updated` / `-u` 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` is primarily intended for viewing items within the terminal.
To view a file in the system's preferred GUI application,
use [`nb open`](#open).
For full `nb show` usage information, run [`nb help show`](#show).
##### Shortcut Alias: `s`
`show` is aliased to `s`:
```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: `view`
`nb show` can also be invoked with `nb view` 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
```
#### Deleting Notes
To delete a note, pass its id, filename, or title to
[`nb delete`](#delete):
```bash
# delete note by id
nb delete 3
# delete note by filename
nb delete example.md
# delete note by title
nb delete "A Document Title"
# delete note by id, alternative
nb 3 delete
# delete note 12 in the notebook named "example"
nb delete example:12
# delete note 12 in the notebook named "example", alternative
nb example:12 delete
# show note 12 in the notebook named "example", alternative
nb example:delete 12
```
By default, `nb delete` will display a confirmation prompt. To skip, use the
`--force` / `-f` option:
```bash
nb delete 3 --force
```
##### Shortcut Alias: `d`
`delete` has the alias `d`:
```bash
# delete note by id
nb d 3
# delete note by filename
nb d example.md
# delete note by title
nb d "A Document Title"
# delete note by id, alternative
nb 3 d
# delete note 12 in the notebook named "example"
nb d 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` help information, run [`nb help delete`](#delete).
### π Bookmarks
`nb` is a powerful bookmark management system, enabling you to to view, search,
and manage your bookmarks, links, and online references. Bookmarks are
Markdown notes containing information about the bookmarked page.
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)
## 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 with [`nb search`](#search). When [Pandoc](https://pandoc.org/)
is installed, the HTML page content will be 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 using the `-q` / `--quote` option:
```bash
nb https://example.com --quote "Example quote line one.
Example quote line two."
```
```markdown
# Example Title (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 to a bookmark using the `-c` / `--comment` option:
```bash
nb https://example.com --comment "Example comment."
```
```markdown
# Example Title (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)
```
Bookmarks can be tagged using the `-t` / `--tags` option. Tags are converted
into hashtags:
```bash
nb https://example.com --tags tag1,tag2
```
```markdown
# Example Title (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 for tagged bookmarks with [`nb search` / `nb q`](#search):
```bash
nb search "#tag1"
nb q "#tag"
```
`nb search` / `nb q` 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
[`nb bookmark`](#bookmark) and `nb bookmark list` can be used to list
and filter only bookmarks:
```bash
> nb bookmark
Add: nb Help: nb help bookmark
------------------------------------
[3] π π example.bookmark.md.enc
[2] π Example Two (example.com)
[1] π Example One (example.com)
> nb bookmark list two
[2] π Example Two (example.com)
```
Bookmarks are also included in `nb`, `nb ls`, and `nb list`:
```bash
> nb
home
----
[7] π Example Bookmark Three (example.com)
[6] Example Note Three
[5] π Example Bookmark Two (example.net)
[4] Example Note Two
[3] π π example-encrypted.bookmark.md.enc
[2] Example Note One
[1] π Example Bookmark One (example.com)
```
Use the [`--type ` / `--`](#ls) option as a filter to display
only bookmarks:
```bash
> nb --type bookmark
[7] π Example Bookmark Three (example.com)
[5] π Example Bookmark Two (example.net)
[3] π π example-encrypted.bookmark.md.enc
[1] π Example Bookmark One (example.com)
> nb --bookmark
[7] π Example Bookmark Three (example.com)
[5] π Example Bookmark Two (example.net)
[3] π π example-encrypted.bookmark.md.enc
[1] π Example Bookmark One (example.com)
```
`nb` saves the domain in the title, making it easy to filter by domain
using any list subcommands:
```bash
> nb example.com
[7] π Example Bookmark Three (example.com)
[1] π Example Bookmark One (example.com)
```
For more listing options, see [`nb help ls`](#ls), [`nb help list`](#list),
and [`nb help bookmark`](#bookmark).
##### Shortcut Alias: `b`
`bookmark` can also be used with the alias `b`:
```bash
> nb b
Add: nb Help: nb help bookmark
------------------------------------
[7] π Example Bookmark Three (example.com)
[5] π Example Bookmark Two (example.net)
[3] π π example-encrypted.bookmark.md.enc
[1] π Example Bookmark One (example.com)
> nb b example.net
[5] π Example Bookmark Two (example.net)
```
#### Opening and Viewing Bookmarked Pages
`nb` provides multiple ways to view bookmarked web pages.
[`nb open`](#open) opens the bookmarked page in your
system's primary web browser:
```bash
# open bookmark by id
nb open 3
# open bookmark 12 in the notebook named "example"
nb open example:12
# open bookmark 12 in the notebook named "example", alternative
nb example:12 open
# open bookmark 12 in the notebook named "example", alternative
nb example:open 12
```
[`nb peek`](#peek) (alias: `preview`) opens the bookmarked page
in your terminal web browser, such as
[w3m](https://en.wikipedia.org/wiki/W3m) or
[Lynx](https://en.wikipedia.org/wiki/Lynx_(web_browser)):
```bash
# peek bookmark by id
nb peek 3
# peek bookmark 12 in the notebook named "example"
nb peek example:12
# peek bookmark 12 in the notebook named "example", alternative
nb example:12 peek
# peek bookmark 12 in the notebook named "example", alternative
nb example:peek 12
```
`open` and `peek` subcommands also work seamlessly with encrypted bookmarks.
`nb` will simply prompt you for the bookmark's password.
`open` and `peek` automatically check whether the URL is still valid.
If the page has been removed, `nb` can check the [Internet Archive
Wayback Machine](https://archive.org/web/) for an archived copy.
The preferred terminal web browser can be set using the `$BROWSER`
environment variable, assigned in `~/.bashrc`, `~/.zshrc`, or similar:
```bash
export BROWSER=lynx
```
When `$BROWSER` is not set, `nb` looks for `w3m` and `lynx` and uses the
first one it finds.
`$BROWSER` can also be used to easy specify the terminal browser for an
individual command:
```bash
> BROWSER=lynx nb 12 peek
# opens the URL from bookmark 12 in lynx
> BROWSER=w3m nb 12 peek
# opens the URL from bookmark 12 in w3m
```
`nb show` and `nb edit` can also be used to view and edit bookmark files,
which include the cached page converted to Markdown.
`nb show --render` / `nb show -r` displays the bookmark file
converted to HTML in the terminal web browser, including all bookmark fields
and the cached page content, providing a cleaned-up, distraction-free,
locally-served view of the page content along with all of your notes.
##### Shortcut Aliases: `o` and `p`
`open` and `peek` can also be used with the shortcut aliases `o` and
`p`:
```bash
# open bookmark by id
nb o 3
# open bookmark 12 in the notebook named "example"
nb o example:12
# open bookmark 12 in the notebook named "example", alternative
nb example:12 o
# peek bookmark by id
nb p 3
# peek bookmark 12 in the notebook named "example"
nb p example:12
# peek bookmark 12 in the notebook named "example", alternative
nb example:12 p
```
#### Bookmark File Format
Bookmarks are identified by a `.bookmark.md` file extension. The
bookmark URL is the first URL in the file within `<` and `>` characters.
To create a minimally valid bookmark file with `nb add`:
```bash
nb add example.bookmark.md --content ""
```
For a full overview, see
[`nb` Markdown Bookmark File Format](#nb-markdown-bookmark-file-format).
#### `bookmark` -- A command line tool for managing bookmarks.
`nb` includes [`bookmark`](#bookmark-help), a full-featured command line
interface for creating, viewing, searching, and editing bookmarks.
`bookmark` is a shortcut for the `nb bookmark` subcommand, accepting all
of the same subcommands and options with identical behavior.
Bookmark a page:
```bash
> bookmark https://example.com --tags tag1,tag2
Added: [3] π 20200101000000.bookmark.md "Example Title (example.com)"
```
List and filter bookmarks with `bookmark` and `bookmark list`:
```bash
> bookmark
Add: bookmark Help: bookmark help
---------------------------------------
[3] π π example.bookmark.md.enc
[2] π Example Two (example.com)
[1] π Example One (example.com)
> bookmark list two
[2] π Example Two (example.com)
```
View a bookmark in your terminal web browser:
```bash
> bookmark peek 2
```
Open a bookmark in your system's primary web browser:
```bash
> bookmark open 2
```
Perform a full text search of bookmarks and archived page content:
```bash
> bookmark search "example query"
[10] π example.bookmark.md "Example Bookmark (example.com)"
---------------------------------------------------------
5:Lorem ipsum example query.
```
See [`bookmark help`](#bookmark-help) for more information.
### π Search
Use [`nb search`](#search) to search your notes, with support for
regular expressions and tags:
```bash
# search current notebook for "example query"
nb search "example query"
# search the notebook "example" for "example query"
nb example:search "example query"
# search all unarchived notebooks for "example query" and list matching items
nb search "example query" --all --list
# search for "Example" OR "Sample"
nb search "Example|Sample"
# search items containing the hashtag "#example"
nb search "#example"
# search with a regular expression
nb search "\d\d\d-\d\d\d\d"
# search bookmarks for "example"
nb search "example" --type bookmark
# search bookmarks for "example", alternative
nb b q "example"
# search the current notebook for "example query"
nb q "example query"
# search the notebook named "example" for "example query"
nb example:q "example query"
# search all unarchived notebooks for "example query" and list matching items
nb q -la "example query"
```
`nb search` prints the id number, filename, and title of each matched
file, followed by each search query match and its line number, with color
highlighting:
```bash
> nb search "example"
[314] π example.bookmark.md "Example Bookmark (example.com)"
----------------------------------------------------------
1:# Example Bookmark (example.com)
3:
[2718] example.md "Example Note"
--------------------------------
1:# Example Note
```
To just print the note information line without the content matches, use
the `-l` or `--list` option:
```bash
> nb search "example" --list
[314] π example.bookmark.md "Example Bookmark (example.com)"
[2718] example.md "Example Note"
```
`nb search` looks for [`rg`](https://github.com/BurntSushi/ripgrep),
[`ag`](https://github.com/ggreer/the_silver_searcher),
[`ack`](https://beyondgrep.com/), and
[`grep`](https://en.wikipedia.org/wiki/Grep), in that order, and
performs searches using the first tool it finds. `nb search` works
mostly the same regardless of which tool is found and is perfectly fine using
the environment's built-in `grep`. `rg`, `ag`, and `ack` are faster and there
are some subtle differences in color highlighting.
##### Shortcut Alias: `q`
`search` can also be used with the alias `q` (for "query"):
```bash
# search for "example" and print matching excerpts
nb q "example"
# search for "example" and list each matching file
nb q -l "example"
# search for "example" in all unarchived notebooks
nb q -a "example"
# search for "example" in the notbook named "sample"
nb sample:q "example"
```
For more information about search, see [`nb help search`](#search).
### π Revision History
Whenever a note is added, modified, or deleted, `nb` automatically commits
the change to git transparently in the background.
Use [`nb history`](#history) to view the history of the notebook or an
individual note:
```bash
# show history for current notebook
nb history
# show history for note number 4
nb history 4
# show history for note with filename example.md
nb history example.md
# show history for note titled "Example"
nb history Example
# show history for the notebook named "example"
nb example:history
# show history for the notebook named "example", alternative
nb history example:
# show the history for note 12 in the notebook named "example"
nb history example:12
```
`nb history` uses `git log` by default and prefers
[`tig`](https://github.com/jonas/tig) when available.
### π Notebooks
You can create additional notebooks, each of which has its own version history.
Create a new notebook with [`nb notebooks add`](#notebooks):
```bash
# add a notebook named example
nb notebooks add example
```
`nb` and `nb ls` list the available notebooks above the list of notes:
```bash
> nb
example Β· home
--------------
[3] Title Three
[2] Title Two
[1] Title One
```
Commands in `nb` run within the current notebook, and identifiers like id,
filename, and title refer to notes within the current notebook.
`nb edit 3`, for example, tells `nb` to `edit` note with id `3` within the
current notebook.
To switch to a different notebook, use [`nb use`](#use):
```bash
# switch to the notebook named "example"
nb use example
```
If you are in one notebook and you want to perform a command in a
different notebook without switching to it, add the notebook name with a
colon before the command name:
```bash
# add a new note in the notebook "example"
nb example:add
# add a new note in the notebook "example", shortcut alias
nb example:a
# show note 5 in the notebook "example"
nb example:show 5
# show note 5 in the notebook "example", shortcut alias
nb example:s 5
# edit note 12 in the notebook "example"
nb example:edit 12
# edit note 12 in the notebook "example", shortcut alias
nb example:e 12
# search for "example query" in the notebook "example"
nb example:search "example query"
# search for "example query" in the notebook "example", shortcut alias
nb example:q "example query"
# show the revision history of the notebook "example"
nb example:history
```
The notebook name with colon can also be used as a modifier to the id,
filename, or title:
```bash
# edit note 12 in the notebook "example"
nb edit example:12
# edit note 12 in the notebook "example", shortcut alias
nb e example:12
# edit note 12 in the notebook "example", alternative
nb example:12 edit
# edit note 12 in the notebook "example", alternative, shortcut alias
nb example:12 e
# show note titled "misc" in the notebook "example"
nb show example:misc
# show note titled "misc" in the notebook "example", shortcut alias
nb s example:misc
# delete note with filename "todos.md" in the notebook "example", alternative
nb example:todos.md delete
# delete note with filename "todos.md" in the notebook "example", alternative,
# shortcut alias
nb example:todos.md d
```
When a notebook name with colon is called without a subcommand, `nb` runs
`nb ls` in the specified notebook:
```bash
> nb example:
example Β· home
--------------
[example:3] Title Three
[example:2] Title Two
[example:1] Title One
```
A bookmark can be created in another notebook by specifying the notebook
name with colon, then a space, then the URL and bookmark options:
```bash
# create a new bookmark in a notebook named "sample"
> nb sample: https://example.com --tags tag1,tag2
```
Notes can also be moved between notebooks:
```bash
# move note 3 from the current notebook to "example"
nb move 3 example
# move note 5 in the notebook "example" to the notebook "sample"
nb move example:5 sample
```
##### Example Workflow
The flexibility of `nb`'s argument handling makes it easy to build commands
step by step as items are listed, filtered, viewed, and edited, particularly
in combination with shell history:
```bash
# list items in the "example" notebook
> nb example:
example Β· home
--------------
[example:3] Title Three
[example:2] Title Two
[example:1] Title One
# filter list
> nb example: three
[example:3] Title Three
# view item
> nb example:3 show
# opens item in `less`
# edit item
> nb example:3 edit
# opens item in $EDITOR
```
##### Notebooks and Tab Completion
[`nb` tab completion](#tab-completion) is optimized for frequently running
commands in various notebooks using the colon syntax, so installing the
completion scripts is recommended and makes working with notebooks easy,
fluid, and fun.
For example, listing the contents of a notebook is usually as simple as typing
the first two or three characters of the name, then press the \ key,
then press \:
```bash
> nb exa
# completes to "example:"
> nb example:
example Β· home
--------------
[example:3] Title Three
[example:2] Title Two
[example:1] Title One
```
Scoped notebook commands are also available in tab completion:
```bash
> nb exa
# completes to "example:"
> nb example:hi
# completes to "example:history"
```
#### Notebooks, Tags, and Taxonomy
`nb` is optimized to work well with a bunch of notebooks, so notebooks are
a really good way to organize your notes and bookmarks by top-level topic.
Tags are searchable across notebooks and can be created ad hoc, making
notebooks and tags distinct and complementary organizational systems in `nb`.
Search for a tag in or across notebooks with
[`nb search`](#search) / [`nb q`](#search):
```bash
# search for #tag in the current notebook
nb q "#tag"
# search for #tag in all notebooks
nb q "#tag" -a
# search for #tag in the "example" notebook
nb example:q "#tag"
```
#### Global and Local Notebooks
##### Global Notebooks
By default, all `nb` notebooks are global, making them always accessible in
the terminal regardless of the current working directory. Global notebooks are
stored in the directory configured in [`nb set nb_dir`](#nb_dir), which is
`~/.nb` by default.
##### Local Notebooks
`nb` also supports creating and working with local notebooks. Local
notebooks are notebooks that are anywhere on the system outside
of `NB_DIR`. Any folder can be an `nb` local notebook, which is just a normal
folder that has been initialized as a git repository and contains an `nb`
.index file. Initializing a folder as an `nb` local notebook is a very easy
way to add structured git versioning to any folder of documents and
other files.
When `nb` runs within a local notebook, the local notebook is set as the
current notebook:
```bash
> nb
local Β· example Β· home
----------------------
[3] Title Three
[2] Title Two
[1] Title One
```
A local notebook is always referred to by the name `local` and otherwise
behaves just like a global notebook whenever a command is run from within it:
```bash
# add a new note in the local notebook
nb add
# edit note 15 in the local notebook
nb edit 15
# move note titled "Todos" from the home notebook to the local notebook
nb move home:Todos local
# move note 1 from the local notebook to the home notebook
nb move 1 home
# search the local notebook for
nb search "query string"
# search the local notebook and all unarchived global notebooks for
nb search "query string" --all
```
Local notebooks can be created with [`nb notebooks init`](#notebooks):
```bash
# initialize the current directory as a notebook
nb notebooks init
# create a new notebook at ~/example
nb notebooks init ~/example
# clone an existing notebook to ~/example
nb notebooks init ~/example https://github.com/example/example.git
```
Local notebooks can also be created by exporting a global notebook:
```bash
# export global notebook named "example" to "../path/to/destination"
nb notebooks export example ../path/to/destination
# alternative
nb export example ../path/to/destination
```
Local notebooks can also be imported, making them global:
```bash
# import notebook or folder at "../path/to/notebook"
nb notebooks import ../path/to/notebook
# alternative
nb import ../path/to/notebook
```
`nb notebooks init` and `nb notebooks import` can be used together to
easily turn any directory of existing files into a global `nb` notebook:
```bash
> ls
example-directory
> nb notebooks init example-directory
Initialized local notebook: /home/username/example-directory
> nb notebooks import example-directory
Imported notebook: example-directory
> nb notebooks
example-directory
home
```
#### Archiving Notebooks
Notebooks can be archived using [`nb notebooks archive`](#notebooks):
```bash
# archive the current notebook
nb notebooks archive
# archive the notebook named "example"
nb notebooks archive example
```
When a notebook is archived it is not included in [`nb`](#ls) /
[`nb ls`](#ls) output, [`nb search --all`](#search), or tab completion,
nor synced automatically with [`nb sync --all`](#sync).
```bash
> nb
example1 Β· example2 Β· example3 Β· [1 archived]
---------------------------------------------
[3] Title Three
[2] Title Two
[1] Title One
```
Archived notebooks can still be used individually using normal notebook
commands:
```bash
# switch the current notebook to the archived notebook "example"
nb use example
# run the `list` subcommand in the archived notebook "example"
nb example:list
```
Check a notebook's archival status with
[`nb notebooks status`](#notebooks):
```bash
> nb notebooks status example
example is archived.
```
Use [`nb notebooks unarchive`](#notebooks) to unarchive a notebook:
```bash
# unarchive the current notebook
nb notebooks unarchive
# unarchive the notebook named "example"
nb notebooks unarchive example
```
For more information about working with notebooks, see
[`nb help notebooks`](#notebooks).
For technical details about notebooks, see
[`nb` Notebook Specification](#nb-notebook-specification).
### π Git Sync
Each notebook can be synced with a remote git repository by setting the
remote URL using [`nb remote`](#remote):
```bash
# set the current notebook's remote to a private GitHub repository
nb remote set https://github.com/example/example.git
# set the remote for the notebook named "example"
nb example:remote set https://github.com/example/example.git
```
Any notebook with a remote URL will sync automatically every time a command is
run in that notebook.
When you use `nb` on multiple systems, you can set a notebook on both
systems to the same remote and `nb` will keep everything in sync in the
background every time there's a change in that notebook.
Since each notebook has its own git history, you can have some notebooks
syncing with remotes while other notebooks are only available locally on that
system.
Many services provide free private git repositories, so git syncing with
`nb` is easy, free, and vendor-independent. You can also sync your notes
using Dropbox, Drive, Box, Syncthing, or another syncing tool by changing
your `nb` directory with [`nb set nb_dir `](#nb_dir)
and git syncing will still work simultaneously.
When you have an existing `nb` notebook in a git repository, simply
pass the URL to [`nb notebooks add`](#notebooks) and `nb` will clone
your existing notebook and start syncing changes automatically:
```bash
# create a new notebook named "example" cloned from a private GitLab repository
nb notebooks add example https://gitlab.com/example/example.git
```
Turn off syncing for a notebook by removing the remote:
```bash
# remove the remote from the current notebook
nb remote remove
# remove the remote from the notebook named "example"
nb example:remote remove
```
Automatic git syncing can be turned on or off with
[`nb set auto_sync`](#auto_sync).
To sync manually, use [`nb sync`](#sync):
```bash
# manually sync the current notebook
nb sync
# manually sync the notebook named "example"
nb example:sync
```
To bypass `nb` syncing and run `git` commands directly within a
notebook, use [`nb git`](#git):
```bash
# run `git fetch` in the current notebook
nb git fetch origin
# run `git status` in the notebook named "example"
nb example:git status
```
#### Private Repositories and Git Credentials
Syncing with private repositories requires configuring git to not prompt
for credentials. For repositories cloned over HTTPS,
[credentials can be cached with git
](https://docs.github.com/en/free-pro-team@latest/github/using-git/caching-your-github-credentials-in-git).
For repositories cloned over SSH,
[keys can be added to the ssh-agent
](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent).
Use [`nb sync`](#sync) within a notebook to determine whether your
configuration is working. If `nb sync` displays a password prompt,
then follow the instructions above to configure your credentials.
The password prompt can be used to authenticate, but `nb` does not
cache or otherwise handle git credentials in any way, so there will
likely be multiple password prompts during each sync if credentials
are not configured.
#### Sync Conflict Resolution
`nb` handles git operations automatically, so you shouldn't ever need
to use the `git` command line tool directly. `nb` merges changes when
syncing and handles conflicts using a couple different strategies.
When [`nb sync`](#sync) encounters a conflict in a text file and can't
cleanly merge overlapping local and remote changes, `nb` saves both
versions within the file separated by git conflict markers and prints a
message indicating which file(s) contain conflicting text.
Use [`nb edit`](#edit) to remove the conflict markers and delete any
unwanted text.
For example, in the following file, the second list item was changed on
two systems, and git has no way to determine which one we want to keep:
```
# Example Title
- List Item apple
<<<<<<< HEAD
- List Item apricot
=======
- List Item pluot
>>>>>>> 719od01... [nb] Commit
- List Item plum
```
The local change is between the lines starting with `<<<<<<<` and
`=======`, while the remote change is between the `=======` and
`>>>>>>>` lines.
To resolve this conflict by keeping both items, simply edit the file
with `nb edit` and remove the lines starting with `<<<<<<<`, `=======`,
and `>>>>>>>`:
```
# Example Title
- List Item apple
- List Item apricot
- List Item pluot
- List Item plum
```
When `nb` encounters a conflict in a binary file, such as an encrypted
note, both versions of the file are saved in the notebook as individual
files, with `--conflicted-copy` appended to the filename of the version
from the remote. To resolve a conflicted copy of a binary file, compare
both versions and merge them manually, then delete the `--conflicted-copy`.
If you do encounter a conflict that `nb` says it can't merge at all,
[`nb git`](#git) and [`nb run`](#run) can be used to perform git and
shell operations within the notebook to resolve the conflict manually.
Please also [open an issue](https://github.com/xwmx/nb/issues/new)
with any relevant details that could inform a strategy for handling any
such cases automatically.
### βοΈ Import / Export
Files of any type can be imported into a notebook using
[`nb import`](#import). [`nb edit`](#edit) and [`nb open`](#open) will open
files in your system's default application for that file type.
```bash
# import an image file
nb import ~/Pictures/example.png
# open image in your default image viewer
nb open example.png
# import a .docx file
nb import ~/Documents/example.docx
# open .docx file in Word or your system's .docx viewer
nb open example.docx
```
Multiple filenames and globbing are supported:
```bash
# import all files and directories in the current directory
nb import ./*
# import all markdown files in the current directory
nb import ./*.md
# import example.md and sample.md in the current directory
nb import example.md sample.md
```
`nb import` can also download and import files directly from the web:
```bash
# import a PDF file from the web
nb import https://example.com/example.pdf
# Imported "https://example.com/example.pdf" to "example.pdf"
# open example.pdf in your system's PDF viewer
nb open example.pdf
```
Some imported file types have indicators to make them easier to identify in
lists:
```bash
> nb
home
----
[6] π example-ebook.epub
[5] π example-picture.png
[4] π example-document.docx
[3] πΉ example-video.mp4
[2] π example-audio.mp3
[1] π Example Folder
```
Notes, bookmarks, and other files can be exported using [`nb export`](#export).
If [Pandoc](https://pandoc.org/) is installed, notes can be automatically
converted to any of the
[formats supported by Pandoc](https://pandoc.org/MANUAL.html#option--to).
By default, the output format is determined by the file extension:
```bash
# export a Markdown note to a .docx Microsoft Office Word document
nb export example.md /path/to/example.docx
# export a note titled "Movies" to an HTML web page.
nb export Movies /path/to/example.html
```
For more control over the `pandoc` options, use the
[`nb export pandoc`](#export) subcommand:
```bash
# export note 42 as an epub with pandoc options
nb export pandoc 42 --from markdown_strict --to epub -o path/to/example.epub
```
[`nb export notebook`](#export) and [`nb import notebook`](#import) can be
used to export and import notebooks:
```bash
# export global notebook named "example" to "../path/to/destination"
nb export notebook example ../path/to/destination
# import notebook or folder at "../path/to/notebook"
nb import notebook ../path/to/notebook
```
[`nb export notebook`](#export) and [`nb import notebook`](#import) behave
like aliases for [`nb notebooks export`](#notebooks) and
[`nb notebooks import`](#notebooks), and the subcommands can be used
interchangeably.
For more information about imported and exported notebooks, see
[Global and Local Notebooks](#global-and-local-notebooks).
For `nb import` and `nb export` help information, see
[`nb help import`](#import) and [`nb help export`](#export).
### βοΈ `set` & Settings
[`nb set`](#settings) and [`nb settings`](#settings) open the settings
prompt, which provides an easy way to change your `nb` settings.
```bash
nb set
```
To update a setting in the prompt, enter the setting name or number,
then enter the new value, and `nb` will add the setting to your
`~/.nbrc` configuration file.
#### Example: editor
`nb` can be configured to use a specific command line editor using the
`editor` setting.
The settings prompt for a setting can be started by passing the setting
name or number to [`nb set`](#settings):
```bash
> nb set editor
[6] editor
------
The command line text editor to use with `nb`.
β’Β Example Values:
atom
code
emacs
macdown
mate
micro
nano
pico
subl
vi
vim
EDITOR is currently set to vim
Enter a new value, unset to set to the default value, or q to quit.
Value:
```
A setting can also be updated without the prompt by passing both the name
and value to `nb set`:
```bash
# set editor with setting name
> nb set editor code
EDITOR set to code
# set editor with setting number (6)
> nb set 6 code
EDITOR set to code
# set the color theme to blacklight
> nb set color_theme blacklight
NB_COLOR_THEME set to blacklight
# set the default `ls` limit to 10
> nb set limit 10
NB_LIMIT set to 10
```
Use [`nb settings get`](#settings) to print the value of a setting:
```bash
> nb settings get editor
code
> nb settings get 6
code
```
Use [`nb settings unset`](#settings) to unset a setting and revert to
the default:
```bash
> nb settings unset editor
EDITOR restored to the default: vim
> nb settings get editor
vim
```
`nb set` and `nb settings` are aliases that refer to the same subcommand, so
the two subcommand names can be used interchangably.
For more information about `set` and `settings`, see
[`nb help settings`](#settings) and
[`nb settings list --long`](#settings-list---long).
### π¨ Color Themes
`nb` uses color to highlight various interface elements, including ids, the
current notebook name, the shell prompt, and divider lines.
`nb` includes several built-in color themes and also supports user-defined
themes. The current color theme can be set using
[`nb set color_theme`](#color_theme):
```bash
nb set color_theme
```
#### Built-in Color Themes
##### `blacklight`
|  | 
|:--:|:--:|
| | |
##### `console`
|  |  |
|:--:|:--:|
| | |
##### `desert`
|  |  |
|:--:|:--:|
| | |
##### `electro`
|  |  |
|:--:|:--:|
| | |
##### `forest`
|  |  |
|:--:|:--:|
| | |
##### `monochrome`
|  |  |
|:--:|:--:|
| | |
##### `nb` (default)
|  |  |
|:--:|:--:|
| | |
##### `ocean`
|  |  |
|:--:|:--:|
| | |
##### `raspberry`
|  |  |
|:--:|:--:|
| | |
##### `unicorn`
|  |  |
|:--:|:--:|
| | |
##### `utility`
|  |  |
|:--:|:--:|
| | |
#### Custom Color Themes
Color themes are [`nb` plugins](#-plugins) with a `.nb-theme` file
extension and contain one `if` statement indicating the name and setting
the color environment variables to `tput` ANSI color numbers:
```bash
# turquoise.nb-theme
if [[ "${NB_COLOR_THEME}" == "turquoise" ]]
then
export NB_COLOR_PRIMARY=43
export NB_COLOR_SECONDARY=38
fi
```
View this theme as a complete file:
[`plugins/turquoise.nb-theme`](https://github.com/xwmx/nb/blob/master/plugins/turquoise.nb-theme)
Themes can be installed using [`nb plugins`](#plugins):
```bash
> nb plugins install https://github.com/xwmx/nb/blob/master/plugins/turquoise.nb-theme
Plugin installed:
/home/example/.nb/.plugins/turquoise.nb-theme
```
Once a theme is installed, use [`nb set color_theme`](#color_theme) to set it
as the current theme:
```bash
> nb set color_theme turquoise
NB_COLOR_THEME set to turquoise
```
The primary and secondary colors can also be overridden individually, making
color themes easily customizable:
```bash
# open the settings prompt for the primary color
nb set color_primary
# open the settings prompt for the secondary color
nb set color_secondary
```
To view a table of available colors and numbers, run:
```bash
nb set colors
```
#### Syntax Highlighting Theme
`nb` displays files with syntax highlighting when
[`bat`](https://github.com/sharkdp/bat),
[`highlight`](http://www.andre-simon.de/doku/highlight/en/highlight.php),
or
[Pygments](https://pygments.org/)
is installed.
When `bat` is installed, syntax highlighting color themes are
available for both light and dark terminal backgrounds.
To view a list of available themes and set the syntax highlighting color
theme, use [`nb set syntax_theme`](#syntax_theme).
### $ Shell Theme Support
- [`astral` Zsh Theme](https://github.com/xwmx/astral) - Displays the
current notebook name in the context line of the prompt.
### π Plugins
`nb` includes support for plugins, which can be used to create new
subcommands, design themes, and otherwise extend the functionality of `nb`.
`nb` supports two types of plugins, identified by their file extensions:
.nb-theme
- Plugins defining color themes.
.nb-plugin
- Plugins defining new subcommands and adding functionality.
Plugins are managed with the [`nb plugins`](#plugins) subcommand and
are installed in the `${NB_DIR}/.plugins` directory.
Plugins can be installed from either a URL or a path using the
[`nb plugins install`](#plugins) subcommand.
```bash
# install a plugin from a URL
nb plugins install https://raw.githubusercontent.com/xwmx/nb/master/plugins/copy.nb-plugin
# install a plugin from a standard GitHub URL
nb plugins install https://github.com/xwmx/nb/blob/master/plugins/example.nb-plugin
# install a theme from a standard GitHub URL
nb plugins install https://github.com/xwmx/nb/blob/master/plugins/turquoise.nb-theme
# install a plugin from a path
nb plugins install plugins/example.nb-plugin
```
The `` should be the full URL to the plugin file. `nb` also
recognizes regular GitHub URLs, which can be used interchangably with
raw GitHub URLs.
Installed plugins can be listed with [`nb plugins`](#plugins), which
optionally takes a name and prints full paths:
```bash
> nb plugins
copy.nb-plugin
example.nb-plugin
turquoise.nb-theme
> nb plugins copy.nb-plugin
copy.nb-plugin
> nb plugins --paths
/home/example/.nb/.plugins/copy.nb-plugin
/home/example/.nb/.plugins/example.nb-plugin
/home/example/.nb/.plugins/turquoise.nb-theme
> nb plugins turquoise.nb-theme --paths
/home/example/.nb/.plugins/turquoise.nb-theme
```
Use [`nb plugins uninstall`](#plugins) to uninstall a plugin:
```bash
> nb plugins uninstall example.nb-plugin
Plugin successfully uninstalled:
/home/example/.nb/.plugins/example.nb-plugin
```
#### Creating Plugins
Plugins are written in a Bash-compatible shell scripting language and
have an `.nb-plugin` extension.
`nb` includes a few example plugins:
- [`example.nb-plugin`](https://github.com/xwmx/nb/blob/master/plugins/example.nb-plugin)
- [`copy.nb-plugin`](https://github.com/xwmx/nb/blob/master/plugins/copy.nb-plugin)
- [`ebook.nb-plugin`](https://github.com/xwmx/nb/blob/master/plugins/ebook.nb-plugin)
Create a new subcommand in three easy steps:
##### 1. Add the new subcommand name with `_subcommands add `:
```bash
_subcommands add "example"
```
##### 2. Define help and usage text with `_subcommands describe `:
```bash
_subcommands describe "example" <`, and you can publish it on GitHub, GitLab, or
anywhere else online and install it with `nb plugins install `.
#### API
The `nb` API is the [command line interface](#nb-help), which is designed for
composability and provides a variety of powerful options for interacting with
notes, bookmarks, notebooks, and `nb` functionality. Within plugins,
subcommands can be called using their function names, which are named with
leading underscores. Options can be used to output information in formats
suitable for parsing and processing:
```bash
# print the content of note 3 to standard output with no color
_show 3 --print --no-color
# list all unarchived global notebook names
_notebooks --names --no-color --unarchived --global
# list all filenames in the current notebook
_list --filenames --no-id --no-indicator
# print the path to the current notebook
_notebooks current --path
```
##### Selectors
[`nb` notebooks](#-notebooks) can be selected by the user on a per-command
basis by prefixing the subcommand name or the note identifier (id, filename,
path, or title) with the notebook name followed by a colon. A colon-prefixed
argument is referred to as a "selector" and comes in two types: subcommand
selectors and identifier selectors.
*Subcommand Selectors*
```text
notebook:
notebook:show
notebook:history
notebook:a
notebook:q
```
*Idenitifer Selectors*
```text
1
example.md
title
/path/to/example.md
notebook:1
notebook:example.md
notebook:title
notebook:/path/to/example.md
```
`nb` automatically scans arguments for selectors with notebook names and
updates the current notebook if a valid one is found.
Identifier selectors are passed to subcommands as arguments along with
any subcommand options. Use [`show `](#show) to query
information about the file specified in the selector. For example, to
obtain the filename of a selector-specified file, use
`show --filename`:
```bash
_example() {
local _selector="${1:-}"
[[ -z "${_selector:-}" ]] && printf "Usage: example \\n" && exit 1
# Get the filename using the selector.
local _filename
_filename="$(_show "${_selector}" --filename)"
# Rest of subcommand function...
}
```
[`notebooks current --path`](#notebooks) returns the path to the current
notebook:
```bash
# _example() continued:
# get the notebook path
local _notebook_path
_notebook_path="$(_notebooks current --path)"
# print the file at "${_notebook_path}/${_filename}" to standard output
cat "${_notebook_path}/${_filename}"
```
See
[`copy.nb-plugin`](https://github.com/xwmx/nb/blob/master/plugins/copy.nb-plugin)
for a practical example using both [`show --filename`](#show) and
[`notebooks current --path`](#notebooks) along with other
subcommands called using their underscore-prefixed function names.
### > `nb` Interactive Shell
`nb` has an interactive shell that can be started with
[`nb shell`](#shell), `nb -i`, or `nb --interactive`:
```bash
$ nb shell
__ _
\ \ _ __ | |__
\ \ | '_ \| '_ \
/ / | | | | |_) |
/_/ |_| |_|_.__/
------------------
nb shell started. Enter ls to list notes and notebooks.
Enter help for usage information. Enter exit to exit.
nb> ls
home
----
[3] Example
[2] Sample
[1] Demo
nb> edit 3 --content "New content."
Updated: [3] Example
nb> bookmark https://example.com
Added: [4] π example.bookmark.md "Example Title (example.com)"
nb> ls
home
----
[4] π Example Title (example.com)
[3] Example
[2] Sample
[1] Demo
nb> bookmark url 4
https://example.com
nb> search "example"
[4] example.bookmark.md "Example (example.com)"
-----------------------------------------------
1:# Example (example.com)
3:
[3] example.md "Example"
------------------------
1:# Example
nb> exit
$
```
The `nb` shell recognizes all `nb` subcommands and options,
providing a streamlined, distraction-free approach for working with `nb`.
### Shortcut Aliases
Several core `nb` subcommands have single-character aliases to make
them faster to work with:
```bash
# `a` (add): add a new note named "example.md"
nb a example.md
# `b` (bookmark): list bookmarks
nb b
# `o` (open): open bookmark 12 in your web browser
nb o 12
# `p` (peek): open bookmark 6 in your terminal browser
nb p 6
# `e` (edit): edit note 5
nb e 5
# `d` (delete): delete note 19
nb d 19
# `s` (show): show note 27
nb s 27
# `q` (search): search notes for "example query"
nb q "example query"
# `h` (help): display the help information for the `add` subcommand
nb h add
# `u` (use): switch to example-notebook
nb u example-notebook
```
For more commands and options, run `nb help` or `nb help `
### Help
nb β’
bookmark β’
subcommands β’
plugins
#### `nb help`
```text
__ _
\ \ _ __ | |__
\ \ | '_ \| '_ \
/ / | | | | |_) |
/_/ |_| |_|_.__/
[nb] Command line note-taking, bookmarking, archiving with plain-text data
storage, encryption, filtering and search, Git-backed versioning and syncing,
Pandoc-backed conversion, global and local notebooks, customizable color
themes, plugins, and more in a single portable, user-friendly script.
Help:
nb help Display this help information.
nb help View help information for .
nb help --colors View information about color settings.
nb help --readme View the `nb` README file.
Usage:
nb
nb [...] [ | | | | ]
nb [] [...]
nb add [ | ] [-c | --content ]
[-e | --encrypt] [-f | --filename ]
[-t | --title ] [--type ]
nb bookmark [...]
nb bookmark [-c | --comment ] [--edit]
[-e | --encrypt] [-f | --filename ]
[-q | --quote] [-r | --related ]... [--save-source]
[--skip-content] [-t ,... | --tags ,...]
[--title ]
nb bookmark [list [...]]
nb bookmark (open | peek | url) ( | | | )
nb bookmark (edit | delete) ( | | | )
nb bookmark search
nb completions (check | install [-d | --download] | uninstall)
nb count
nb delete ( | | | ) [-f | --force]
nb edit ( | | | )
[-c | --content ] [--edit]
[-e | --editor ]
nb export ( | | | ) [-f | --force]
[...]
nb export notebook []
nb export pandoc ( | | | )
[...]
nb git [checkpoint [] | dirty]
nb git ...
nb help [] [-p | --print]
nb help [-c | --colors] | [-r | --readme] | [-s | --short] [-p | --print]
nb history [ | | | ]
nb import [copy | download | move] (... | ) [--convert]
nb import notebook []
nb init []
nb list [-e [] | --excerpt []] [--filenames]
[-n | --limit | --] [--no-id]
[--no-indicator] [-p | --pager] [--paths] [-s | --sort]
[-r | --reverse] [-t | --type | --]
[ | | | | ]
nb ls [-a | --all] [-e [] | --excerpt []] [--filenames]
[-n | --limit | --] [--no-id] [--no-indicator]
[-p | --pager] [--paths] [-s | --sort] [-r | --reverse]
[-t | --type | --]
[ | | | | ]
nb move ( | | | ) [-f | --force]
nb notebooks [] [--archived] [--global] [--local] [--names]
[--paths] [--unarchived]
nb notebooks add []
nb notebooks (archive | open | peek | status | unarchive) []
nb notebooks current [--path | --selected | --filename []]
[--global | --local]
nb notebooks delete [-f | --force]
nb notebooks (export [] | import )
nb notebooks init [ []]
nb notebooks rename
nb notebooks select
nb notebooks show ( | | ) [--archived]
[--escaped | --name | --path | --filename []]
nb notebooks use
nb show ( | | | ) [[-a | --added] |
--filename | --id | --info-line | --path | [-p | --print]
[-r | --render] | --selector-id | --title | --type [] |
[-u | --updated]]
nb notebooks use
nb open ( | | | | )
nb peek ( | | | | )
nb plugins [] [--paths]
nb plugins install [ | ] [--force]
nb plugins uninstall [--force]
nb remote [remove | set [-f | --force]]
nb rename ( | | | ) [-f | --force]
( | --reset | --to-bookmark | --to-note)
nb run [...]
nb search [-a | --all] [-t | --type | --]
[-l | --list] [--path]
nb set [ [] | []]
nb settings [colors [ | themes] | edit | list [--long]]
nb settings (get | show | unset) ( | )
nb settings set ( | )
nb shell [ [...] | --clear-history]
nb show ( | | | ) [--added | --filename |
--id | --info-line | --path | [-p | --print] [-r | --render] |
--selector-id | --title | --type [] | --updated]
nb show
nb subcommands [add ...] [alias ]
[describe ]
nb sync [-a | --all]
nb update
nb use
nb -i | --interactive [ [...]]
nb -h | --help | help [ | --readme]
nb --no-color
nb --version | version
Subcommands:
(default) List notes and notebooks. This is an alias for `nb ls`.
When a is provided, create a new bookmark.
add Add a new note.
bookmark Add, open, list, and search bookmarks.
completions Install and uninstall completion scripts.
count Print the number of notes.
delete Delete a note.
edit Edit a note.
export Export a note to a variety of different formats.
git Run `git` commands within the current notebook.
help View help information for the program or a subcommand.
history View git history for the current notebook or a note.
import Import a file into the current notebook.
init Initialize the first notebook.
list List notes in the current notebook.
ls List notebooks and notes in the current notebook.
move Move a note to a different notebook.
notebooks Manage notebooks.
open Open a bookmarked web page or notebook folder, or edit a note.
peek View a note, bookmarked web page, or notebook in the terminal.
plugins Install and uninstall plugins and themes.
remote Get, set, and remove the remote URL for the notebook.
rename Rename a note.
run Run shell commands within the current notebook.
search Search notes.
settings Edit configuration settings.
shell Start the `nb` interactive shell.
show Show a note or notebook.
status Run `git status` in the current notebook.
subcommands List, add, alias, and describe subcommands.
sync Sync local notebook with the remote repository.
update Update `nb` to the latest version.
use Switch to a notebook.
version Display version information.
Notebook Usage:
nb :[] [] [...]
nb : [...]
Program Options:
-i, --interactive Start the `nb` interactive shell.
-h, --help Display this help information.
--no-color Print without color highlighting.
--version Display version information.
More Information:
https://github.com/xwmx/nb
```
#### `bookmark help`
```text
__ __ __
/ /_ ____ ____ / /______ ___ ____ ______/ /__
/ __ \/ __ \/ __ \/ //_/ __ `__ \/ __ `/ ___/ //_/
/ /_/ / /_/ / /_/ / ,< / / / / / / /_/ / / / ,<
/_.___/\____/\____/_/|_/_/ /_/ /_/\__,_/_/ /_/|_|
bookmark -- Command line bookmarking with tagging, encryption,
full-text page content search with regular expression support,
GUI and terminal browser support, and data stored in plain text
Markdown files with Git-backed versioning and syncing.
Usage:
bookmark [...]
bookmark [-c | --comment ] [--edit]
[-e | --encrypt] [-f | --filename ]
[-q | --quote] [-r | --related ]... [--save-source]
[--skip-content] [-t ,... | --tags ,