From 0f9a2dc9d34c465e2be072b36af6273f7bc51f20 Mon Sep 17 00:00:00 2001 From: Andrew Hankinson Date: Wed, 9 Jan 2013 11:27:47 -0500 Subject: [PATCH] Fixed: XCodeCapp reads the user's shell environment Before this fix, XCodeCapp always ran under /bin/bash, causing problems when trying to source the files from other shells, like /bin/zsh This fix reads the shell information directly from the user's environment and XCC to run using that shell. --- Tools/XcodeCapp/TNXCodeCapp.h | 2 +- Tools/XcodeCapp/TNXCodeCapp.m | 62 +++++++++++++++++++++++++++-------- 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/Tools/XcodeCapp/TNXCodeCapp.h b/Tools/XcodeCapp/TNXCodeCapp.h index 2097b6dc8..fe5e09f0c 100644 --- a/Tools/XcodeCapp/TNXCodeCapp.h +++ b/Tools/XcodeCapp/TNXCodeCapp.h @@ -40,6 +40,7 @@ extern NSString * const XCCListeningStartNotification; NSString *XCodeSupportProjectName; NSString *XCodeTemplatePBXPath; NSString *profilePath; + NSString *shellPath; NSString *PBXModifierScriptPath; NSURL *currentProjectURL; NSURL *XCodeSupportProject; @@ -99,4 +100,3 @@ extern NSString * const XCCListeningStartNotification; - (NSDate*)lastModificationDateForPath:(NSString *)path; @end - diff --git a/Tools/XcodeCapp/TNXCodeCapp.m b/Tools/XcodeCapp/TNXCodeCapp.m index 1e35e29cc..a3d2c3815 100644 --- a/Tools/XcodeCapp/TNXCodeCapp.m +++ b/Tools/XcodeCapp/TNXCodeCapp.m @@ -73,23 +73,59 @@ NSString * const XCCListeningStartNotification = @"XCCListeningStartNotification [self configure]; - if([fm fileExistsAtPath:[@"~/.bash_profile" stringByExpandingTildeInPath]]) - profilePath = [@"source ~/.bash_profile" stringByExpandingTildeInPath]; - else if([fm fileExistsAtPath:[@"~/.profile" stringByExpandingTildeInPath]]) - profilePath = [@"source ~/.profile" stringByExpandingTildeInPath]; - else if([fm fileExistsAtPath:[@"~/.bashrc" stringByExpandingTildeInPath]]) - profilePath = [@"source ~/.bashrc" stringByExpandingTildeInPath]; - else if([fm fileExistsAtPath:[@"~/.zshrc" stringByExpandingTildeInPath]]) - profilePath = [@"source ~/.zshrc" stringByExpandingTildeInPath]; + NSString* myShell = [[[NSProcessInfo processInfo] environment] objectForKey:@"SHELL"]; + + if (myShell) + { + shellPath = myShell; + } else { - NSAlert *alert = [NSAlert alertWithMessageText:@"Cannot find any valid profile file." + shellPath = @"/bin/bash"; + } + + if([shellPath isEqualToString:@"/bin/bash"]) + { + if([fm fileExistsAtPath:[@"~/.bash_profile" stringByExpandingTildeInPath]]) + { + profilePath = [@"source ~/.bash_profile" stringByExpandingTildeInPath]; + } + else if([fm fileExistsAtPath:[@"~/.bashrc" stringByExpandingTildeInPath]]) + { + profilePath = [@"source ~/.bashrc" stringByExpandingTildeInPath]; + } + else if([fm fileExistsAtPath:[@"~/.profile" stringByExpandingTildeInPath]]) + { + profilePath = [@"source ~/.profile" stringByExpandingTildeInPath]; + } + else + { + profilePath = @""; + } + + } + else if ([shellPath isEqualToString:@"/bin/zsh"]) + if([fm fileExistsAtPath:[@"~/.zshrc" stringByExpandingTildeInPath]]) + { + profilePath = [@"source ~/.zshrc" stringByExpandingTildeInPath]; + } + else if([fm fileExistsAtPath:[@"~/.profile" stringByExpandingTildeInPath]]) + { + profilePath = [@"source ~/.profile" stringByExpandingTildeInPath]; + } + else + { + profilePath = @""; + } + else + { + NSAlert *alert = [NSAlert alertWithMessageText:@"Shell not recognized." defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:@"Neither ~/.bash_profile, ~/.profile, ~/.bashrc nor ~/.zshrc can be found.\n\nWithout this XcodeCapp cannot locate nib2cib.\n\nIf you notice any errors or strange behaviour, please look at the system log for messages and open a ticket."]; + informativeTextWithFormat:@"You are running %@ as your shell, which is not supported. Please change your shell to either BASH or ZSH.", shellPath]; [alert runModal]; - profilePath = @""; + profilePath = @""; } } @@ -415,8 +451,8 @@ NSString * const XCCListeningStartNotification = @"XCCListeningStartNotification NSNumber *status; task = [[NSTask alloc] init]; - - [task setLaunchPath: @"/bin/bash"]; + + [task setLaunchPath:shellPath]; [task setArguments: arguments]; [task setStandardOutput:[NSPipe pipe]]; [task launch];