Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Better 'hushbang' handling; XDG Base Directory use
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b90795e12dbdaa4ae0fda97dae773edf8918ae92e7029686e15c821a88afd248
User & Date: jmcclure 2020-03-25 21:17:52
Context
2020-03-25
21:18
Comment man page install for now ... until it's written check-in: 0e51a9e212 user: jmcclure tags: trunk
21:17
Better 'hushbang' handling; XDG Base Directory use check-in: b90795e12d user: jmcclure tags: trunk
16:00
Initial Commit check-in: 8c27047cfb user: jmcclure tags: trunk
Changes

Changes to config.h.

1
2
3
4

5
6
7
8
9
10
11
..
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
..
35
36
37
38
39
40
41
42


43
44
45
46
47
48
49
50
51
52
53
54
55
56

#define BANG_CHAR  "!"

static const char *font = "PT Sans";


static unsigned long
	colBG = 0x404448,
	colFG = 0xEEEEEE,
	colCS = 0xFFDD88,
	colBD = 0x000000;

................................................................................
	/* 'h' is determined by font metrics */
	left = 4, // TODO, I hate this ... needs to come from font metrics
	bpx = 1;

static Key keys[] = {
/*   Modifiers             Keysym           Function     Args */
	{ ControlMask,          XK_q,            quit,        { 0 } },
	{ 0,                    XK_Tab,          complete,    { .v = BANG_CHAR } },
	{ 0,                    XK_Return,       run,         { .v = BANG_CHAR } },

	{ 0,                    XK_Left,         move,        { .i = -1 } },
	{ 0,                    XK_Right,        move,        { .i = +1 } },
	{ 0,                    XK_Home,         move,        { .i = -MAX } },
	{ 0,                    XK_End,          move,        { .i = +MAX } },

	{ 0,                    XK_BackSpace,    del,         { .i = -1 } },
................................................................................

	{ ShiftMask,            XK_Insert,       paste,       { .i = 0 } },
	{ ControlMask,          XK_v,            paste,       { .i = 1 } },

	{ 0,                    0,               NULL,        { 0 } },
};

static Key extra[] = {


	{ 0,                    0,               NULL,        { 0 } },
};

/* KEYMAPS:
 * Any keymap named "default" is always used.
 * Each additional keymap is only included if it's name is listed on the command line preceded by a "+".
 * If a given key binding is included in more than one keymap, the last one take precedence.
 */
static KeyMap keymaps[] = {
	{ "default",      keys },
	{ "extra",        extra },
	{ NULL,           NULL },
};


<
<

>







 







|
|







 







|
>
>










|



1


2
3
4
5
6
7
8
9
10
..
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
..
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57



static const char *font = "PT Sans";
static const char bang = '!';

static unsigned long
	colBG = 0x404448,
	colFG = 0xEEEEEE,
	colCS = 0xFFDD88,
	colBD = 0x000000;

................................................................................
	/* 'h' is determined by font metrics */
	left = 4, // TODO, I hate this ... needs to come from font metrics
	bpx = 1;

static Key keys[] = {
/*   Modifiers             Keysym           Function     Args */
	{ ControlMask,          XK_q,            quit,        { 0 } },
	{ 0,                    XK_Tab,          complete,    { .v = "default" } },
	{ 0,                    XK_Return,       run,         { .v = "default" } },

	{ 0,                    XK_Left,         move,        { .i = -1 } },
	{ 0,                    XK_Right,        move,        { .i = +1 } },
	{ 0,                    XK_Home,         move,        { .i = -MAX } },
	{ 0,                    XK_End,          move,        { .i = +MAX } },

	{ 0,                    XK_BackSpace,    del,         { .i = -1 } },
................................................................................

	{ ShiftMask,            XK_Insert,       paste,       { .i = 0 } },
	{ ControlMask,          XK_v,            paste,       { .i = 1 } },

	{ 0,                    0,               NULL,        { 0 } },
};

static Key keys_pdf[] = {
	{ 0,                    XK_Tab,          complete,    { .v = "pdf" } },
	{ 0,                    XK_Return,       run,         { .v = "pdf" } },
	{ 0,                    0,               NULL,        { 0 } },
};

/* KEYMAPS:
 * Any keymap named "default" is always used.
 * Each additional keymap is only included if it's name is listed on the command line preceded by a "+".
 * If a given key binding is included in more than one keymap, the last one take precedence.
 */
static KeyMap keymaps[] = {
	{ "default",      keys },
	{ "pdf",          keys_pdf },
	{ NULL,           NULL },
};

Changes to interrobang.c.

17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
..
57
58
59
60
61
62
63
64
65
66
67
68

















69
70
71
72
73
74
75
76
77
...
200
201
202
203
204
205
206

207
208
209
210
211
212
213
...
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232

233
234

235
236
237
238
239
240
241
242
243
244
...
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
...
300
301
302
303
304
305
306
307
308

#define ENV_CHAR	"iBangChar"
#define ENV_BANG	"iBangBang"
#define ENV_ARGS	"iBangArgs"
#define ENV_LINE	"iBangLine"
#define ENV_LAST	"iBangLast"
#define ENV_TEMP	"iBangTemp"


#define ENV_RUN_PATH   "/home/jmcclure/code/xin/run/"
#define ENV_TAB_PATH   "/home/jmcclure/code/xin/tab/"

typedef union {
	int i;
	unsigned int ui;
	float f;
	const void *v;
} Arg;
................................................................................
static int scr, fh, h, pos = 0, running = 1;
static Window root, win;
static GC gc;
static XftFont *xfont;
static XftDraw *xdraw;
static XftColor xcol;
static char line[MAX];
static const char *hush;


/* INITIALIZATION FUNCTIONS: IN ORDER OF CALL */


















static int xlibInit(int argc, const char *argv[]) {
	hush = "default";
	int i;
	dpy = XOpenDisplay(0x0);
	scr = DefaultScreen(dpy);
	root = RootWindow(dpy, scr);
	w = (w ? w : DisplayWidth(dpy,scr) - bpx * 2);
	for (i = 0; i < 1000; i++) {
		if (XGrabKeyboard(dpy,root,True,GrabModeAsync,GrabModeAsync,
................................................................................
	XUngrabKeyboard(dpy, CurrentTime);
	XCloseDisplay(dpy);
	unlink(getenv(ENV_TEMP));
	return 0;
}

int main(int argc, const char *argv[]) {

	xlibInit(argc, argv);
	colorsInit(argc, argv);
	fontInit(argc, argv);
	winInit(argc, argv);
	keymapInit(argc, argv);
	mainLoop();
	cleanup();
................................................................................
	return 0;
}


/* KEY BINDABLE ACTION FUNCTIONS */

void complete_run_helper(const Arg *arg, const char *path, int run) {
	if (line[0] == '\0' || line[1] == '\0') return;
	char arg0[MAX], arg1[MAX], *p;
	pid_t pid;
	int fd[2];
	FILE *in;
	setenv(ENV_LINE, line, 1);
	strcpy(arg0, path);
	if (line[0] == ((char *)arg->v)[0]) {
		p = strchr(line, ' ');
		if (p) { *p = '\0'; p++; }
		strcat(arg0, line + 1);
		strcpy(arg1, p ? p : "");

		setenv(ENV_CHAR, (char*)arg->v, 1);
		setenv(ENV_BANG, line + 1, 1);

	}
	else {
		strcat(arg0, hush);
		strcpy(arg1, line);
		setenv(ENV_CHAR, "", 1);
		setenv(ENV_BANG, "", 1);
	}
	setenv(ENV_ARGS, arg1, 1);
	pipe(fd);
	pid = fork();
................................................................................
		setenv(ENV_LAST, line, 1);
		while(fgets(line, MAX, in));
		fclose(in);
	}
}

void complete(const Arg *arg) {
	complete_run_helper(arg, ENV_TAB_PATH, 0);
}

void del(const Arg *arg) {
	int p = pos + arg->i;
	char *part;
	if (p < pos) { /* Backwards delete, e.g., Backspace */
		if (p < 0) p = 0;
................................................................................
}

void quit(const Arg *arg) {
	running = 0;
}

void run(const Arg *arg) {
	complete_run_helper(arg, ENV_RUN_PATH, 1);
}







<
>
|
<







 







<




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

<







 







>







 







|






|



|
>
|

>


|







 







|







 







|

17
18
19
20
21
22
23

24
25

26
27
28
29
30
31
32
..
56
57
58
59
60
61
62

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

85
86
87
88
89
90
91
...
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
...
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
...
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
...
317
318
319
320
321
322
323
324
325

#define ENV_CHAR	"iBangChar"
#define ENV_BANG	"iBangBang"
#define ENV_ARGS	"iBangArgs"
#define ENV_LINE	"iBangLine"
#define ENV_LAST	"iBangLast"
#define ENV_TEMP	"iBangTemp"

#define ENV_TAB   "iBangTabDir"
#define ENV_RUN   "iBangRunDir"


typedef union {
	int i;
	unsigned int ui;
	float f;
	const void *v;
} Arg;
................................................................................
static int scr, fh, h, pos = 0, running = 1;
static Window root, win;
static GC gc;
static XftFont *xfont;
static XftDraw *xdraw;
static XftColor xcol;
static char line[MAX];



/* INITIALIZATION FUNCTIONS: IN ORDER OF CALL */

static int dirsInit(int argc, const char *argv[]) {
	const char *var;
	if ((var=getenv("XDG_DATA_HOME"))) {
		snprintf(line, MAX, "%s/interrobang/tab/", var);
		setenv(ENV_TAB, line, 1);
		snprintf(line, MAX, "%s/interrobang/run/", var);
		setenv(ENV_RUN, line, 1);
	}
	else if ((var=getenv("HOME"))) {
		snprintf(line, MAX, "%s/.local/share/interrobang/tab/", var);
		setenv(ENV_TAB, line, 1);
		snprintf(line, MAX, "%s/.local/share/interrobang/run/", var);
		setenv(ENV_RUN, line, 1);
	}
	return 0;
}

static int xlibInit(int argc, const char *argv[]) {

	int i;
	dpy = XOpenDisplay(0x0);
	scr = DefaultScreen(dpy);
	root = RootWindow(dpy, scr);
	w = (w ? w : DisplayWidth(dpy,scr) - bpx * 2);
	for (i = 0; i < 1000; i++) {
		if (XGrabKeyboard(dpy,root,True,GrabModeAsync,GrabModeAsync,
................................................................................
	XUngrabKeyboard(dpy, CurrentTime);
	XCloseDisplay(dpy);
	unlink(getenv(ENV_TEMP));
	return 0;
}

int main(int argc, const char *argv[]) {
	dirsInit(argc, argv);
	xlibInit(argc, argv);
	colorsInit(argc, argv);
	fontInit(argc, argv);
	winInit(argc, argv);
	keymapInit(argc, argv);
	mainLoop();
	cleanup();
................................................................................
	return 0;
}


/* KEY BINDABLE ACTION FUNCTIONS */

void complete_run_helper(const Arg *arg, const char *path, int run) {
	if (line[0] == '\0' || line[0] == bang && line[1] == '\0') return;
	char arg0[MAX], arg1[MAX], *p;
	pid_t pid;
	int fd[2];
	FILE *in;
	setenv(ENV_LINE, line, 1);
	strcpy(arg0, path);
	if (line[0] == bang) {
		p = strchr(line, ' ');
		if (p) { *p = '\0'; p++; }
		strcat(arg0, line + 1);
		arg1[0] = bang;
		arg1[1] = '\0';
		setenv(ENV_CHAR, arg1, 1);
		setenv(ENV_BANG, line + 1, 1);
		strcpy(arg1, p ? p : "");
	}
	else {
		strcat(arg0, arg->v);
		strcpy(arg1, line);
		setenv(ENV_CHAR, "", 1);
		setenv(ENV_BANG, "", 1);
	}
	setenv(ENV_ARGS, arg1, 1);
	pipe(fd);
	pid = fork();
................................................................................
		setenv(ENV_LAST, line, 1);
		while(fgets(line, MAX, in));
		fclose(in);
	}
}

void complete(const Arg *arg) {
	complete_run_helper(arg, getenv(ENV_TAB), 0);
}

void del(const Arg *arg) {
	int p = pos + arg->i;
	char *part;
	if (p < pos) { /* Backwards delete, e.g., Backspace */
		if (p < 0) p = 0;
................................................................................
}

void quit(const Arg *arg) {
	running = 0;
}

void run(const Arg *arg) {
	complete_run_helper(arg, getenv(ENV_RUN), 1);
}