LyX tries to use gecos [1] information to get the user's real name to put in 
the "name" field in tools > preferences > identity. LyX currently uses all four 
gecos fields, which is why on Ubuntu I've been seeing "scott,,,". If you had 
entered a room number, work phone, or home phone in your gecos, these would 
have shown up under LyX's "name" field as well. To see this, you can run the 
command chfn and this will allow you to change the gecos fields. Then rename 
your LyX user preferences file which forces LyX to regenerate your "user name" 
in tools > preferences > identity. Another way to see what your gecos looks 
like is to look in /etc/passwd

LyX does this in support::user_name() which currently returns the entire gecos 
if there is one, and if gecos is empty it returns the user name.

Under the attached patch, support::user_name() returns the real name field of 
gecos (that is, everything up to the first comma) except if that field is empty 
in which case it returns the user name.

Also note that the function "user_name" is somewhat deceptive. Our first 
approach is to get the *real* name. Getting the user_name is only the backup. 
Assuming that real_or_user_name() is too long, I don't have any suggestion. I 
updated the comment to reflect these two return possibilities.

I found a similar patch [2] by John Levon (CC'ed on this email) that was added 
in lyx 1.3.6 but somewhere along the way it was taken out. I couldn't figure 
out why since it was so long ago and happened before userinfo.cpp existed.

Comments?

Thank you,

Scott

[1] http://en.wikipedia.org/wiki/Gecos_field
[2] http://wiki.lyx.org/uploads/Tips/lyx-1.3.6-changebars.diff.txt
diff --git a/src/support/userinfo.cpp b/src/support/userinfo.cpp
index 5f2cfca..1d18636 100644
--- a/src/support/userinfo.cpp
+++ b/src/support/userinfo.cpp
@@ -48,7 +48,9 @@ docstring const user_name()
 	struct passwd * pw = getpwuid(geteuid());
 	LASSERT(pw, /**/);
 
-	string name = pw->pw_gecos;
+	const string gecos = pw->pw_gecos;
+	const size_t pos = gecos.find(",");
+	string name = gecos.substr(0, pos);
 	if (name.empty())
 		name = pw->pw_name;
 	return from_local8bit(name);
diff --git a/src/support/userinfo.h b/src/support/userinfo.h
index 2c482f4..6232a2b 100644
--- a/src/support/userinfo.h
+++ b/src/support/userinfo.h
@@ -18,7 +18,7 @@
 namespace lyx {
 namespace support {
 
-/// return the current user's real name
+/// return the current user's real name or user name
 docstring const user_name();
 
 /// return the current user's e-mail address

Reply via email to