zsh-cheatsheet is a lightweight Zsh plugin that provides context-aware interactive cheat sheets directly in your terminal. Using ZLE (Zsh Line Editor) and fzf, it gives you instant access to your command documentation without leaving the command line.
- Language: Zsh (Version 5.8 or higher required).
- Fuzzy Finder: fzf.
- Database: Markdown (
.md) files parsed on-the-fly. - Integration: Zsh Line Editor (ZLE) for native command buffer interaction.
The project follows a simple and high-performance architecture, prioritizing Zsh internal mechanisms:
- ZLE Integration: The plugin registers a
zsh-cheatsheet-openwidget that interacts directly with$BUFFERand$LBUFFER. - Markdown-as-Database: Cheat sheets are stored in the
cheats/directory. Each file follows a strict formatting contract for ultra-fast parsing without heavy external tools. - Autoloadable Functions: Business logic is decoupled into autoloadable functions in
functions/, ensuring minimal shell startup time. - Context Awareness: The plugin automatically detects the command being typed to open the relevant documentation directly.
- Zsh (5.8+)
- fzf installed and available in your
$PATH. - tldr (Optional) for extended command coverage.
-
Clone the repository into your custom plugins folder:
git clone https://github.com/Xav-Deb/zsh-cheatsheet.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-cheatsheet -
Add
zsh-cheatsheetto your plugins list in~/.zshrc:plugins=(... zsh-cheatsheet)
-
Reload your configuration:
source ~/.zshrc
-
Clone the repository:
git clone https://github.com/Xav-Deb/zsh-cheatsheet.git ~/.zsh-cheatsheet -
Source the plugin in your
~/.zshrc:echo "source ~/.zsh-cheatsheet/zsh-cheatsheet.plugin.zsh" >> ~/.zshrc
-
Context-Aware Search: Type a command (e.g.,
git) and pressCtrl+H(default). The plugin will detect the command and open the specific cheat sheet forgit.git <Ctrl+H>
-
Global Search: If the command line is empty or the command is not recognized, pressing
Ctrl+Hwill open a searchable list of all available cheat sheets. -
Navigation (fzf):
- Type to filter entries.
- Use
Up/Downarrows orCtrl+K/Ctrl+Jto navigate results. - Press
Enterto select a command. The command will be inserted under your cursor in the terminal, ready to be edited or executed. - Press
EscorCtrl+Cto close without inserting anything.
The default keybinding is ^H (Ctrl+H). To change it, define ZSH_CHEATSHEET_BIND before loading the plugin (or before source ~/.zshrc if using Oh-My-Zsh plugins) in your .zshrc:
# Example: bind to Ctrl+O
export ZSH_CHEATSHEET_BIND='^O'
plugins=(... zsh-cheatsheet)When you request help for a command that doesn't have a dedicated .md file in the cheats/ directory, the plugin automatically falls back to secondary sources:
- tldr (Optional): If the
tldrclient is installed, the plugin parses its output to extract interactive commands. - Man Pages: If
tldrisn't available, it parses themanpage's EXAMPLES section to find usable command lines. - App Help: As a final resort, it provides a shortcut to the application's own
--helpcommand.
All external entries are marked with a prefix in the search results: [tldr], [man], or [help].
-
Reload: If you modify a cheat sheet file manually, reload the plugin without restarting your shell:
zsh-cheatsheet reload
-
Update: Fetch the latest cheat sheets (if configured with remote source) and plugin updates:
zsh-cheatsheet update # Update database zsh-cheatsheet upgrade # Update plugin code source ~/.zshrc # Reload configuration to apply all changes
1. Type a command (e.g., git) to set the context.
2. Press Ctrl+H to open the interactive cheat sheet, filter with fzf, and press Enter to insert.
zsh-cheatsheet.plugin.zsh: Main entry point (loading, keybindings).functions/: Core logic for functions (open,update,upgrade).cheats/: Markdown "database" of cheat sheets.test/: Testing scripts and content validation.
- ποΈ Speed: Pure Zsh parsing; avoids heavy dependencies like grep, sed, or awk.
- π§ Contextual: Typing
gitthen the hotkey automatically opensgit.md. - β‘ Dynamic Fallbacks: If no local cheat sheet exists, it automatically pulls data from
tldr,manpages, or application--help. - π Fuzzy Search: Powered by
fzfwith category filtering based on H2 headers. - β¨οΈ Auto-Insertion: The selected command is inserted directly at the cursor position.
- π Auto-Update: Built-in commands to update the database and the plugin itself.
Development follows iterative steps defined in the project plan:
- Skeleton definition and widget registration.
- Context detection implementation.
fzfintegration.- Markdown parsing according to the contract.
- Command insertion logic.
- Fallback for global selection.
Every new feature must be validated by the scripts in test/.
- Prefer Zsh Builtins: Use parameter expansion and internal pattern matching instead of external system calls.
- Portability: Ensure support for both macOS and Linux (GNU/BSD compatibility).
- Buffer Safety: Never clear the user's buffer without explicit action.
- Markdown Contract:
- Exactly one
# <cmd>header at the top. ## <Category>sections for visual grouping.- Entries formatted as
- \command` β description`.
- Exactly one
The project includes an automated test suite to ensure stability:
- Syntax Check:
zsh -non all scripts. - Content Validation: Ensures all files in
cheats/follow the Markdown contract.
Run all tests with:
./test/run.shContributions are welcome! To add or modify a cheat sheet:
- Review the Coding Standards section to understand the Markdown contract.
- Add your file to the
cheats/directory. - Validate with
./test/run.sh. - Open a Pull Request.
Distributed under the MIT License. See LICENSE for more information.
Built with β€οΈ for the Zsh community.