Make sh(1) support \u in PS1. This removes one fork/exec on interactive
shell startup.
Details
- Reviewers
jilles 0mp - Group Reviewers
manpages - Commits
- rS343399: Make sh(1) support \u in PS1. This removes one fork/exec on interactive
Diff Detail
- Repository
- rS FreeBSD src repository - subversion
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
bin/sh/sh.1 | ||
---|---|---|
1406 ↗ | (On Diff #52688) | I do remember; it's just that I never know when something will get committed. |
bin/sh/parser.c | ||
---|---|---|
1983 ↗ | (On Diff #52689) | We have the LOGNAME variable that's set (from login(8)): The login utility enters information into the environment (see environ(7)) specifying the user's home directory (HOME), command interpreter (SHELL), search path (PATH), terminal type (TERM) and user name (both LOGNAME and USER). so maybe use that instead and fall back to this as a backup? |
2059 ↗ | (On Diff #52689) | Can you write a regression test for this too? |
bin/sh/parser.c | ||
---|---|---|
1983 ↗ | (On Diff #52689) | I used to run a system where we had 4 different users map to the same UID, but have different home directories, so we found (and often fixed) programs that didn't grok LOGNAME properly... So it can and does happen. |
bin/sh/parser.c | ||
---|---|---|
1983 ↗ | (On Diff #52689) | There are two problems with LOGNAME - first, the user (or script) can change it, and it seems kind of wrong to display that instead of the actual login name. Second - LOGNAME seems to be unaffected by su(1), so after you su from your normal user to root, it will still return the name of the normal user and not 'root'. The latter problem also seems to apply to getlogin(2). So, both ways seem somewhat suboptimal, in different ways. As it is now, sh(1) just calls whoami(1), and that does pretty much the same as the code added here. |
2059 ↗ | (On Diff #52689) | Hm, we don't seem to have any tests for the prompt, do we? |
My original objection to \u is no longer valid since we have accepted that the ugly \ bash prompt sequences are staying.
bin/sh/parser.c | ||
---|---|---|
1983 ↗ | (On Diff #52689) | More "proper" way would be to getpwnam based on LOGNAME (or getlogin(2)?) and use that if the passwd's UID matches geteuid(); otherwise, use getpwuid as now. |