Skip to content

MichaelOskin/prompt-saver

Repository files navigation

Prompt Saver (pmsv)

Prompt Saver (pmsv) is a fast and convenient CLI utility for saving, managing, and searching your AI prompts.

The utility supports a hierarchical topic structure, tags, usage history, and powerful interactive search via fzf.

img

Key Features

  • Saving and Management: Easily save, edit, and delete prompts.
  • Topic Hierarchy: Organize prompts into a tree-like topic structure (e.g., java/testing/junit).
  • Interactive Search: Instant fuzzy search by names and content using fzf.
  • Copy to Clipboard:
  • History:

Build and Installation

Requirements

  • JDK (Java 21+).
  • GraalVM (for native compilation).
  • fzf (for interactive search pmsv find).

Build

  1. Clone the repository:

    git clone <repository_address>
    cd prompt-saver
  2. Compile the native executable: Gradle and the GraalVM plugin are used for building. Run the following command:

    ./gradlew nativeCompile

    This process may take several minutes.

  3. Install to PATH: After successful compilation, the executable will be located in build/native/nativeCompile/prompt-saver.

    For ease of use, move it or create a symbolic link in a directory that is in your system's PATH.

    # Example for Linux/macOS
    sudo mv build/native/nativeCompile/prompt-saver /usr/local/bin/pmsv

    After this, you can call the utility from anywhere simply by its name pmsv.


Usage

All commands use the alias pmsv.

Saving a prompt (save)

# Save a simple prompt from a string
pmsv save my-prompt "Это мой первый промпт" --topic "general"

# Save a prompt with tags and a nested topic
pmsv save stream-api-example "Пример использования Java Stream API для фильтрации..." \
  --topic "java/core" --tags "stream,api,java8"

# Save a prompt by reading its content from a file (via stdin)
cat my_prompt_file.txt | pmsv save file-prompt --topic "files"

Getting a prompt (get)

# Output the prompt content to stdout
pmsv get my-prompt

# Get the prompt and immediately copy it to the clipboard
pmsv get stream-api-example --copy

Editing a prompt (edit)

This command opens the content of the specified prompt in your system's text editor ($EDITOR).

pmsv edit my-prompt

After saving the file and closing the editor, the changes will be written to the database.

Deleting a prompt (rm)

# Delete a prompt by name
pmsv rm file-prompt

Usage History (history)

Shows recently used prompts (via get or find commands).

pmsv history

Displaying Topic Tree (tree)

# Show the hierarchy of all topics with the number of prompts in each
pmsv tree

Output example:

.
├── general (1)
├── git (1)
└── java (1)
    └── core (1)

Interactive Search (fzf)

The most powerful function for quick access to prompts.

pmsv find

This command launches fzf for interactive search. By default, pressing Enter copies the content of the selected prompt to the clipboard and outputs its name to stdout.

fzf Configuration

You can fine-tune fzf's behavior through the utility's configuration file (by default ~/.prompt_saver/config.yaml).

Example config.yaml:

---
active_profile: "default"
profiles_path: "/home/michaelos/.prompt_saver/profiles"
fzf_command_args:
- "fzf"
- "--prompt='Find Prompt> '"
- "--height=35%"
- "--layout=reverse"
- "--preview='pmsv get {}'"
- "--preview-window=right:60%"
- "--bind='enter:execute(pmsv get {} --copy > /dev/null)+accept'"

Explanation of fzf_command_args parameters:

  • --prompt='Find Prompt> ': Sets the input prompt text in fzf.
  • --height=35%: Limits the height of the fzf window to 35% of the terminal height.
  • --layout=reverse: Displays the list of results at the top, and the input field at the bottom.
  • --preview='pmsv get {}': Enables the preview window. fzf executes the pmsv get command for each selected item ({} is replaced by the prompt name), showing its content.
  • --preview-window=right:60%: Places the preview window on the right, occupying 60% of the width.
  • --bind='...': Allows overriding key actions. This is the most interesting flag:
    • enter:: Defines the action for the Enter key.
    • execute(pmsv get {} --copy > /dev/null): Execute an external command. Here we get the selected prompt and immediately copy it to the clipboard (--copy), and hide the command's standard output (> /dev/null) to avoid cluttering the terminal.
    • +accept: After executing execute, also perform the default action for Enter (in this case - terminate fzf and output the selected item to stdout).

JavaDoc

./gradlew javadoc
# doc : build/docs/javadoc/index.html

About

smart prompt saver for ai

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages