/nap

Code snippets in your terminal 🛌

Primary LanguageGo

Nap

Nap

zzz

Nap is a code snippet manager for your terminal. Create and access new snippets quickly with the command-line interface or browse, manage, and organize them with the text-user interface. Keep your code snippets safe, sound, and well-rested in your terminal.



Text-based User Interface

Launch the interactive interface:

nap

Key Bindings
Action Key
Create a new snippet n
Edit selected snippet (in $EDITOR) e
Copy selected snippet to clipboard c
Paste clipboard to selected snippet p
Delete selected snippet x
Rename selected snippet r
Set folder of selected snippet f
Set language of selected snippet L
Move to next pane tab
Move to previous pane shift+tab
Search for snippets /
Toggle help ?
Quit application q ctrl+c

Command Line Interface

Create new snippets:

# Quick save an untitled snippet.
nap < main.go

# From a file, specify Notes/ folder and Go language.
nap Notes/FizzBuzz.go < main.go

# Save some code from the internet for later.
curl https://example.com/main.go | nap Notes/FizzBuzz.go

# Works great with GitHub gists
gh gist view 4ff8a6472247e6dd2315fd4038926522 | nap

Output saved snippets:

# Fuzzy find snippet.
nap fuzzy

# Write snippet to a file.
nap go/boilerplate > main.go

# Copy snippet to clipboard.
nap foobar | pbcopy
nap foobar | xclip

List snippets:

nap list

Fuzzy find a snippet (with Gum).

nap $(nap list | gum filter)

Installation

Install with Go:

go install github.com/maaslalani/nap@main

Or download a binary from the releases.

Customization

Nap is customized through environment variables:

  • NAP_HOME, the folder where your snippets will rest. Defaults to $XDG_DATA_HOME/nap.

  • NAP_DEFAULT_LANGUAGE, the language your snippets will use by default.

  • NAP_THEME, the theme to highlight code. Defaults to dracula.

  • NAP_PRIMARY_COLOR / NAP_PRIMARY_COLOR_SUBDUED, the color to use for the active pane title bars.

  • NAP_RED / NAP_BRIGHT_RED, the colors to use for the selected item being deleted.

  • NAP_GREEN / NAP_BRIGHT_GREEN, the colors to use for the selected item being copied.

  • NAP_FOREGROUND / NAP_BACKGROUND, the colors to use for the foreground and background colors.

  • NAP_BLACK / NAP_WHITE / NAP_GRAY, the colors to use for the unselected items.


image

License

MIT

Feedback

I'd love to hear your feedback on improving nap.

Feel free to reach out via:


zzz