Skip to content

Instantly share code, notes, and snippets.

@metinsenturk
Created July 19, 2026 03:00
Show Gist options
  • Select an option

  • Save metinsenturk/d827d837ae582ac8ae019bda6330cad4 to your computer and use it in GitHub Desktop.

Select an option

Save metinsenturk/d827d837ae582ac8ae019bda6330cad4 to your computer and use it in GitHub Desktop.
Terminal Capture Tool

๐Ÿ“‹ c_pipe

A universal macOS clipboard utility built for Zsh that bridges the gap between running terminal commands and sharing outputs.

By appending | c to any command, it streams the output live to your console screen while simultaneously generating a beautifully structured, distinct text block on your macOS system clipboard. It works identically in the native Mac Terminal, iTerm2, and VS Code's integrated terminal.


๐Ÿš€ Usage

Simply attach | c to the end of your standard terminal workflow:

# Capture regular command output
sw_vers | c

# Capture commands that include errors (redirects stderr to stdout)
curl https://invalid-url.xyz 2>&1 | c

Clipboard Output Example

When you paste your clipboard (into Slack, GitHub, Notion, or an email), it will be formatted cleanly like this:

=== Copy Command: COMMAND ===
\$ sw_vers
=== Copy Command: OUTPUT  ===
ProductName:		macOS
ProductVersion:		14.5
BuildVersion:		23F79
=== Copy Command: END     ===

๐Ÿ› ๏ธ Installation

Option 1: Quick Install (Direct to .zshrc)

If you just want the tool quickly without managing extra files, paste the code inside c_pipe.zsh directly into the bottom of your ~/.zshrc file.

Option 2: Modular Install (Recommended for Dotfiles repos)

If you manage your configuration using a dotfiles repository or a custom functions folder:

  1. Clone or save this directory into your custom configuration path (e.g., ~/.config/zsh/functions/c_pipe/).
  2. Add the following safety check to your primary ~/.zshrc file to source it automatically:
# Replace the path below with the location where you saved the directory
export USER_FUNCTIONS_DIR="\$HOME/.config/zsh/functions"

if [ -f "\$USER_FUNCTIONS_DIR/c_pipe/c_pipe.zsh" ]; then
    source "\$USER_FUNCTIONS_DIR/c_pipe/c_pipe.zsh"
fi
  1. Restart your terminal or run source ~/.zshrc to activate.

๐Ÿ—บ๏ธ Future Roadmap (v2.0 Ideas)

  • Smart Markdown Auto-Wrapping: Automatically wrap the captured payload inside markdown code blocks (```bash) for instant, syntax-highlighted pasting on Slack or GitHub.
  • Automated Data Scrubbing: Use regex filters to automatically detect and replace sensitive text strings (like GitHub tokens, AWS keys, or passwords) with a [REDACTED] placeholder before it hits the clipboard.
# ==============================================================================
# COMMAND & OUTPUT CLIPBOARD CAPTURE UTILITY
# ==============================================================================
# DESCRIPTION:
# A universal macOS clipboard tool designed for Mac Terminal and VS Code.
# By appending '| c' to any command, it streams the output live to your
# terminal screen while simultaneously generating a clearly formatted,
# distinct block containing both the executed command and its full output
# directly onto your Mac clipboard.
#
# USAGE:
# [your-command] | c
# [your-command] 2>&1 | c (To also capture error outputs)
# ==============================================================================
c_pipe() {
# 1. Fetch the last command from history and clean up spaces/pipes
local last_cmd=$(fc -ln -1 | sed -E 's/[[:space:]]*\|[[:space:]]*c[[:space:]]*$//' | sed 's/^[ \t]*//')
# 2. Create a clean structure with distinct boundaries
{
echo "=== Copy Command: COMMAND ==="
echo "$ $last_cmd"
echo "=== Copy Command: OUTPUT ==="
} > /tmp/pipe_capture.txt
# 3. Stream the output live to your screen and append it to the file
tee -a /tmp/pipe_capture.txt
# 4. Append a closing footer for final separation
echo "=== Copy Command: END ===" >> /tmp/pipe_capture.txt
# 5. Push to the macOS clipboard and clean up
cat /tmp/pipe_capture.txt | pbcopy
rm /tmp/pipe_capture.txt
}
# Alias shortcut for command/output capture
alias c="c_pipe"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment