Set default nick to USER unless -P

master
Curtis McEnroe 2019-09-16 17:09:49 -04:00
parent c5718dd82f
commit 58a54e3b6b
No known key found for this signature in database
GPG Key ID: CEA2F97ADCFCD77C
2 changed files with 16 additions and 11 deletions

View File

@ -8,7 +8,7 @@
. .
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl NRv .Op Fl NPRv
.Op Fl W Ar pass .Op Fl W Ar pass
.Op Fl a Ar auth .Op Fl a Ar auth
.Op Fl h Ar host .Op Fl h Ar host
@ -33,6 +33,9 @@ The arguments are as follows:
Send notifications with Send notifications with
.Xr notify-send 1 . .Xr notify-send 1 .
. .
.It Fl P
Prompt for nickname.
.
.It Fl R .It Fl R
Restrict the use of the Restrict the use of the
.Ic /join , .Ic /join ,
@ -83,6 +86,8 @@ in files named by date.
.It Fl n Ar nick .It Fl n Ar nick
Set nickname to Set nickname to
.Ar nick . .Ar nick .
The default nickname
is the user's name.
. .
.It Fl p Ar port .It Fl p Ar port
Connect to Connect to
@ -114,14 +119,6 @@ Log in with
.Ar pass . .Ar pass .
.El .El
. .
.Pp
If
.Fl h Ar host
or
.Fl n Ar nick
are not provided,
they will be prompted for.
.
.Sh COMMANDS .Sh COMMANDS
Any unique prefix Any unique prefix
may be used to abbreviate a command. may be used to abbreviate a command.
@ -367,6 +364,8 @@ to set the hostname
to the first word of to the first word of
.Ev SSH_CLIENT , .Ev SSH_CLIENT ,
usually the client IP address. usually the client IP address.
.It Ev USER
The default nickname.
.El .El
. .
.Sh EXAMPLES .Sh EXAMPLES

10
chat.c
View File

@ -53,9 +53,10 @@ int main(int argc, char *argv[]) {
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
int opt; 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) { switch (opt) {
break; case 'N': self.notify = true; break; case 'N': self.notify = true;
break; case 'P': self.nick = prompt("Name: ");
break; case 'R': self.limit = true; break; case 'R': self.limit = true;
break; case 'W': self.webp = dupe(optarg); break; case 'W': self.webp = dupe(optarg);
break; case 'a': self.auth = 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.host) self.host = prompt("Host: ");
if (!self.port) self.port = dupe("6697"); if (!self.port) self.port = dupe("6697");
if (!self.nick) self.nick = prompt("Name: ");
if (!self.user) self.user = dupe(self.nick); if (!self.user) self.user = dupe(self.nick);
if (!self.real) self.real = dupe(self.nick); if (!self.real) self.real = dupe(self.nick);