aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2020-01-02 13:35:42 +0100
committerGerd Hoffmann <kraxel@redhat.com>2020-01-02 13:35:42 +0100
commit7303df70a900bef271044b7eaef35fcb3416a40f (patch)
treefa2727dbc15953603d6b39e8ffd8ce2306c7b238
parent7312a5fcacb82cd92c936846dca641d322600054 (diff)
downloaddrminfo-7303df70a900bef271044b7eaef35fcb3416a40f.tar.gz
bash completion, fix drminfo logn getopt
-rw-r--r--drminfo.c13
-rw-r--r--drmtest.c8
-rw-r--r--meson.build4
3 files changed, 21 insertions, 4 deletions
diff --git a/drminfo.c b/drminfo.c
index ef9e259..e806417 100644
--- a/drminfo.c
+++ b/drminfo.c
@@ -21,6 +21,7 @@
#include "drmtools.h"
#include "drm-lease.h"
#include "logind.h"
+#include "complete.h"
static int ttycols = 80;
@@ -460,6 +461,7 @@ static void usage(FILE *fp)
enum {
OPT_LONG_LEASE = 0x100,
+ OPT_LONG_COMP_BASH,
};
struct option long_opts[] = {
@@ -505,6 +507,10 @@ struct option long_opts[] = {
.has_arg = false,
.val = 'l',
},{
+ .name = "complete-bash",
+ .has_arg = false,
+ .val = OPT_LONG_COMP_BASH,
+ },{
/* --- with argument --- */
.name = "card",
@@ -535,7 +541,7 @@ int main(int argc, char **argv)
char *columns;
for (;;) {
- c = getopt(argc, argv, "hlaAmsopPfFrc:");
+ c = getopt_long(argc, argv, "hlaAmsopPfFrc:", long_opts, NULL);
if (c == -1)
break;
switch (c) {
@@ -579,9 +585,12 @@ int main(int argc, char **argv)
case 'f':
format = true;
break;
- case 'L':
+ case OPT_LONG_LEASE:
lease_fd = drm_lease(optarg);
break;
+ case OPT_LONG_COMP_BASH:
+ complete_bash("drminfo", long_opts);
+ exit(0);
case 'h':
usage(stdout);
exit(0);
diff --git a/drmtest.c b/drmtest.c
index 57faa5f..26450ca 100644
--- a/drmtest.c
+++ b/drmtest.c
@@ -392,6 +392,7 @@ enum {
OPT_LONG_VGEM,
OPT_LONG_UNBIND,
OPT_LONG_LEASE,
+ OPT_LONG_COMP_BASH,
};
struct option long_opts[] = {
@@ -421,6 +422,10 @@ struct option long_opts[] = {
.has_arg = false,
.val = OPT_LONG_UNBIND,
},{
+ .name = "complete-bash",
+ .has_arg = false,
+ .val = OPT_LONG_COMP_BASH,
+ },{
/* --- with argument --- */
.name = "card",
@@ -521,6 +526,9 @@ int main(int argc, char **argv)
case OPT_LONG_LEASE:
lease_fd = drm_lease(optarg);
break;
+ case OPT_LONG_COMP_BASH:
+ complete_bash("drminfo", long_opts);
+ exit(0);
case 'h':
usage(stdout);
exit(0);
diff --git a/meson.build b/meson.build
index fa89bcc..63ccd7c 100644
--- a/meson.build
+++ b/meson.build
@@ -31,9 +31,9 @@ configure_file(output : 'config.h', configuration : config)
jpeg_dep = declare_dependency(link_args : '-ljpeg')
drminfo_srcs = [ 'drminfo.c', 'drmtools.c', 'drm-lease.c', 'drm-lease-x11.c',
- 'logind.c' ]
+ 'logind.c', 'complete.c' ]
drmtest_srcs = [ 'drmtest.c', 'drmtools.c', 'drm-lease.c', 'drm-lease-x11.c',
- 'logind.c', 'ttytools.c', 'render.c', 'image.c' ]
+ 'logind.c', 'complete.c', 'ttytools.c', 'render.c', 'image.c' ]
fbinfo_srcs = [ 'fbinfo.c', 'fbtools.c', 'logind.c' ]
fbtest_srcs = [ 'fbtest.c', 'fbtools.c', 'logind.c',
'ttytools.c', 'render.c', 'image.c' ]