├── .gitignore ├── Makefile ├── README.md ├── xgetres.1 ├── LICENSE └── xgetres.c /.gitignore: -------------------------------------------------------------------------------- 1 | /xgetres 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | VERSION ?= 1.0 2 | 3 | CPPFLAGS := -DVERSION=\"$(VERSION)\" $(CPPFLAGS) 4 | CFLAGS ?= -O2 -Wall -Werror 5 | LDFLAGS := -lX11 $(LDFLAGS) 6 | 7 | PREFIX ?= /usr/local 8 | BINDIR ?= $(PREFIX)/bin 9 | MANDIR ?= $(PREFIX)/share/man/man1 10 | 11 | all: xgetres 12 | 13 | xgetres: xgetres.c 14 | $(CC) $(CPPFLAGS) $(CFLAGS) $? -o $@ $(LDFLAGS) 15 | 16 | install: xgetres 17 | mkdir -p $(BINDIR) 18 | install -D $< $(BINDIR) 19 | mkdir -p $(MANDIR) 20 | install -Dm 644 xgetres.1 $(MANDIR)/xgetres.1 21 | 22 | clean: 23 | rm -f xgetres 24 | 25 | .PHONY: all install clean 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xgetres 2 | 3 | xgetres is a simple utility which prints the value of an X resource. 4 | 5 | ## Example 6 | 7 | $ cat ~/.Xresources 8 | simple: 1 9 | *wildcard: 2 10 | $ xgetres simple 11 | 1 12 | $ xgetres foo.wildcard 13 | 2 14 | 15 | ## Build & installation 16 | 17 | First make sure you have libx11. 18 | 19 | In order to build, simply run: 20 | 21 | $ make 22 | 23 | Then in order to install, run: 24 | 25 | $ sudo make install 26 | 27 | Installation location is determined by the `PREFIX` variable 28 | (`/usr/local` by default), you can specify a different location like this: 29 | 30 | $ sudo make install PREFIX=/app 31 | -------------------------------------------------------------------------------- /xgetres.1: -------------------------------------------------------------------------------- 1 | .TH xgetres 1 "2018-01-27" "xgetres" "User Commands" 2 | .SH NAME 3 | xgetres \- Get the value of an X resource. 4 | .SH SYNOPSIS 5 | \fBxgetres\fP [\fR\fIOPTION\fR] \fR\fIRESOURCE\fR 6 | .SH DESCRIPTION 7 | \fBxgetres\fP gets the value of the X resource named 8 | \fR\fIRESOURCE\fR. Handles wildcards, same as every program which 9 | uses X resources does. 10 | .SH OPTIONS 11 | .PP 12 | .IP "\fB\-h\fR, \fB\-\-help\fR" 13 | Display help message. 14 | .IP "\fB\-v\fR, \fB\-\-version\fR" 15 | Display version information. 16 | .SH EXIT STATUS 17 | \fBxgetres\fP returns \fI0\fR on success, \fI1\fR if the resource 18 | was not found and \fI-1\fR on error. 19 | .SH AUTHOR 20 | Tamir Zahavi-Brunner 21 | .SH SEE ALSO 22 | xrdb(1) 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Tamir Zahavi-Brunner 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /xgetres.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static int print_xresource(const char *resource) 6 | { 7 | int ret; 8 | 9 | XrmInitialize(); 10 | 11 | Display *display = XOpenDisplay(NULL); 12 | if (NULL == display) { 13 | fprintf(stderr, "Can't open display\n"); 14 | ret = -1; 15 | goto cleanup; 16 | } 17 | 18 | char *resource_manager = XResourceManagerString(display); 19 | if (NULL == resource_manager) { 20 | fprintf(stderr, "Can't obtain RESOURCE_MANAGER\n"); 21 | ret = -1; 22 | goto cleanup; 23 | } 24 | 25 | XrmDatabase db = XrmGetStringDatabase(resource_manager); 26 | if (NULL == db) { 27 | fprintf(stderr, "Can't open resource database\n"); 28 | ret = -1; 29 | goto cleanup; 30 | } 31 | 32 | XrmValue value; 33 | char *type; 34 | if (XrmGetResource(db, resource, resource, &type, &value)) { 35 | printf("%s\n", value.addr); 36 | ret = 0; 37 | } else { 38 | // Resource not found 39 | ret = 1; 40 | } 41 | 42 | cleanup: 43 | if (NULL != display) { 44 | XCloseDisplay(display); 45 | } 46 | return ret; 47 | } 48 | 49 | #define USAGE "Usage: %s [OPTION] RESOURCE\n" 50 | 51 | int main(int argc, char * const argv[]) 52 | { 53 | struct option options[] = { 54 | {"help", no_argument, NULL, 'h'}, 55 | {"version", no_argument, NULL, 'v'}, 56 | {0, 0, 0, 0} 57 | }; 58 | switch(getopt_long(argc, argv, "hv", options, NULL)) { 59 | case 'h': 60 | printf(USAGE 61 | "Get the value of the X resource named RESOURCE\n" 62 | "\n" 63 | "Options:\n" 64 | " -h, --help Prints this help message\n" 65 | " -v, --version Prints the version\n", 66 | argv[0]); 67 | return 0; 68 | case 'v': 69 | printf("xgetres " VERSION "\n"); 70 | return 0; 71 | case -1: 72 | if (2 == argc) { 73 | return print_xresource(argv[1]); 74 | } 75 | default: 76 | fprintf(stderr, USAGE 77 | "Try '%s -h' for more information\n", 78 | argv[0], argv[0]); 79 | return -1; 80 | } 81 | } 82 | --------------------------------------------------------------------------------