Commits

Robert Lowry  committed bdf854d

added color config stuff, broken again? huh

  • Participants
  • Parent commits edcb255

Comments (0)

Files changed (4)

 	@mkdir -p ${DESTDIR}${PREFIX}/bin
 	@for bin in ${BIN}; do cp -f $$bin ${DESTDIR}${PREFIX}/bin/$$bin; done
 	@for bin in ${BIN}; do chmod 755   ${DESTDIR}${PREFIX}/bin/$$bin; done
+	@cp -f cw_color.sh ${DESTDIR}${PREFIX}/bin/cw_color.sh
+	@chmod 755 ${DESTDIR}${PREFIX}/bin/cw_color.sh
 	@echo installing manual pages to ${DESTDIR}${MANPREFIX}/man1
 	@mkdir -p ${DESTDIR}${MANPREFIX}/man1
 	@sed "s/VERSION/${VERSION}/g" < pcw.1 > ${DESTDIR}${MANPREFIX}/man1/pcw.1

File config.def.h

 /*
  * This defines the command to run when you join a new channel or a new message comes in.
- * Use paths[wd] for the path to the channel's directory, channel for the channel name
+ * Use w->path for the path to the channel's directory, channel for the channel name
  * (actually it's "name> " so it can be used as a prompt for srw), out for the out file
  * and in for the in fifo. If you want to do something more complicated, write a script to
- * put in your path and execute. For example, I replace cw with a script that calls cw but
+ * put in your w->path and execute. For example, I replace cw with a script that calls cw but
  * pipes the output through sed for colors and bell on my nick so urxvt sets the urgent hint.
  */
 
 /*
+ * Terminal to use
+ */
+#define TERM "urxvt"
+
+/*
+ * The default nick to highlight when using colors, "" reverts to your login name ($USER)
+ */
+#define DEFAULT_NICK ""
+
+/*
+ * The default color setting (0 for off, 1 for on.)
+ */
+#define DEFAULT_COLOR_SETTING 0
+
+/*
  * The default command
  */
-#define CMD { "urxvt", "-title", paths[wd], "-e", "srw", "-p", channel, "cw", out, in, NULL }
+#define CMD { TERM, "-title", w->path, "-e", "srw", "-p", channel, "cw", out, in, NULL }
+#define CMD_COLOR { TERM, "-title", w->path, "-e", "srw", "-p", channel, "cw_color.sh", out, in, nick ? nick : NULL, NULL }
 
 /*
  * Use this if for some reason you really don't want to use srw, it's not necessary, but it makes
  * everything much nicer, there's a reason, it's the default...
  */
-//#define CMD { "urxvt", "-title", paths[wd], "-e", "cw", out, in, NULL }
-
-
-/*
- * Use this if you want colors and bell on your nick. You must first edit cw_color.sh to change the
- * nick, and then place it in your path. It is not installed by default.
- */
-//#define CMD { "urxvt", "-title", paths[wd], "-e", "srw", "-p", channel, "cw_color.sh", out, in, NULL }
+//#define CMD { TERM, "-title", w->path, "-e", "cw", out, in, NULL }
+//#define CMD_COLOR { TERM, "-title", w->path, "-e", "cw_color.sh", out, in, nick ? nick : NULL, NULL }
 
 /*
  * Use this if you want to use tabbed (http://tools.suckless.org/tabbed) so that each new channel is
  * It would be fairly simple to do all three steps in a script, have fun! (and you can add the color
  * too if you want)
  */
-//#define CMD { "urxvt", "-embed", getenv("pcw_window_id"), "-title", paths[wd], "-e", "srw", "-p", channel, "cw", out, in, NULL }
+//#define CMD { TERM, "-embed", getenv("pcw_window_id"), "-title", w->path, "-e", "srw", "-p", channel, "cw", out, in, NULL }
+//#define CMD_COLOR { TERM, "-embed", getenv("pcw_window_id"), "-title", w->path, "-e", "srw", "-p", channel, "cw_color.sh", out, in, nick ? nick : NULL, NULL }
 # Make sure to change NICK to your correct nick and feel free to change the formatting to your liking
 #
 
-NICK="$USER"
+if [ $3 ]
+then
+	NICK="$3"
+else
+	NICK="$USER"
+fi
 
 reset="$(tput sgr0)"
 
 bg_cyan="$(tput setab 6)"
 bg_white="$(tput setab 7)"
 
-cw "$@" | sed -e "s/^\([-0-9]\{10,10\}\) \([:0-9]\{5,5\}\) <\([^ \t\r\n\v\f]*\)>/${yellow}\1 ${green}\2${reset} <${cyan}\3${reset}>/" \
+cw $1 $2 | sed -e "s/^\([-0-9]\{10,10\}\) \([:0-9]\{5,5\}\) <\([^ \t\r\n\v\f]*\)>/${yellow}\1 ${green}\2${reset} <${cyan}\3${reset}>/" \
               -e "s/^\([-0-9]\{10,10\}\) \([:0-9]\{5,5\}\) \(-!-\)/${yellow}\1 ${green}\2${reset} ${magenta}\3${reset}/" \
               -e "s/^\([-0-9]\{10,10\}\) \([:0-9]\{5,5\}\)/${yellow}\1 ${green}\2${reset}/" \
               -e "s/$NICK/\a${red}&${reset}/g" 
 };
 
 watch_t *watch = NULL;
+char *nick = DEFAULT_NICK;
+int color = DEFAULT_COLOR_SETTING;
 
 int evq, init;
-int wins[MAX_WATCH] = {0};
-char paths[MAX_WATCH][PATH_MAX] = {{0}};
 
-/*
-void spawn_win(int wd)
+void usage()
 {
-	char out[PATH_MAX], in[PATH_MAX], path[PATH_MAX], channel[32];
-	char *cmd[] = CMD;
+	fprintf(stderr, "pcw-"VERSION" (c) Evan Gates\n");
+	fprintf(stderr, "Usage: pcw [-v] [-c nick] dir\n");
+	exit(1);
+}
 
-	if (wins[wd])
-		return;
-
-	strcpy(path, paths[wd]); // stupid basename messing with my strings
-	sprintf(channel, "%s> ", basename(path));
-	sprintf(out, "%s/out", paths[wd]);
-	sprintf(in,  "%s/in",  paths[wd]);
-
-	if ((wins[wd] = fork()) == 0) {
-		execvp(cmd[0], cmd);
-		err(1, "failed on execvp %s", cmd[0]);
-	}
-} */
 
 void spawn_win(watch_t *w)
 {
 	char out[PATH_MAX], in[PATH_MAX], path[PATH_MAX], channel[32];
 	char *cmd[] = CMD;
+	char *cmd_color[] = CMD_COLOR;
 
 	strcpy(path,w->path);
 	snprintf(channel,sizeof(channel),"%s> ",basename(path));
 	snprintf(out,sizeof(out),"%s/out",w->path);
 	snprintf(in,sizeof(in),"%s/in",w->path);
 
+	printf("spawning %s\n",w->path);
+
 	if ((w->pid = fork()) == 0) {
-		execvp(cmd[0],cmd);
-		err(1, "failed on execvp %s", cmd[0]);
+		color ? execvp(cmd_color[0],cmd_color) : execvp(cmd[0],cmd);
+		err(1, "failed on execvp %s", color ? cmd_color[0] : cmd[0]);
 	}
 }
 
 	watch_t *w;
 	int wd;
 
+	printf("adding %s\n",fpath);
+
 	if(!(typeflag & FTW_D))
 		return 0;
 
 		warn("failed on inotify_add_watch on %s", fpath);
 		return 0;
 	}
-	printf("test");
 
+	if (!watch) {
+		watch = malloc(sizeof(watch_t));
+		watch->wd = wd;
+	}
 	for(w = watch; w; w = w->next) {
 		if (w->wd == wd) {
 			if(!w->path) {
 				w->path = strdup(fpath);
 				snprintf(out,sizeof(out),"%s/out",fpath);
-				printf("adding %s\n",out);
 				if(!init && stat(out, &st) == 0)
 					spawn_win(w);
 			}
 int main(int argc, char **argv)
 {
 	struct stat st;
+	char *dir = NULL;
+	int i;
 
-	if (argc != 2 || !strcmp(argv[1], "-v")) {
-		fprintf(stderr, "Usage: pcw [-v] dir\n");
-		fprintf(stderr, "pcw-"VERSION" © Evan Gates\n");
-		exit(1);
+	if (argc<2) usage();
+
+	for (i = 1; i < argc; i++) {
+		if (argv[i][0] != '-') {
+			if (!dir) {
+				dir = argv[i];
+				continue;
+			} else { usage(); }
+		}
+		if (argv[i][2] != '\0')
+			usage();
+		switch (argv[i][1]) {
+			case 'c': color = 1; nick = argv[++i]; break;
+			case 'v': break;
+			default: usage();
+		}
 	}
+	if (!dir) 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]);
+	if (stat(dir, &st) < 0 || !S_ISDIR(st.st_mode))
+		errx(1, "%s does not exist or is not a directory", dir);
 
 	if (signal(SIGCHLD, sigchld) == SIG_ERR)
 		err(1, "failed installing SIGCHLD handler");
 
-	run_inotify(argv[1]);
+	run_inotify(dir);
 
 	return 0;
 }