A simple command-line Python script that copies the contents of a text file to the clipboard. Works with Linux X11 environments and uses tkinter to interface with the clipboard.
- Copy the contents of a file to the clipboard.
- Trim whitespace before copying (optional).
- Print the file contents to stdout (optional).
- Verbose output for debugging (optional).
- Supports running the script with a simple
copyfilecommand after setup.
- Python 3.x
- X11 (for clipboard access)
- Tkinter (for clipboard management with X11)
git clone https://github.com/JPDeerenberg/copyfile
cd copyfilechmod +x copyfile.pymv copyfile.py copyfileTo run the copyfile command from anywhere, you need to add it to your system's PATH.
sudo mv copyfile /usr/local/bin/Add this line to your shell config (~/.bashrc, ~/.zshrc, etc.):
export PATH=$PATH:/path/to/your/script/directoryThen source the file:
source ~/.bashrc # or source ~/.zshrcOnce installed, you can use the script from the command line.
copyfile filename.txtCopies the contents of filename.txt to the clipboard.
--trim: Trim whitespace before copying.--print: Print file contents to stdout.-v,--verbose: Show verbose output during copying.
Example:
copyfile filename.txt --trim --verbose- The script checks for missing or unreadable files.
- It ensures you're running in an X11 environment with the
DISPLAYvariable set.
This project is licensed under the MIT License - see the LICENSE file for details.