
How about the convenience of copying files via the command line? You can quickly create your own command with C++.
See the step-by-step guide below!
Example for distros that use APT as the package manager
Look for corresponding names for your distro.
sudo apt install build-essential libx11-dev libxcb1-dev libpng-devAlso compile and install clip
git clone https://github.com/dacap/clip
cd clip
cmake . -B build
cmake --build build
sudo cmake --install buildExample: main.cpp
#include <clip.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <memory>
const auto use = [](){
std::cerr << "Use: xclip++ <file> [file...]\n";
};
class Xclip {
public:
Xclip(int argc, char** argv){
std::ostringstream buffer;
for (int i = 1; i < argc; ++i) {
std::ifstream file(argv[i], std::ios::binary);
if (!file) {
std::cerr << "Error opening: " << argv[i] << "\n";
std::exit(1);
}
buffer << file.rdbuf();
if(i + 1 < argc){
buffer << '\n';
}
}
clip::set_text(buffer.str());
}
};
int main(int argc, char** argv){
if(argc < 2){
use();
return 1;
}
auto xclip = std::make_unique<Xclip>(argc, argv);
}g++ main.cpp -o xclip++ -lclip -lxcb -lX11 -lpng -pthread
sudo install -v xclip++ /usr/local/bin/xclip++ file.txt
# Or multiple files
xclip++ file1.txt file2.md file3.cpp # ...See also: Copy and Paste via Linux Command Line with xclip
cpp cppdaily cli commands terminal