Skip to content

grab your last stdout on tmux and put it in your clipboard

Notifications You must be signed in to change notification settings

diffficult/tgrab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

📋 tgrab

A simple yet powerful script to grab and copy to clipboard the output of previously executed commands in your tmux session. Perfect for when you need to capture that command output you forgot to redirect to a file!

🚀 Features

  • Copy the last command's output to clipboard
  • Select specific previous command outputs (e.g., 2nd to last, 3rd to last, etc.)
  • Nice visual feedback with nerd font icons
  • Error handling with visually distinct messages
  • Automatic detection of missing dependencies

📋 Requirements

  • tmux
  • xclip (for clipboard operations)
  • zsh
  • A terminal with Nerd Fonts installed for the icons

📥 Installation

  1. Clone this repository:
git clone https://github.com/diffficult/tgrab.git
cd tgrab
  1. Make it executable:
chmod +x tgrab
  1. Move it to your local bin:
mv tgrab ~/.local/bin/

Make sure ~/.local/bin is in your PATH. If it's not, add this line to your ~/.zshrc:

export PATH="$HOME/.local/bin:$PATH"

🔧 Usage

The script can be used in two ways:

  1. Copy the last command's output:
tgrab
  1. Copy a specific previous command's output using the -p flag:
tgrab -p 3  # Copies the 3rd to last command output

Options

  • -p NUMBER: Specify which previous output to copy (default: 1)
  • -h: Show help message

📝 Examples

# Copy the last command's output
tgrab

# Copy the output from 3 commands ago
tgrab -p 3

# Show help
tgrab -h

⚠️ Error Handling

The script includes several error checks:

  • Verifies xclip is installed
  • Checks if there are enough previous outputs in buffer
  • Validates if there's actually content to copy
  • Ensures numeric input for the -p option

All errors are displayed with distinct red-on-white formatting and helpful icons.

🔍 Known Limitations

  • Works only within tmux sessions
  • Requires zsh as the shell
  • Designed for prompts using the ❯❯❯ symbol
  • Assumes a two-line prompt with pwd on first line

🤝 Contributing

Feel free to open issues or submit pull requests if you have suggestions for improvements!

Visit the repository at https://github.com/diffficult/tgrab

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Inspired by the common need to grab previous command outputs in tmux sessions
  • Icons provided by Nerd Fonts

About

grab your last stdout on tmux and put it in your clipboard

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages