Skip to content

Commit 154053b

Browse files
committed
Allow to set default options with $BLOBDROP_ARGS
This is the easiest way to implement setting default values without having to implement an entire config system.
1 parent bc472b5 commit 154053b

File tree

6 files changed

+31
-7
lines changed

6 files changed

+31
-7
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if (UNIX AND NOT APPLE)
2525
endif()
2626

2727
include(FetchContent)
28-
FetchContent_Declare(quartz GIT_REPOSITORY https://github.com/vimpostor/quartz.git GIT_TAG 9f1ac6cce6b338c6613aa195cffe6f0bb5c965df)
28+
FetchContent_Declare(quartz GIT_REPOSITORY https://github.com/vimpostor/quartz.git GIT_TAG v0.7)
2929
FetchContent_MakeAvailable(quartz)
3030

3131
list(APPEND LINK_LIBS ${PKGCONFIG_MODULES})

doc/man/man1/blobdrop.1

+16
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,22 @@ Using this option causes blobdrop to quit after the first drag operation has fin
119119
.SS "all"
120120
With this option blobdrop keeps track of which items have been dragged already. It quits when all paths have been dragged at least once.
121121

122+
.SH DEFAULT ARGUMENTS
123+
The
124+
.B $BLOBDROP_ARGS
125+
environment variable can be used to provide default arguments. The default arguments will be prepended to the actually passed arguments, for example:
126+
.PP
127+
.in +2n
128+
.EX
129+
$ \fBBLOBDROP_ARGS\fP=\fI"\-f gui \-p"\fP \fBblobdrop\fP \-x \fInever\fP image.png
130+
$ # is equivalent to:
131+
$ \fBblobdrop\fP \-f \fIgui\fP \-p \-x \fInever\fP image.png
132+
.EE
133+
.in
134+
.PP
135+
136+
This can be useful to change the default value of some options permanently.
137+
122138
.SH EXAMPLES
123139
Here are some example usecases.
124140

flake.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
owner = "vimpostor";
1616
repo = "quartz";
1717
rev = builtins.head (builtins.match ".*FetchContent_Declare\\(.*GIT_TAG ([[:alnum:]\\.]+).*" (builtins.readFile ./CMakeLists.txt));
18-
hash = "sha256-UacYQ5c+MGUK4saLohnZs4691CBGI59JpkdgCaYbPUk=";
18+
hash = "sha256-cANBwVXcnWPaFE58lfbi53DUJ1mAmJL/p1hxoS5cX7s=";
1919
};
2020
makeStdenvPkg = env: env.mkDerivation {
2121
pname = "blobdrop";

src/getopts.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55

66
namespace Getopts {
77

8-
bool parse(QCoreApplication &app) {
8+
QStringList setup_args(int argc, char *argv[]) {
9+
const auto *env = std::getenv("BLOBDROP_ARGS");
10+
return quartz::getopts::prepend_args(argc, argv, env);
11+
}
12+
13+
bool parse(const QStringList &args) {
914
QCommandLineParser p;
1015
p.setApplicationDescription("Quickly drag and drop files from the terminal to applications.");
1116
p.addHelpOption();
@@ -49,7 +54,7 @@ bool parse(QCoreApplication &app) {
4954
"behaviour");
5055

5156
p.addOptions({frameless_opt, cursor_opt, frontend_opt, intercept_opt, keep_opt, persistent_opt, remote_opt, ontop_opt, auto_quit_opt});
52-
p.process(app);
57+
p.process(args);
5358

5459
if (p.isSet(auto_quit_opt)) {
5560
const auto opt = p.value(auto_quit_opt);
@@ -90,5 +95,4 @@ bool parse(QCoreApplication &app) {
9095
std::ranges::for_each(p.positionalArguments(), [](auto i) { PathRegistry::get()->add_path(i.toStdString()); });
9196
return true;
9297
}
93-
9498
}

src/getopts.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
#include <QCommandLineParser>
44
#include <iostream>
5+
#include <quartz/getopts.hpp>
56

67
#include "path_registry.hpp"
78
#include "settings.hpp"
89

910
namespace Getopts {
10-
bool parse(QCoreApplication &app);
11+
12+
QStringList setup_args(int argc, char *argv[]);
13+
bool parse(const QStringList &args);
1114
}

src/main.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ int main(int argc, char *argv[]) {
2424
quartz::Signals signal_handler {{SIGINT, SIGHUP, SIGTERM, SIGQUIT}, [](int) { Backend::get()->quit_delayed(0ms); }};
2525
#endif
2626

27-
if (!Getopts::parse(app)) {
27+
const auto &args = Getopts::setup_args(argc, argv);
28+
if (!Getopts::parse(args)) {
2829
return EXIT_FAILURE;
2930
}
3031

0 commit comments

Comments
 (0)