summary refs log tree commit diff
path: root/chat.c
diff options
context:
space:
mode:
authorCurtis McEnroe2019-09-16 17:09:49 -0400
committerCurtis McEnroe2019-09-16 17:09:49 -0400
commit58a54e3b6b26827b979a1fe8d5bfe27eefdb46a9 (patch)
tree5dde175701cef896e9ed837cd54bceab5664c32b /chat.c
parentc5718dd82fca4fb633846ae232838b477d95d16e (diff)
Set default nick to USER unless -P
Diffstat (limited to 'chat.c')
-rw-r--r--chat.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/chat.c b/chat.c
index 021ac77..7e1a9aa 100644
--- a/chat.c
+++ b/chat.c
@@ -53,9 +53,10 @@ int main(int argc, char *argv[]) {
 	setlocale(LC_CTYPE, "");
 
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "NRW:a:h:j:k:l:n:p:r:u:vw:"))) {
+	while (0 < (opt = getopt(argc, argv, "NPRW:a:h:j:k:l:n:p:r:u:vw:"))) {
 		switch (opt) {
 			break; case 'N': self.notify = true;
+			break; case 'P': self.nick = prompt("Name: ");
 			break; case 'R': self.limit = true;
 			break; case 'W': self.webp = dupe(optarg);
 			break; case 'a': self.auth = dupe(optarg);
@@ -73,9 +74,14 @@ int main(int argc, char *argv[]) {
 		}
 	}
 
+	if (!self.nick) {
+		const char *user = getenv("USER");
+		if (!user) errx(EX_USAGE, "USER unset");
+		self.nick = dupe(user);
+	}
+
 	if (!self.host) self.host = prompt("Host: ");
 	if (!self.port) self.port = dupe("6697");
-	if (!self.nick) self.nick = prompt("Name: ");
 	if (!self.user) self.user = dupe(self.nick);
 	if (!self.real) self.real = dupe(self.nick);