9menu-patches / 08_print_only.diff

# HG changeset patch
# Parent 66f628989313665f448cb5d7ae116c40c21cc21b
Description: add -print option to avoid command execution
Author: Julien Jehannet <julien@smaf.org>
Last-Update: 2012-01-14

diff --git a/9menu.1 b/9menu.1
--- a/9menu.1
+++ b/9menu.1
@@ -168,10 +168,13 @@ This option is particularly useful when 
 .B \-version
 This option prints the version of
 .I 9menu
 on the standard output, and then exits with an exit value of zero.
 .TP
+.BR \-print
+Print only to stdout (no command execution).
+.TP
 .B \-warp
 Warp the mouse to the menu when the menu is uniconified.
 After the selection is made, restore the mouse to where it was.
 This option is particularly useful when combined with
 .BR \-popdown .
diff --git a/9menu.c b/9menu.c
--- a/9menu.c
+++ b/9menu.c
@@ -42,10 +42,16 @@
  * spawn() changed to do exec directly if -popup, based on
  * suggestion from
  * Andrew Stribblehill
  * a.d.stribblehill@durham.ac.uk
  * June, 2004
+ *
+ * Code added for -print options.
+ * Julien Jehannet
+ * julien@smaf.org
+ * January, 2012
+ *
  */
 
 #include <stdio.h>
 #include <fcntl.h>
 #include <signal.h>
@@ -141,10 +147,11 @@ char *filename;		/* file to read options
 int popup;		/* true if we're a popup window */
 int popdown;		/* autohide after running a command */
 int iconic;		/* start iconified */
 int teleport;		/* teleport the menu */
 int warp;		/* warp the mouse */
+int print;		/* print only to stdout */
 
 char **labels;		/* list of labels and commands */
 char **commands;
 int numitems;
 
@@ -197,10 +204,12 @@ char **argv;
 			i++;
 		} else if (strcmp(argv[i], "-popup") == 0)
 			popup++;
 		else if (strcmp(argv[i], "-popdown") == 0)
 			popdown++;
+		else if (strcmp(argv[i], "-print") == 0)
+			print++;
 		else if (strcmp(argv[i], "-fg") == 0)
 			fgcname = argv[++i];
 		else if (strcmp(argv[i], "-bg") == 0)
 			bgcname = argv[++i];
 		else if (strcmp(argv[i], "-iconic") == 0)
@@ -462,10 +471,14 @@ char *com;
 			com += 5;
 		}
 	}
 
 	close(ConnectionNumber(dpy));
+	if (print) {
+		printf("%s\n", com);
+		exit(0);
+	}
 	execl(shell, sh_base, "-c", com, NULL);
 	execl("/bin/sh", "sh", "-c", com, NULL);
 	_exit(1);
 }
 
@@ -485,11 +498,11 @@ void
 usage()
 {
 	fprintf(stderr, "usage: %s [-display displayname] [-font fname] ", progname);
 	fprintf(stderr, "[-file filename] [-path]");
 	fprintf(stderr, "[-geometry geom] [-shell shell]  [-label name] ");
-	fprintf(stderr, "[-popup] [-popdown] [-iconic]  [-teleport] ");
+	fprintf(stderr, "[-popup] [-popdown] [-iconic] [-teleport] [-print]");
 	fprintf(stderr, "[-warp]  [-version] menitem:command ...\n");
 	exit(0);
 }
 
 /* run_menu --- put up the window, execute selected commands */
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.