git: b4b61ead7eab - main - dot.profile: handle symlinked $HOME

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Tue, 13 Feb 2024 18:25:35 UTC
The branch main has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=b4b61ead7eabb7b6f3a6de67f7594b17c3a20660

commit b4b61ead7eabb7b6f3a6de67f7594b17c3a20660
Author:     Edward Tomasz Napierala <trasz@FreeBSD.org>
AuthorDate: 2019-01-09 11:04:27 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2024-02-13 18:24:22 +0000

    dot.profile: handle symlinked $HOME
    
    Reapply 4cea05a273c875b5d5d4c41bfa6f2f0a60fa4a66:
    
        Make sh(1) recognize the default $HOME.  By default /home
        is a symlink; without this change, when you log in, sh(1)
        won't realize the current directory (eg '/usr/home/test')
        is the same as $HOME ('/home/test').
    
    /home is no longer a symlink by default, but new users may be added on
    systems that started out with an earlier version of FreeBSD (and still
    have /home as a symlink) or admins may do so.
    
    This test is not particularly expensive, so just restore it.
    
    Suggested by:   danfe, brooks
---
 share/skel/dot.profile | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/share/skel/dot.profile b/share/skel/dot.profile
index 7b9aa96c834a..40dfa58f4e84 100644
--- a/share/skel/dot.profile
+++ b/share/skel/dot.profile
@@ -19,6 +19,9 @@ PAGER=less;  	export PAGER
 # set ENV to a file invoked each time sh is started for interactive use.
 ENV=$HOME/.shrc; export ENV
 
+# Let sh(1) know it's at home, despite /home being a symlink.
+if [ "$PWD" != "$HOME" ] && [ "$PWD" -ef "$HOME" ] ; then cd ; fi
+
 # Query terminal size; useful for serial lines.
 if [ -x /usr/bin/resizewin ] ; then /usr/bin/resizewin -z ; fi