+
+ /* We need to create a custom script containing our actual command
+ * since not every terminal emulator which is contained in
+ * i3-sensible-terminal supports -e with multiple arguments (and not
+ * all of them support -e with one quoted argument either).
+ *
+ * NB: The paths need to be unique, that is, don’t assume users close
+ * their nagbars at any point in time (and they still need to work).
+ * */
+ char *script_path = get_process_filename("nagbar-cmd");
+
+ int fd = open(script_path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
+ if (fd == -1) {
+ warn("Could not create temporary script to store the nagbar command");
+ return;
+ }
+ FILE *script = fdopen(fd, "w");
+ if (script == NULL) {
+ warn("Could not fdopen() temporary script to store the nagbar command");
+ return;
+ }
+ fprintf(script, "#!/bin/sh\nrm %s\n%s", script_path, button->action);
+ /* Also closes fd */
+ fclose(script);
+
+ char *terminal_cmd;
+ sasprintf(&terminal_cmd, "i3-sensible-terminal -e %s", argv0);
+ printf("argv0 = %s\n", argv0);
+ printf("terminal_cmd = %s\n", terminal_cmd);
+
+ setenv("_I3_NAGBAR_CMD", script_path, 1);
+ start_application(terminal_cmd);
+ unsetenv("_I3_NAGBAR_CMD");
+
+ free(terminal_cmd);
+ free(script_path);