@@ -158,12 +158,14 @@ impl ShellUser {
158158}
159159
160160#[ cfg( not( target_os = "macos" ) ) ]
161- fn default_shell_command ( shell : & str , _user : & str ) -> Command {
161+ fn default_shell_command ( shell : & str , _user : & str , _home : & str ) -> Command {
162162 Command :: new ( shell)
163163}
164164
165165#[ cfg( target_os = "macos" ) ]
166- fn default_shell_command ( shell : & str , user : & str ) -> Command {
166+ fn default_shell_command ( shell : & str , user : & str , home : & str ) -> Command {
167+ use std:: path:: Path ;
168+
167169 let shell_name = shell. rsplit ( '/' ) . next ( ) . unwrap ( ) ;
168170
169171 // On macOS, use the `login` command so the shell will appear as a tty session.
@@ -173,12 +175,20 @@ fn default_shell_command(shell: &str, user: &str) -> Command {
173175 // `login` normally does this itself, but `-l` disables this.
174176 let exec = format ! ( "exec -a -{} {}" , shell_name, shell) ;
175177
178+ // Since we use -l, `login` will not change directory to the user's home. However,
179+ // `login` only checks the current working directory for a .hushlogin file, causing
180+ // it to miss any in the user's home directory. We can fix this by doing the check
181+ // ourselves and passing `-q`
182+ let has_home_hushlogin = Path :: new ( home) . join ( ".hushlogin" ) . exists ( ) ;
183+
176184 // -f: Bypasses authentication for the already-logged-in user.
177185 // -l: Skips changing directory to $HOME and prepending '-' to argv[0].
178186 // -p: Preserves the environment.
187+ // -q: Act as if `.hushlogin` exists.
179188 //
180189 // XXX: we use zsh here over sh due to `exec -a`.
181- login_command. args ( [ "-flp" , user, "/bin/zsh" , "-fc" , & exec] ) ;
190+ let flags = if has_home_hushlogin { "-qflp" } else { "-flp" } ;
191+ login_command. args ( [ flags, user, "/bin/zsh" , "-fc" , & exec] ) ;
182192 login_command
183193}
184194
@@ -208,7 +218,7 @@ pub fn from_fd(config: &Options, window_id: u64, master: OwnedFd, slave: OwnedFd
208218 cmd. args ( shell. args . as_slice ( ) ) ;
209219 cmd
210220 } else {
211- default_shell_command ( & user. shell , & user. user )
221+ default_shell_command ( & user. shell , & user. user , & user . home )
212222 } ;
213223
214224 // Setup child stdin/stdout/stderr as slave fd of PTY.
0 commit comments