Skip to content

Commit ab23336

Browse files
committed
clipctl: cache-dir/version support
These were supported by the end in 6.3.0, let's make sure we also support them in v7.
1 parent 614206e commit ab23336

5 files changed

Lines changed: 26 additions & 6 deletions

File tree

man/clipctl.1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ Invert the current state of clipboard collection.
2222
.TP
2323
.B status
2424
Print the current state of clipboard collection.
25+
.TP
26+
.B version
27+
Print the major clipmenu version.
28+
.TP
29+
.B cache-dir
30+
Print the cache directory used by clipmenud.
2531

2632
.TP
2733
clipctl also accepts one dash option:

src/clipctl.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,31 @@ static bool _nonnull_ should_enable(struct config *cfg, const char *mode_str) {
7070
int main(int argc, char *argv[]) {
7171
_drop_(config_free) struct config cfg = setup("clipctl");
7272
exec_man_on_help(argc, argv);
73-
die_on(argc != 2, "Usage: clipctl <enable|disable|toggle|status>\n");
73+
die_on(argc != 2,
74+
"Usage: clipctl <enable|disable|toggle|status|version|cache-dir>\n");
75+
76+
const char *cmd = argv[1];
77+
78+
if (streq(cmd, "cache-dir")) {
79+
printf("%s\n", get_cache_dir(&cfg));
80+
return 0;
81+
}
82+
if (streq(cmd, "version")) {
83+
printf("%d\n", CLIPMENU_VERSION);
84+
return 0;
85+
}
7486

7587
pid_t pid = get_clipmenud_pid();
7688
die_on(pid == -ENOENT, "clipmenud is not running\n");
7789
die_on(pid == -EEXIST, "Multiple instances of clipmenud are running\n");
7890
expect(pid > 0);
7991

80-
if (streq(argv[1], "status")) {
92+
if (streq(cmd, "status")) {
8193
printf("%s\n", is_enabled(&cfg) ? "enabled" : "disabled");
8294
return 0;
8395
}
8496

85-
bool want_enable = should_enable(&cfg, argv[1]);
97+
bool want_enable = should_enable(&cfg, cmd);
8698

8799
expect(kill(pid, want_enable ? SIGUSR2 : SIGUSR1) == 0);
88100
dbg("Sent signal to pid %d\n", pid);

src/config.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include "config.h"
1010
#include "x.h"
1111

12-
#define CLIPMENU_VERSION 7
13-
1412
/**
1513
* Determines the runtime directory for storing application data. This is _not_
1614
* the clip store, but the place to create the directory that will become it

src/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include "util.h"
1111

12+
#define CLIPMENU_VERSION 7
13+
1214
struct selection {
1315
const char *name;
1416
bool active;

tests/x_integration_tests

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export CM_DIR=$(mktemp -d)
3939
export CM_DEBUG=1
4040
export ASAN_OPTIONS='halt_on_error=1:abort_on_error=1'
4141
export UBSAN_OPTIONS='halt_on_error=1:abort_on_error=1'
42+
uid=$(id -u)
43+
[[ "$(clipctl version)" == 7 ]]
44+
[[ "$(clipctl cache-dir)" == "$CM_DIR/clipmenu.7.$uid" ]]
4245

4346
launcher=$(mktemp)
4447
l_out=$(mktemp)
@@ -60,7 +63,6 @@ export CM_LAUNCHER="$launcher"
6063
tilde_home=$(mktemp -d)
6164
tilde_dir="$tilde_home/clipmenu_tilde"
6265
mkdir -p "$tilde_dir"
63-
uid=$(id -u)
6466
HOME="$tilde_home" CM_DIR="~/clipmenu_tilde" CM_CONFIG="$(mktemp)" \
6567
clipmenu || true
6668
[[ -d "$tilde_dir/clipmenu.7.$uid" ]]

0 commit comments

Comments
 (0)