https://github.com/dcsunset/rofi-snippets
A Rofi plugin to select snippets and simulate keyboard input of snippet content.
https://github.com/dcsunset/rofi-snippets
linux rofi rofi-mode snippets wayland x11
Last synced: 3 months ago
JSON representation
A Rofi plugin to select snippets and simulate keyboard input of snippet content.
- Host: GitHub
- URL: https://github.com/dcsunset/rofi-snippets
- Owner: DCsunset
- License: agpl-3.0
- Created: 2025-06-07T18:08:34.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-10T21:45:21.000Z (12 months ago)
- Last Synced: 2025-06-20T21:50:20.631Z (12 months ago)
- Topics: linux, rofi, rofi-mode, snippets, wayland, x11
- Language: Rust
- Homepage:
- Size: 42 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# rofi-snippets
A Rofi plugin to select snippets and simulate keyboard input of snippet content.
It supports both Wayland and X11.
## Installation
### Nix
This package is available as an [NUR](https://nur.nix-community.org/documentation/) package `nur.repos.dcsunset.rofi-snippets`.
It is also available from the flake output of the [NUR repo](https://github.com/DCsunset/nur-packages), where a NixOS overlay is provided as well.
To use it with NixOS:
```nix
environment.systemPackages = [
(pkgs.rofi.override (old: {
plugins = old.plugins ++ [nur.repos.dcsunset.rofi-snippets];
}))
];
```
Or you can also use it with home-manager:
```nix
programs.rofi = {
enable = true;
plugins = [nur.repos.dcsunset.rofi-snippets];
}
```
The NUR repo also provides a home-manager module via flake:
``` nix
{
imports = [ inputs.nur-dcsunset.homeManagerModules.rofi-snippets ];
# rofi should be enabled as well
programs.rofi.enable = true;
programs.rofi-snippets = {
enable = true;
settings = {
entries = [
{
key = "date";
snippet = {
type = "command";
value = [ "date" "--iso-8601" ];
trim = true;
};
}
];
};
};
}
```
### Pre-built Binaries
Pre-built binaries can be downloaded from GitHub release.
Put the downloaded `.so` file in Rofi lib dir depending on your Rofi installation (e.g. `/lib/rofi`) or add the plugin's dir to `ROFI_PLUGIN_PATH` environment variable.
Note that runtime dependencies (including glib, cairo, pango) must be installed before using the pre-built binaries.
If the pre-built binaries don't work for your system, try other installation methods.
### Manually
1. Clone this repo
2. Install dependencies based on your environment
- Common: rust, pkg-config, glib, cairo, pango, libxkbcommon
- X11: xdotool
3. Build the plugin
- Wayland only: `cargo build --release --features=wayland --no-default-features`
- X11 only: `cargo build --release --features=x11 --no-default-features`
- Both: `cargo build --release`
4. Move the built plugin (`target/release/librofi_snippets.so`) to Rofi lib dir or add the plugin's dir to `ROFI_PLUGIN_PATH` environment variable
## Usage
To start Rofi with rofi-snippets mode:
`rofi -show rofi-snippets -modes rofi-snippets`
## Configuration
Rofi-snippets will look for the configuration file in the following order (with environment variables):
- `$ROFI_SNIPPETS_CONFIG`
- `$XDG_CONFIG_HOME/rofi-snippets/config.json`
- `$HOME/.config/rofi-snippets/config.json`
The config file is in JSON format and follows the following structure (shown in Rust):
```rust
// Type for the whole config file
struct Config {
// shell command to use for shell snippet (default: sh)
shell: Option,
// snippet entries
entries: Vec,
// Delay time before sending input event to ensure rofi window closes (in ms)
delay: Option,
}
struct Entry {
// string to match in Rofi
key: String,
// Snippet will be used for simulating keyboard input
snippet: Snippet,
// (optionaL) extra description for this entry
description: Option,
}
// Snippet is a tagged union
#[serde(tag = "type", rename_all = "camelCase")]
enum Snippet {
// Use the text as is
Text { value: String },
// Run a command and use the output
// (the first elem is the command and the rest are arguments)
Command { value: Vec, trim: Option },
// Run a shell command and use the output
Shell { value: String, trim: Option },
// Evaluate a sequence of snippets and concatenate the outputs
Sequence { value: Vec },
}
// Use the text as is
type Text = {
type: "text",
value: string,
}
// Run a command and use the output
// (the first elem is the command and the rest are arguments)
type Command = {
type: "command",
value: string[],
trim?: boolean, // Trim whitespaces at the beginning and the end
}
// Run a shell command and use the output
type Shell = {
type: "shell",
value: string,
trim?: boolean, // Trim whitespaces at the beginning and the end
}
// Evaluate a sequence of snippets and concatenate the outputs
type Sequence = {
type: "sequence",
value: Snippet[],
}
```
Example:
```json
{
"shell": "bash",
"delay": 100,
"entries": [
{
"key": "hello",
"description": "Hello Test",
"snippet": {
"type": "text",
"value": "Hello world ❤️"
}
},
{
"key": "date",
"snippet": {
"type": "command",
"value": ["date", "--iso-8601"],
"trim": true
}
},
{
"key": "datetime",
"snippet": {
"type": "sequence",
"value": [
{ "type": "shell", "value": "date +%F", "trim": true },
{ "type": "text", "value": " " },
{ "type": "shell", "value": "date +%T", "trim": true }
]
}
}
]
}
```
## Licence
AGPL-3.0