diff -r 71cf9456e6ec tabbed.1
--- a/tabbed.1	Sat Oct 13 06:57:32 2012 +0200
+++ b/tabbed.1	Mon Nov 05 16:52:09 2012 -0500
@@ -9,6 +9,8 @@
 .RB [ \-v ]
 .RB [ \-n
 .IR name ]
+.RB [ \-r
+.IR narg ]
 .IR [ command ... ]
 .SH DESCRIPTION
 .B tabbed
@@ -32,6 +34,13 @@
 .B \-s
 will disable automatic spawning of the command.
 .TP
+.BI \-r " narg"
+will replace the
+.I narg 
+th argument in
+.I command
+with the window id, rather than appending it to the end.
+.TP
 .B \-v
 prints version information to stderr, then exits.
 .SH USAGE
@@ -61,4 +70,6 @@
 $ tabbed xterm -into
 .TP
 $ $(tabbed -d >/tmp/tabbed.xid); urxvt -embed $(</tmp/tabbed.xid);
+.TP
+$ tabbed -r 2 st -w '' -e tmux
 
diff -r 71cf9456e6ec tabbed.c
--- a/tabbed.c	Sat Oct 13 06:57:32 2012 +0200
+++ b/tabbed.c	Mon Nov 05 16:52:09 2012 -0500
@@ -118,7 +118,7 @@
 static void run(void);
 static void sendxembed(Client *c, long msg, long detail, long d1, long d2);
 static void setup(void);
-static void setcmd(int argc, char *argv[]);
+static void setcmd(int argc, char *argv[], int);
 static void sigchld(int unused);
 static void spawn(const Arg *arg);
 static int textnw(const char *text, unsigned int len);
@@ -719,14 +719,14 @@
 }
 
 void
-setcmd(int argc, char *argv[]) {
+setcmd(int argc, char *argv[], int replace) {
 	int i;
 
 	cmd = emallocz((argc+2) * sizeof *cmd);
 	for(i = 0; i < argc; i++)
 		cmd[i] = argv[i];
-	cmd[argc] = winid;
-	cmd[argc+1] = NULL;
+	cmd[(replace>0)?replace:argc] = winid;
+	cmd[argc+!(replace>0)] = NULL;
 }
 
 void
@@ -888,12 +888,12 @@
 void
 usage(void)
 {
-	die("usage: %s [-dhsv] [-n name] command...\n", argv0);
+	die("usage: %s [-dhsv] [-r narg][-n name] command...\n", argv0);
 }
 
 int
 main(int argc, char *argv[]) {
-	int detach = 0;
+	int replace = 0, detach = 0;
 
 	ARGBEGIN {
 	case 'd':
@@ -905,6 +905,9 @@
 	case 's':
 		doinitspawn = False;
 		break;
+	case 'r':
+		replace = atoi(EARGF(usage()));
+		break;
 	case 'v':
 		die("tabbed-"VERSION", © 2009-2012"
 			" tabbed engineers, see LICENSE"
@@ -917,7 +920,7 @@
 	if(argc < 1)
 		doinitspawn = False;
 
-	setcmd(argc, argv);
+	setcmd(argc, argv, replace);
 
 	if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
 		fprintf(stderr, "tabbed: no locale support\n");
