Leadr
Leadr is a customizable CLI shortcut manager inspired by the leader key concept in (Neo)Vim. Use memorable key sequences to quickly execute or insert commands in your terminal.
💪 Features
- Customizable Shortcuts: Define your own key sequences to set your prompt.
- Insert or Execute: Immediately execute
git statusor just insertgit commit -m ""ready for you to fill in. - Prepend/Append: Forgot
sudo? Just prepend it to the your prompt and keep typing. - Cursor Positioning: Automatically place your cursor at the right position after inserting or replacing commands.
- Evaluate pre-insert: Need the current date in your file name? Evaluate a command, then insert it.
🎮 Usage
After installing leadr, you can start using it by pressing the leadr keybinding followed by a shortcut.
With the default config, you can e.g. execute git status by pressing <Ctrl-g> followed by gs.
Similarly, you can pre-populate git commit -m "" by pressing <Ctrl-g> followed by gc.
Notice how your cursor is placed in between the double quotes? Neat, right?
But that's not all!
<Ctrl-g>s will prepend sudo to your currently typed command, <Ctrl-g>c will append a pipe to the system clipboard.
To list your currently configured shortcuts, run:
Consult the Configuration section to learn how to make leadr your own.
⚡️ Requirements
- bash or zsh
- crossterm compatible terminal (see their Readme for a list)
Note: leadr works best inside a tmux session since it can utilize tmux's send-keys to execute commands.
Outside of tmux, leadr will fallback to eval and manually appending the command to the shell's history.
📦 Installation
You can download pre-built binaries from the releases page.
Just copy the binary to a directory in your PATH, e.g. using the following command:
You can install leadr using cargo:
This will install the latest version of leadr from crates.io.
You can build leadr from source using cargo:
🐚 Shell Integration
To use leadr, simply add the following line to your shell configuration file (e.g. ~/.bashrc or ~/.zshrc):
# For bash
# For zsh
🛠️ Configuration
Configuration File
leadr will automatically create a configuration file and fill it with some default shortcuts the first time you run it.
See confy's Readme for the location of the configuration file.
Modify the configuration file to add your own shortcuts or adjust the leadr keybinding.
Shortcuts
Define new shortcuts by adding a new entry to the shortcuts section of the configuration file.
The key will be the key sequence you want to use, command will be the command you want to execute or insert.
Optionally, add a description for the --list command to show.
Finally, you can customize the behavior of the shortcut by specifying insert_type, evaluate, and execute options.
Here's an overview of the available options:
| Setting | Options | Description |
|---|---|---|
insert_type |
'Replace' (default) | Clears the current prompt and replaces it with the command. Cursor will be placed at the end of the prompt. |
| 'Insert' | Inserts the command at the current cursor position. Cursor will be placed at the end of the inserted command. | |
| 'Prepend' | Prepends the command to the current prompt. Cursor will be placed where it was before adding the prefix. | |
| 'Append' | Appends the command to the current prompt. Cursor will be placed at the end of the prompt. | |
evaluate |
true or false (default) |
If true, the command will be evaluated before being inserted. |
execute |
true or false (default) |
If true, the command will be executed immediately. |
The cursor position after inserting or replacing commands can be customized by adding #CURSOR to the command.
For the git commit -m "" example, define the command as git commit -m "#CURSOR" to place the cursor between the double quotes after inserting the command.
This works for all insert types but will have no effect if evaluate or execute is set to true.
Leadr Keybinding
For a list of currently supported keybindings, see src/keymap.rs.
Visual Feedback
You can print the currently typed key sequence at the bottom right of your terminal by setting print_sequence = true.
Be aware though that this is somewhat experimental and might lead to issues.