On 4 May 2015 at 11:56, Roberto E. Vargas Caballero <[email protected]> wrote:
> The idea is good, but it means that you have to modify all the programs
> to accept this new feature. If you want to experiment with this idea
> you can try to add this variable in st and read it in surf.

I've written a wrapper which makes a given program support this, and
it's pretty tiny, too. Attached. Sample usage:

> #!/bin/sh
> exec 9embed -e surf "$@"

I've not found time to add the functionality into a terminal like st
yet, but I was happy to discover that tabbed already sets XEMBED, and
the wrapper works as expected: 'surf &' will open surf in a new
window, whereas 'surf' will open it in a new tab.

Thanks,
cls
/* (c) Connor Lane Smith, 2015 */
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int
main(int argc, char **argv)
{
	if(argc < 3) {
		fprintf(stderr, "usage: %s flag cmd ...\n", argv[0]);
		return 2;
	}

	char *xembed = getenv("XEMBED");

	if(!xembed)
		goto noembed;

	int tty = open("/dev/tty", O_RDONLY);

	if(tty < 0)
		goto noembed;

	pid_t pgrp = getpgrp();
	pid_t tcpgrp = tcgetpgrp(tty);

	close(tty);

	if(pgrp == tcpgrp) { // in foreground of tty
		argv[0] = argv[2];
		argv[2] = xembed;
	}
	else {
noembed:
		argv += 2;
	}

	execvp(argv[0], argv);

	perror(argv[0]); // failed to execute
	return 1;
}

Reply via email to