@@ -29,6 +29,8 @@ import { IncomingMessage } from 'http'
29
29
import { Channel } from './channel'
30
30
import { StdioChannelKuiSide } from './stdio-channel'
31
31
32
+ import kuirc from './kuirc'
33
+
32
34
import { CodedError , ExecOptions , Registrar } from '@kui-shell/core'
33
35
34
36
const debug = Debug ( 'plugins/bash-like/pty/server' )
@@ -148,49 +150,58 @@ export const disableBashSessions = async (): Promise<ExitHandler> => {
148
150
* Determine, and cache, the user's login shell
149
151
*
150
152
*/
151
- const bashShellOpts = [ '-l' , '-i' , '-c' , '--' ]
152
- const shellOpts = process . platform === 'win32' ? [ ] : bashShellOpts
153
153
type Shell = { shellExe : string ; shellOpts : string [ ] }
154
- let cachedLoginShell : Shell
155
- export const getLoginShell = ( ) : Promise < Shell > => {
154
+ let cachedLoginShell : string
155
+ export const getLoginShell = ( ) : Promise < string > => {
156
156
return new Promise ( ( resolve , reject ) => {
157
157
if ( cachedLoginShell ) {
158
158
debug ( 'returning cached login shell' , cachedLoginShell )
159
159
resolve ( cachedLoginShell )
160
160
} else if ( process . env . SHELL ) {
161
161
// Note how we intentionally assume bash here, even on windows
162
- resolve ( { shellExe : process . env . SHELL , shellOpts : bashShellOpts } )
162
+ resolve ( process . env . SHELL )
163
163
} else {
164
164
const defaultShell = process . platform === 'win32' ? 'powershell.exe' : '/bin/bash'
165
165
166
166
if ( process . env . TRAVIS_JOB_ID !== undefined || process . platform === 'win32' ) {
167
167
debug ( 'using defaultShell for travis' )
168
- cachedLoginShell = { shellExe : defaultShell , shellOpts }
168
+ cachedLoginShell = defaultShell
169
169
resolve ( cachedLoginShell )
170
170
} else {
171
171
try {
172
- exec ( `${ defaultShell } -l -c "echo $SHELL"` , ( err , stdout , stderr ) => {
172
+ exec ( `${ defaultShell } -l -c "echo $SHELL"` , async ( err , stdout , stderr ) => {
173
173
if ( err ) {
174
174
console . error ( 'error in getLoginShell subroutine' , err )
175
175
if ( stderr ) {
176
176
console . error ( stderr )
177
177
}
178
178
reject ( err )
179
179
} else {
180
- cachedLoginShell = { shellExe : stdout . trim ( ) || defaultShell , shellOpts }
180
+ cachedLoginShell = stdout . trim ( ) || defaultShell
181
181
debug ( 'login shell' , cachedLoginShell )
182
182
resolve ( cachedLoginShell )
183
183
}
184
184
} )
185
185
} catch ( err ) {
186
186
console . error ( 'error in exec of getLoginShell subroutine' , err )
187
- resolve ( { shellExe : defaultShell , shellOpts } )
187
+ resolve ( defaultShell )
188
188
}
189
189
}
190
190
}
191
191
} )
192
192
}
193
193
194
+ export async function getShellOpts ( ) : Promise < Shell > {
195
+ const bashShellOpts = process . platform === 'win32' ? undefined : [ '--rcfile' , await kuirc , '-i' , '-c' , '--' ]
196
+ const shellOpts = process . platform === 'win32' ? [ ] : bashShellOpts
197
+ console . error ( '!!!!!!!!' , bashShellOpts )
198
+
199
+ return {
200
+ shellExe : process . platform === 'win32' ? 'powershell.exe' : '/bin/bash' ,
201
+ shellOpts
202
+ }
203
+ }
204
+
194
205
/**
195
206
* Use precomputed shell aliases
196
207
*
@@ -305,7 +316,7 @@ export const onConnection = (exitNow: ExitHandler, uid?: number, gid?: number) =
305
316
const aliasedCmd = shellAliases [ cmd ]
306
317
const cmdline = aliasedCmd ? msg . cmdline . replace ( new RegExp ( `^${ cmd } ` ) , aliasedCmd ) : msg . cmdline
307
318
308
- const { shellExe, shellOpts } = await getLoginShell ( )
319
+ const { shellExe, shellOpts } = await getShellOpts ( )
309
320
let shell = spawn ( shellExe , shellOpts . concat ( [ cmdline ] ) , {
310
321
uid,
311
322
gid,
0 commit comments