Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

BarbUk/snippy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Snippy

A powerful Linux snippet manager for enhanced productivity and workflow automation.

snippy

Overview

Snippy is a versatile command-line snippet manager that seamlessly integrates with your desktop environment to provide quick access to frequently used text snippets, commands, and templates.

Table of Contents

Table of Contents

Installation

Arch Linux

snippy on AUR

Snippy is available in the AUR as snippy-snippet.

Install using your preferred AUR helper:

yay -S snippy-snippet

Manual Installation

For local user installation:

curl -fsSL https://github.com/barbuk/snippy/releases/latest/download/snippy \
  --create-dirs --output ~/.bin/snippy
chmod +x ~/.bin/snippy

Ensure ~/.bin is in your PATH.

For system-wide installation:

sudo curl -fsSL https://github.com/barbuk/snippy/releases/latest/download/snippy \
  --output /usr/bin/snippy
sudo chmod +x /usr/bin/snippy

Initial Setup

Prerequisites

Prerequisites

Snippy requires the following dependencies to be installed:

Core dependencies:

  • rofi - Application launcher and menu
  • fzf - Command-line fuzzy finder
  • jq - JSON processor

For X11:

  • xsel - Command-line clipboard utility
  • xclip - Clipboard interface
  • xdotool - X11 automation tool

For Wayland:

  • wtype - Text input automation
  • wl-clipboard (wl-copy and wl-paste)

Optional (for enhanced features):

  • bat or highlight - Syntax highlighting in preview
  • perl - Required for certain text processing features

On first run, Snippy will automatically create the configuration directory at ~/.config/snippy with a sample snippet.

Features

Intelligent Clipboard Management

Snippy provides advanced clipboard handling that preserves your workflow:

  • Automatic clipboard restoration - Your original clipboard content is automatically restored after pasting a snippet
  • Dynamic clipboard integration - Use {clipboard} placeholder to embed current clipboard content into snippets

~/.config/snippy/create\ database

CREATE DATABASE `{clipboard}` CHARACTER SET utf8 COLLATE utf8_general_ci;
  • URL-encoded clipboard - Use {clipboard_urlencode} for web-safe clipboard content

~/.config/snippy/cached\ url

https://cachedview.nl/#{clipboard_urlencode}

Smart Cursor Positioning

Control exactly where the cursor lands after snippet insertion using the {cursor} placeholder:

Single-line positioning:

~/.config/snippy/pre

<pre>{cursor}</pre>

Multi-line positioning:

~/.config/snippy/pre\ multiline

<pre>
  {cursor}
</pre>

Snippy intelligently handles cursor movement in both CLI and GUI contexts, including special support for Vim.

Dynamic Content Processing

Variable expansion: Snippy processes snippets through a bash-like template engine, allowing you to use variables and command substitution:

~/.config/snippy/date\ and\ user

Current date: $(date +%Y-%m-%d)
Username: $USER

Command execution: Snippets starting with $ are executed as commands, and their output is pasted:

~/.config/snippy/date

$(date +%Y-%m-%d-%Hh%Mm%S)

Script execution: Bash scripts stored in $snippets_directory/scripts are automatically executed when selected.

Raw content mode: Use Ctrl+Return to paste the snippet source code instead of its processed output.

Snippet Headers

Control snippet behavior with special headers:

  • ##noparse - Disable variable expansion and command execution

~/.config/snippy/cmd\ last\ month

##noparse
date --date="$(date +%F) -1 month" +%F
  • ##tmpfile - Create a tempfile accessible via $tmpfile variable

~/.config/snippy/test\ tmpfile

##tmpfile
$(xsel -b > $tmpfile; cat $tmpfile)
  • ##richsnippet - Enable HTML clipboard support for rich text pasting

~/.config/snippy/test\ html

##richsnippet
<strong>should be pasted as strong</strong>

Visual Organization

Organize your snippets with directory-based categorization. The top-level directory name is used as an icon identifier in rofi:

terminal/
├── commands/
│   └── date
└── scripts/
    └── backup

icons

Usage

Command Line Interface

/usr/bin/snippy-snippet 1.0.11

Usage:
  /usr/bin/snippy-snippet [OPTION] ACTION
  Snippy snippets manager
Options
  -h, --help: Show help
  -s, --sort: true or false Sort snippet in rofi (default)
  -m, --sorting-method: fzf (default) or levenshtein
Actions
  gui  Browse snippet and paste it in the focused window (default)
  cli  list snippet in cli mode, only copy snippet in the paste buffer
  edit   Browse snippet and edit it
  add snippet_name   Add a new snippet
  list   list snippet
  cat  list category
  completion   bash completion

Examples

Browse and paste snippets (GUI mode):

snippy
# or explicitly
snippy gui

Browse snippets in terminal:

snippy cli

Create a new snippet:

snippy add database/mysql-create

Edit an existing snippet:

snippy edit

List all snippets:

snippy list

Bash Completion

Enable tab completion for Snippy commands and options by adding this line to your ~/.bashrc:

eval "$(snippy completion)"

Creating Snippets

Snippets are stored as plain text files in ~/.config/snippy. The directory structure you create becomes your snippet organization system.

Basic Snippet

Create a file with your desired content:

mkdir -p ~/.config/snippy/greetings
echo "Hello from Snippy!" > ~/.config/snippy/greetings/hello

Snippet with Variables

Use bash variable expansion and command substitution:

mkdir -p ~/.config/snippy/dates
cat > ~/.config/snippy/dates/current-datetime << 'EOF'
Current date and time: $(date '+%Y-%m-%d %H:%M:%S')
User: $USER
EOF

Snippet with Placeholders

Use Snippy's special placeholders:

mkdir -p ~/.config/snippy/sql
cat > ~/.config/snippy/sql/create-database << 'EOF'
CREATE DATABASE `{clipboard}`
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;

USE `{clipboard}`;
{cursor}
EOF

Executable Snippet

Create a snippet that executes a command:

echo '$(date +%Y-%m-%d-%Hh%Mm%S)' > ~/.config/snippy/dates/timestamp

Script Snippet

Create an executable bash script in the scripts directory:

mkdir -p ~/.config/snippy/scripts
cat > ~/.config/snippy/scripts/system-info << 'EOF'
#!/bin/bash
echo "System Information"
echo "=================="
echo "Hostname: $(hostname)"
echo "Kernel: $(uname -r)"
echo "Uptime: $(uptime -p)"
EOF

No-Parse Snippet

Prevent processing of special characters:

cat > ~/.config/snippy/examples/raw << 'EOF'
##noparse
This will be pasted as-is: $(date) $USER {cursor} {clipboard}
EOF

Rich Snippet (HTML)

Enable HTML clipboard support:

cat > ~/.config/snippy/html/bold-text << 'EOF'
##richsnippet
<strong>{clipboard}</strong>
EOF

Keyboard Shortcuts

When using the GUI mode with rofi:

  • Enter - Paste processed snippet (variables expanded, commands executed)
  • Ctrl+Return - Paste raw snippet content without processing
  • Escape - Cancel snippet selection

Platform Support

Display Servers

  • X11 - Full support with xdotool, xsel, and xclip
  • Wayland - Full support with wl-clipboard and wtype

Desktop Environments

Snippy has been tested and works with:

  • Wayland compositors:

    • Sway
    • Hyprland
    • Niri
  • X11 window managers:

    • All X11 window managers should be supported

Configuration

Snippy uses a convention-over-configuration approach. Most behavior is controlled through snippet headers and directory structure rather than configuration files.

Environment Variables

  • XDG_CONFIG_HOME - If set, snippets are stored in $XDG_CONFIG_HOME/snippy
  • EDITOR - Used for editing snippets (defaults to vim)

Snippet Location

Default: ~/.config/snippy

You can organize snippets in subdirectories. The top-level directory name is used as the icon identifier in rofi.

Contributing

Contributions are welcome! Here are ways you can help:

  • Report bugs and request features via GitHub Issues
  • Submit pull requests for bug fixes and enhancements
  • Improve documentation
  • Share your snippet collections and use cases

License

Snippy is licensed under the GNU General Public License v3.0.

Acknowledgments

Snippy builds upon the work of several contributors:

Special thanks to the open-source community for the excellent tools that make Snippy possible: rofi, fzf, and all the clipboard and automation utilities.