Commits

Evan Gates  committed d1eb0e8

-n nick changes

  • Participants
  • Parent commits 99f5bc2

Comments (0)

Files changed (3)

File config.def.h

 
 
 /*
- * 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.
+ * Use this if you want colors and bell on your nick. You can first edit cw_color.sh to change the
+ * nick if you don't want to use -n nick every time, 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 { "urxvt", "-title", paths[wd], "-e", "srw", "-p", channel, "cw_color.sh", out, in, nick, NULL }
 
 /*
  * Use this if you want to use tabbed (http://tools.suckless.org/tabbed) so that each new channel is
 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}>/" \
-              -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" 
+if [ $# -eq 3 ]; then
+    NICK="$3"
+fi
+
+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" 
 int evq;
 int wins[MAX_WATCH] = {0};
 char paths[MAX_WATCH][PATH_MAX] = {{0}};
+char *nick = NULL;
 
 void win(int wd)
 {
 	}
 }
 
-void sigchld(int unused) {
+void sigchld(int unused)
+{
 	pid_t pid;
 	int wd;
 
 			wins[wd] = 0;
 	}
 }
+void usage(void)
+{
+	fprintf(stderr, "Usage: pcw [-n nick] [-v] dir\n");
+	exit(1);
+}
 
 int main(int argc, char **argv)
 {
 	char buf[4096];
-	int len;
+	int len, i;
 	struct inotify_event *cur;
 	struct stat st;
 
-	if (argc != 2 || !strcmp(argv[1], "-v")) {
-		fprintf(stderr, "Usage: pcw [-v] dir\n");
-		fprintf(stderr, "pcw-"VERSION" © Evan Gates\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 'n' : nick = argv[++i]; break;
+			case 'v' : printf("pcw-"VERSION" © Evan Gates\n"); exit(1);
+			default  : usage();
+		}
 	}
 
+	if (i >= argc)
+		usage();
+
+	if (!nick)
+		nick = getenv("USER");
+
 	if (stat(argv[1], &st) < 0 || !S_ISDIR(st.st_mode))
 		errx(1, "%s does not exist or is not a directory", argv[1]);