A terminal user interface (TUI) tool for interactively selecting and extracting code blocks or links from Markdown files and copy them to the clipboard, ready for being pasted right in the command line or anywhere else.
mdpick is essentially a snippet manager that uses Markdown files to store the snippets that can be filtered, copied and pasted in a single interactive session. mdpick is a read-only tool, meaning that it just reads from the input file/stream, while it does not support the insertion or the editing of Markdown content (there are so many options for this).
Moreover, mdpick supports entire Markdown codeblocks and single lines within codeblocks. Finally, it supports sending snippets to side panes in a Tmux session, so that commands are executed without leaving the TUI, or can be copied to a text editor.
I find comfortable to add and edit snippets and cheat commands - often saved from the history - into Markdown files: (almost) standard, easy to edit, human friendly, etc.
There are many cases in which I need to execute a sequence of commands, e.g., for setup or installation of tools.
Moreover, I find it useful to be able to do these operations on different sources, e.g., READMEs of different projects.
The usual copy&pasting to the command line from a file opened in the editor is not much comfortable.
Moreover, I prefer to not use snippet managers that directly execute the command, since 1) I want it to be recorded in the history 2) I don't want an intermediate layer between the command and the shell.
The initial version of mdpick was a simple Bash script arranged with awk+fzf+xclip.
However, this required to re-open the list of snippets every time to look for the next command to execute.
All these considerations lead to the development of mdpick, which evolved into a small, compact but functional tool to retrieve commands, snippets and links from Markdown files and copy them into clipboard for later use, or send them straight to a Tmux side pane, with the option to execute them directly in the pane.
The Go language was picked for its speed, friendliness to C programmers (like myself), and possibility to produce a self-contained executable.
- Interactive TUI: Browse and filter items with a full-screen terminal interface
- Code block extraction: Extract code blocks from Markdown with optional context paragraphs (full codeblocks or single lines)
- Link extraction: Extract Markdown links in a readable format
- Real-time filtering: Type to filter items as you search
- Clipboard integration: Automatically copies selected content to clipboard
- Tmux integration: Send commands directly to tmux panes with optional execution
- Multi-copy mode: Copy multiple items in a single session
- Language filtering: Filter code blocks by programming language
- Go 1.21 or later
git clone https://github.com/toolleeo/mdpick
cd mdpick
go mod download
go build -o mdpickmdpick [OPTIONS] [FILE]
mdpick can read from:
- A file specified with
-for--file - A file specified as a positional argument
- Standard input (stdin) via pipe
Read from a file:
mdpick document.mdRead from stdin:
cat document.md | mdpickBy default, mdpick extracts code blocks from Markdown.
To extract only bash code blocks:
mdpick -l bash document.mdThe "language" of the codeblock must be specified in the Markdown file (no auto-detection).
Include one paragraph before and after each code block:
mdpick -b 1 -a 1 document.mdExample of combined options:
mdpick -l python -b 2 -a 1 document.mdUse the --links flag to extract Markdown links instead of code blocks:
# Extract all links from a file
mdpick --links document.md
# Extract links from stdin
cat document.md | mdpick --linksUse -m or --multi to copy multiple items in one interactive session:
mdpick -m document.mdIn multi-copy mode:
- Press Enter to copy the current item to clipboard
- Press Ctrl+Q to quit and print the last copied item
- Press Ctrl+C to quit without printing
When running inside a tmux session, mdpick can send commands directly to other panes.
Enable tmux mode with -t or --tmux:
mdpick -t commands.mdThis will:
- Copy the selected code to clipboard
- Send the code to a side pane (automatically detected)
- Move focus to the target pane
Use -e or --execute to automatically execute commands in the target pane:
mdpick -e setup.mdThis will:
- Copy the selected code to clipboard
- Send the code to the target pane
- Automatically press Enter to execute it
- Keep focus in the mdpick pane for the next command
When tmux mode is active:
- Ctrl+P: Open pane selector to choose target pane
- Ctrl+E: Toggle execute mode on/off
- Enter: Send command to target pane (and execute if in execute mode)
Run a sequence of setup commands in a side pane:
mdpick -e -m setup.mdSend commands to a pane without executing (review before running):
mdpick -t -m commands.mdExecute commands in a specific pane:
# Press Ctrl+P to select the target pane
mdpick -e workflow.md- Automatic Pane Detection: mdpick automatically finds a side pane (left or right)
- Pane Selection: Use Ctrl+P to view and select from all available panes
- Execute Toggle: Use Ctrl+E to switch between copy mode and execute mode
- Focus Management:
- Copy mode: focus moves to target pane after sending
- Execute mode: focus stays in mdpick for sequential commands
$ mdpick --help
Usage of mdpick:
-a, --after int Number of paragraphs after codeblock
-b, --before int Number of paragraphs before codeblock
-e, --execute Execute in tmux pane (implies -t)
-f, --file string File to read items from
-l, --lang string Filter codeblocks by language
--links Extract markdown links instead of codeblocks
-m, --multi Multi-copy mode
-t, --tmux Tmux mode - send to pane
Find all bash scripts in several Markdown files and select one:
cat *.md | mdpick -l bash -mProcess a README file from Github:
curl -s https://raw.githubusercontent.com/user/repo/main/README.md | mdpick --linksCopy selected code and save to file (perfect to extract a snippet):
mdpick -l go examples.md > selected_code.goCopy selected code and execute it, without using Tmux:
mdpick -l bash scripts.md | bashSelect a link and open it in browser:
mdpick --links bookmarks.md | xargs xdg-openThis project is licensed under the GNU General Public License v3.0. You are free to use, modify, and distribute this software under the terms of the GPL-3.0 license. See the LICENSE file for the full license text.
