macOS: Fix opening and running in terminal with zsh

We need to read different startup files for zsh.

Task-number: QTCREATORBUG-21712
Change-Id: Id10b185e3957b44423e847114adc1b3085a8089d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Eike Ziller
2019-11-08 12:27:40 +01:00
parent f51f2a90c6
commit f9c03f23c4

View File

@@ -54,10 +54,10 @@ while read -r line; do
done < <(env) done < <(env)
''' '''
def system_login_script(): def system_login_script_bash():
return 'if [ -f /etc/profile ]; then source /etc/profile; fi\n' return 'if [ -f /etc/profile ]; then source /etc/profile; fi\n'
def login_script(): def login_script_bash():
return ''' return '''
if [ -f $HOME/.bash_profile ]; then if [ -f $HOME/.bash_profile ]; then
source $HOME/.bash_profile source $HOME/.bash_profile
@@ -68,6 +68,16 @@ elif [ -f $HOME/.profile ]; then
fi fi
''' '''
def system_login_script_zsh():
return '[ -r /etc/profile ] && source /etc/profile\n'
def login_script_zsh():
return '''
[ -r $HOME/.zprofile ] && source $HOME/.zprofile
[ -r $HOME/.zshrc ] && source $HOME/.zshrc
[ -r $HOME/.zlogin ] && source $HOME/.zlogin
'''
def environment_script(): def environment_script():
return ''.join(['export ' + quote_shell(key + '=' + os.environ[key]) + '\n' return ''.join(['export ' + quote_shell(key + '=' + os.environ[key]) + '\n'
for key in os.environ]) for key in os.environ])
@@ -98,6 +108,10 @@ end tell
def main(): def main():
# create temporary file to be sourced into bash that deletes itself # create temporary file to be sourced into bash that deletes itself
with NamedTemporaryFile(delete=False) as shell_script: with NamedTemporaryFile(delete=False) as shell_script:
shell = os.environ.get('SHELL')
shell_is_zsh = shell is not None and shell.endswith('/zsh')
system_login_script = system_login_script_zsh if shell_is_zsh else system_login_script_bash
login_script = login_script_zsh if shell_is_zsh else login_script_bash
quoted_shell_script = quote_shell(shell_script.name) quoted_shell_script = quote_shell(shell_script.name)
commands = (clean_environment_script() + commands = (clean_environment_script() +
system_login_script() + # /etc/profile by default resets the path, so do first system_login_script() + # /etc/profile by default resets the path, so do first