Anonymous avatar Anonymous committed 9675cb5

cw : added -q and -v
cwd: added -t and -v

Comments (0)

Files changed (2)

 #include <sys/inotify.h>
 #include <stdio.h>
 
+int quiet = 0;
 mode_t type = 0;
 mode_t perm = 0600;
 
 void usage(void)
 {
-	printf("Usage: cw [-c|-f] infile outfile\n");
+	printf("Usage: cw [-c|-f] [-q] [-v] infile outfile\n");
 	exit(1);
 }
 
 			err(1, "file %s could not be created", path);
 	}
 
-	warnx("Opening %s (if it's a fifo, waiting for the other side to be opened)...", path);
+	if (!quiet) warnx("Opening %s (if it's a fifo, waiting for the other side to be opened)...", path);
 
 	if ((f = fopen(path, mode)) == NULL)
 		err(1, "failed to fopen %s", path);
 
-	warnx("...OK");
+	if (!quiet) warnx("...OK");
 
 	return f;
 }
 		switch (argv[i][1]) {
 			case 'c' : type = S_IFREG; break; // create regular files
 			case 'f' : type = S_IFIFO; break; // create fifos
+			case 'q' : quiet = 1; break;
+			case 'v' : printf("cw-"VERSION" © Evan Gates\n"); exit(1);
 			// is it worth doing character, block, and socket too?
 			default  : usage();
 		}
 
 	out = mopen(argv[i + 1], "w");
 
-	printf("-------------------- new text starts here --------------------\n");
+	if (!quiet) printf("-------------------- new text starts here --------------------\n");
 
 	if ((evq = inotify_init()) < 0)
 		err(1, "failed inotify_init()");
 
 char term[16] = "urxvt";
 
+void usage(void)
+{
+	printf("Usage: cwd [-t terminal] [-v] dir\n");
+	exit(1);
+}
+
 void win(int wd)
 {
 	char path[PATH_MAX], out[PATH_MAX], in[PATH_MAX];
-	char *wincmd[] = {term, "-title", paths[wd], "-e", "srw", "cw", out, in, NULL};
+	char *wincmd[] = {term, "-title", paths[wd], "-e", "srw", "cw", "-f", out, in, NULL};
 
 	if (wins[wd])
 		return;
 	pid_t pid;
 	int wd;
 
-	while((pid = waitpid(-1, NULL, WNOHANG)) > 0) {
+	while ((pid = waitpid(-1, NULL, WNOHANG)) > 0) {
 		if ((wd = find(wins, pid, MAX_WATCH)) > -1)
 			wins[wd] = 0;
 	}
 	struct inotify_event *cur;
 	struct stat st;
 
-	if (argc != 2) {
-		printf("Usage: cwd dir\n");
-		exit(1);
+	for (i = 1; i < argc; i++) {
+		if (argv[i][0] != '-')
+			break;
+		if (argv[i][2] != '\0')
+			usage();
+		switch (argv[i][1]) {
+			case 't' : if (i + 1 >= argc) usage(); strncpy(term, argv[i + 1], sizeof(term)); break;
+			case 'v' : printf("cwd-"VERSION" © Evan Gates\n"); exit(1);
+			default  : usage();
+		}
 	}
 
+	if (i >= argc)
+		usage();
+
 	if (stat(argv[1], &st) < 0 || !S_ISDIR(st.st_mode))
 		errx(1, "%s does not exist or is not a directory", argv[1]);
 
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.