├── .travis.yml ├── LICENSE ├── Makefile ├── README.md ├── config.mk ├── xrq.1 └── xrq.c /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | compiler: 3 | - clang 4 | - gcc 5 | before_install: 6 | - sudo apt-get update -qq 7 | - sudo apt-get install -y libx11-dev 8 | script: make 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2015, Arianon 2 | 3 | Permission to use, copy, modify, and/or distribute this software for any 4 | purpose with or without fee is hereby granted, provided that the above 5 | copyright notice and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 8 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 9 | FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 10 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 11 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 12 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 13 | PERFORMANCE OF THIS SOFTWARE. 14 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | include config.mk 2 | 3 | SRC = xrq.c 4 | OBJ = $(SRC:.c=.o) 5 | BIN = $(SRC:.c=) 6 | MAN = $(SRC:.c=.1) 7 | 8 | .POSIX: 9 | all: $(BIN) 10 | 11 | .c.o: 12 | $(CC) -c $< -o $@ $(CFLAGS) 13 | 14 | $(BIN): $(OBJ) 15 | $(LD) -o $@ $(OBJ) $(LDFLAGS) 16 | 17 | install: $(BIN) 18 | install -Dm755 $(BIN) $(DESTDIR)$(PREFIX)/bin/$(BIN) 19 | install -Dm644 $(MAN) $(DESTDIR)$(MANPREFIX)/man1/$(MAN) 20 | 21 | uninstall: 22 | rm -f $(DESTIDR)$(PREFIX)/bin/$(BIN) 23 | 24 | clean: 25 | rm -f $(OBJ) $(BIN) 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xrq 2 | 3 | [![](https://img.shields.io/travis/arianon/xrq.svg?style=flat-square)](https://travis-ci.org/arianon/xrq) 4 | 5 | **X** **R**esource **Q**uery, 6 | A program for querying the X Resources Database from the command line. 7 | 8 | ## Installing 9 | ```sh 10 | $ git clone https://github.com/arianon/xres 11 | $ cd xres 12 | $ make 13 | $ sudo make install 14 | ``` 15 | 16 | ## Usage 17 | At the computer and time of writing, the following command: 18 | ```sh 19 | $ xrq URxvt.foreground URxvt.background URxvt.font 20 | ``` 21 | yields the following values. 22 | ``` 23 | #b7bdcc 24 | #14181f 25 | -*-tewi-medium-*-*-*-11-*-*-*-*-*-iso10646-* 26 | ``` 27 | 28 | For querying all 16 colors, one could take advantage of shell expansion. 29 | ```sh 30 | $ xrq URxvt.color{0..15} 31 | ``` 32 | yields 33 | ``` 34 | #2b303b 35 | #994e55 36 | #849971 37 | #c5aa75 38 | #707e8c 39 | #8f7189 40 | #778f8e 41 | #a6aab2 42 | #4d576b 43 | #bf616a 44 | #a3be8c 45 | #ebcb8b 46 | #8fa1b3 47 | #b48ead 48 | #96b5b4 49 | #b9bbbe 50 | ``` 51 | 52 | If in your `~/.Xresources` or `~/.Xdefaults`, you use glob patterns - such as `*color4: #aabbcc` - you could simply skip the class's name that precedes the resource name. thus the above commands could become this: 53 | 54 | ```sh 55 | $ xrq color{0..15} 56 | ``` 57 | -------------------------------------------------------------------------------- /config.mk: -------------------------------------------------------------------------------- 1 | PREFIX = /usr 2 | MANPREFIX = $(PREFIX)/share/man 3 | 4 | CFLAGS = -ansi -pedantic -Wall -Os 5 | LDFLAGS = -L/usr/lib -lc -lX11 6 | 7 | CC = cc 8 | LD = $(CC) 9 | -------------------------------------------------------------------------------- /xrq.1: -------------------------------------------------------------------------------- 1 | .Dd October 20, 2015 2 | .Dt XRQ 1 3 | .Sh NAME 4 | .Nm xrq 5 | .Nd query the X Resource Database 6 | .Sh SYNOPSIS 7 | .Nm xrq 8 | .Ar resource Op ... 9 | .Sh DESCRIPTION 10 | .Nm 11 | queries the X Resource Database for the values of the given 12 | .Ar resources 13 | and prints them to the standard output. 14 | .Sh ENVIRONMENT 15 | .Nm 16 | acts on the X display specified by the 17 | .Ev DISPLAY 18 | variable. 19 | .Sh EXAMPLES 20 | At the computer and time of writing, the following command 21 | .Pp 22 | .Dl $ xrq URxvt.foreground URxvt.background URxvt.font 23 | .Pp 24 | Yields the following values 25 | .Pp 26 | .Dl #b7bdcc 27 | .Dl #14181f 28 | .Dl -*-tewi-medium-*-*-*-11-*-*-*-*-*-iso10646-* 29 | .Pp 30 | For querying all 16 colors, one could take advantage of shell expansion. 31 | .Pp 32 | .Dl $ xrq URxvt.color{0..15} 33 | .Pp 34 | yields 35 | .Pp 36 | .Dl #2b303b 37 | .Dl #994e55 38 | .Dl #849971 39 | .Dl #c5aa75 40 | .Dl #707e8c 41 | .Dl #8f7189 42 | .Dl #778f8e 43 | .Dl #a6aab2 44 | .Dl #4d576b 45 | .Dl #bf616a 46 | .Dl #a3be8c 47 | .Dl #ebcb8b 48 | .Dl #8fa1b3 49 | .Dl #b48ead 50 | .Dl #96b5b4 51 | .Dl #b9bbbe 52 | .Pp 53 | If in your 54 | .Pa ~/.Xresources 55 | or 56 | .Pa ~/.Xdefaults 57 | you use glob patterns - such as 58 | .Em *color4: #aabbcc 59 | - you could simply skip the class's name that precedes the resource name. thus the above commands could become this: 60 | .Pp 61 | .Dl $ xrq color{0..15} 62 | .Sh SEE ALSO 63 | .Xr XrmGetResource 3 , 64 | .Xr XrmGetFileDatabase 3 65 | -------------------------------------------------------------------------------- /xrq.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | void 8 | xrdb_print_value(XrmDatabase db, char* resource) 9 | { 10 | char *type; 11 | XrmValue xvalue; 12 | 13 | XrmGetResource(db, resource, "*", &type, &xvalue); 14 | 15 | if (xvalue.addr != NULL) 16 | { 17 | puts(xvalue.addr); 18 | } 19 | else 20 | { 21 | errx(1, "failed to get xrdb value '%s'.", resource); 22 | } 23 | } 24 | 25 | int 26 | main(int argc, char* argv[]) 27 | { 28 | XrmDatabase xrdb; 29 | Display *dpy; 30 | char *xrm; 31 | size_t i; 32 | int ret_code; 33 | 34 | if (argv[1] == NULL || !strcmp(argv[1], "-h")) 35 | { 36 | errx(1, "usage: %s ...", argv[0]); 37 | } 38 | else 39 | { 40 | /* Shift the program name out of the argument vector */ 41 | ++argv; 42 | --argc; 43 | } 44 | 45 | 46 | if (!(dpy = XOpenDisplay(NULL))) 47 | { 48 | errx(1, "could not open the display!"); 49 | } 50 | 51 | XrmInitialize(); 52 | xrm = XResourceManagerString(dpy); 53 | 54 | if (xrm != NULL) 55 | { 56 | xrdb = XrmGetStringDatabase(xrm); 57 | 58 | for (i = 0; i < argc; i++) 59 | { 60 | xrdb_print_value(xrdb, argv[i]); 61 | } 62 | 63 | XrmDestroyDatabase(xrdb); 64 | ret_code = 0; 65 | } 66 | else 67 | { 68 | warnx("could not get the resource properties."); 69 | ret_code = 1; 70 | } 71 | 72 | XFlush(dpy); 73 | XCloseDisplay(dpy); 74 | return ret_code; 75 | } 76 | --------------------------------------------------------------------------------