Skip to content
BarbUkPublic

About

Snippet manager with rofi and fzf

Topics

Resources

Stars

25 stars

Watchers

1 watching

Forks

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

Nix

The flake provides home manager modules with options to enable wayland / x11 support.

Add it to your flake inputs

snippy = {
  url = "github:BarbUk/snippy";
  inputs.nixpkgs.follows = "nixpkgs";
};

Import the home manager module

imports = [
  inputs.snippy.homeManagerModule
];

# Or add it to shared modules
sharedModules = [
  snippy.homeManagerModule
];

Enable it in your home configuration

programs.snippy.enable = true;

# Explicitly disable Wayland / X11 support
# Defaults to installing both dependencies
programs.snippy.enableWayland = false;
programs.snippy.enableX11 = false;

Currently only x86_64-linux is supported (aarch64-linux support coming soon).

darwin systems are currently unsupported. See #34

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

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

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
  • gettext - Required for envsubst (variable expansion)

For X11:

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

For Wayland:

  • wl-clipboard (wl-copy and wl-paste)
  • wtype - Text input automation (for Sway, Hyprland, Niri)
  • dotool - Text input automation (required for KDE Plasma and GNOME)
  • wofi - Application launcher and menu (used on GNOME instead of rofi)

Optional (for enhanced features):

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

Debian / Ubuntu

# Base deps
sudo apt install rofi fzf jq gettext-base perl gawk

# For wayland (Sway, Hyprland, Niri)
sudo apt install wtype wl-clipboard

# For GNOME on Wayland
sudo apt install wofi

# For KDE / GNOME on Wayland
# dotool can be compiled from source (https://git.sr.ht/~geb/dotool)

# For X11
sudo apt install xsel xclip xdotool

Fedora

# Base deps
sudo dnf install rofi fzf jq gettext perl

# For wayland (Sway, Hyprland, Niri)
sudo dnf install wtype wl-clipboard

# For GNOME on Wayland
sudo dnf install wofi

# For KDE / GNOME on Wayland
# dotool is available via Copr or can be compiled from source

# For X11
sudo dnf install xsel xclip xdotool

Archlinux

# Base deps
sudo pacman -Sy rofi fzf jq gettext perl

# For wayland (Sway, Hyprland, Niri)
sudo pacman -Sy wtype wl-clipboard

# For GNOME on Wayland
sudo pacman -Sy wofi

# For KDE / GNOME on Wayland (dotool from AUR)
yay -S dotool

# For X11
sudo pacman -Sy xsel xclip xdotool

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

  • ##bash - Enable full Bash expansion (variables and command substitution). Use only for trusted snippets.

~/.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

Snippet location
  ~/.config/snippy

Options
  -h, --help 		Show help
  -s, --sort true|false Sort snippet in rofi
  -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 <name> 	Add a new snippet
  list 		list snippet
  cat 		list category
  completion 	bash completion. Use it with: eval "$(snippy completion)"

Examples

Browse and paste snippets (GUI mode):

snippy
# or explicitly
snippy gui

Use it directly inside rofi:

If you already have a keybinding for rofi, you can add snippy as a mod, it will autodetect rofi:

rofi -theme-str 'element-icon { size: 3ch;}' -combi-modi 'snippets:snippy' -show combi -modi combi

Note: On Nix, rofi integration is currently unsupported and WIP. To use snippy, use the command snippy instead.

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

Manage snippets via Home Manager

Snippets can be managed from the provided home manager module. Simply add the snippets to programs.snippy.snippets. For example, the following will create a snippet in $HOME/.config/snippy/snippet/test:

programs.snippy.snippets."snippet/test" = ''
  Hello from home manager snippet!
'';

Keyboard Shortcuts

When using GUI mode with rofi:

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

When using GUI mode with wofi (on GNOME):

  • Enter - Paste processed snippet
  • Escape - Cancel snippet selection

Platform Support

Display Servers

  • X11 - Full support with xdotool, xsel, and xclip
  • Wayland - Full support with wl-clipboard, wtype (wlroots compositors), and dotool (KDE Plasma and GNOME)

Desktop Environments

Snippy has been tested and works with:

  • Wayland compositors and desktop environments:

    • Sway (uses wtype and rofi)
    • Hyprland (uses wtype and rofi)
    • Niri (uses wtype and rofi)
    • KDE Plasma (uses dotool and rofi)
    • GNOME (uses dotool and wofi)
  • X11 window managers:

    • All X11 window managers and desktop environments 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.

About

Snippet manager with rofi and fzf

Topics

Resources

Stars

25 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages