├── .gitignore ├── demo.gif ├── drag.pro ├── Dockerfile ├── drag.py ├── drag.cpp └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | *.o 3 | .qmake.stash 4 | bin/ 5 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkevin-arch/CLIdrag/HEAD/demo.gif -------------------------------------------------------------------------------- /drag.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | TARGET = bin/drag 3 | SOURCES += drag.cpp 4 | QMAKE_CXXFLAGS += -std=c++17 5 | LIBS += -lstdc++fs 6 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:latest 2 | RUN apt update && apt install -y qt5-default g++ make 3 | RUN mkdir /src /dist 4 | WORKDIR /src 5 | CMD ["sh", "-c", "qmake && make"] 6 | -------------------------------------------------------------------------------- /drag.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import sys 3 | import os 4 | import signal 5 | from PyQt5.QtCore import Qt, QUrl, QMimeData 6 | from PyQt5.QtWidgets import QApplication, QLabel 7 | from PyQt5.QtGui import QDrag 8 | 9 | class MainWindow(QLabel): 10 | def __init__(self, l): 11 | super().__init__() 12 | mimedata = QMimeData() 13 | mimedata.setUrls([QUrl.fromLocalFile(os.path.abspath(fn)) for fn in l]) 14 | qdrag = QDrag(self) 15 | qdrag.setMimeData(mimedata) 16 | qdrag.exec(Qt.DropAction.MoveAction) 17 | 18 | if __name__ == "__main__": 19 | if len(sys.argv) < 2: 20 | print("Usage: %s FILENAME [FILENAME ...]"%sys.argv[0]) 21 | print("Initiates a drag operation as if you're dragging a file / multiple files.") 22 | print("Click in the window you want to drag the files to.") 23 | sys.exit() 24 | app = QApplication(sys.argv) 25 | signal.signal(signal.SIGINT, signal.SIG_DFL) 26 | window = MainWindow(sys.argv[1:]) 27 | -------------------------------------------------------------------------------- /drag.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | int main(int argc, char *argv[]) 8 | { 9 | if(argc==1){ 10 | std::cout << "Usage: " << argv[0] << " FILENAME [FILENAME ...]" << std::endl; 11 | std::cout << "Initiates a drag operation as if you're dragging a file / multiple files." << std::endl; 12 | std::cout << "Click in the window you want to drag the files to." << std::endl; 13 | return 0; 14 | } 15 | 16 | QGuiApplication app(argc, argv); 17 | 18 | QList urls; 19 | for(int i=1;isetUrls(urls); 29 | 30 | QObject dummyobj; 31 | QDrag* qdrag = new QDrag(&dummyobj); 32 | qdrag->setMimeData(mimedata); 33 | qdrag->exec(); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CLIDrag 2 | 3 | This is a CLI tool that simulates dragging files into GUI applications. Comes with a C++ and a Python version. 4 | 5 | ## Demo 6 | 7 | ![demo.gif](demo.gif) 8 | 9 | ## Use case 10 | 11 | I'm primarily a Linux command line user who rarely use GUI file managers. When I want to send a file through Discord or something similar, I either have to a) open Nautilus, find the file and drag it over, or b) use the file picker and dig through my files. Using this tool, you can just start a drag from the CLI and send the file(s) to your desired GUI application. 12 | 13 | ## C++ version dependencies 14 | 15 | This depends on Qt5, which should hopefully be on most distros by default. 16 | 17 | ## Python version dependencies 18 | 19 | This depends on PyQt5. You may have to `pip install` it or use your favorite package manager. 20 | 21 | ## C++ version compilation 22 | 23 | You'll need qmake and g++ to compile this program. A Dockerfile is provided, and I used the following command in the git directory to build the program: 24 | 25 | ```sh 26 | docker build -t build-drag . && docker run -it --rm -v `pwd`:/src build-drag 27 | ``` 28 | 29 | Afterwards, the binary should be in the `bin` folder. 30 | 31 | ## License and contributing 32 | 33 | [Do whatever the heck you want with this code.](http://www.wtfpl.net/) No credit necessary. Make whatever issues and PRs you want, and I'll fix the issue / merge the PR it if its reasonable. 34 | --------------------------------------------------------------------------------