From d2d1903ce99fff6d2f707561c1d037808dfdf94f Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Mon, 12 Nov 2007 20:17:57 +0100 Subject: [PATCH] Disable login shell with "MMLoginShell" New Vim processes are by default launched via a login shell so that the user's environment gets profiled. This behavior can be disabled by setting the user default "MMLoginShell" to 0. --- src/MacVim/MMAppController.m | 65 ++++++++++++++++++++++++++++---------------- src/MacVim/MacVim.h | 1 + src/MacVim/MacVim.m | 1 + 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index 4a15f451..21f61c1e 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -84,6 +84,7 @@ static NSTimeInterval MMReplyTimeout = 5; [NSNumber numberWithBool:YES], MMTranslateCtrlClickKey, [NSNumber numberWithBool:NO], MMOpenFilesInTabsKey, [NSNumber numberWithBool:NO], MMNoFontSubstitutionKey, + [NSNumber numberWithBool:YES], MMLoginShellKey, nil]; [[NSUserDefaults standardUserDefaults] registerDefaults:dict]; @@ -520,39 +521,55 @@ static NSTimeInterval MMReplyTimeout = 5; - (void)launchVimProcessWithArguments:(NSArray *)args { + NSString *taskPath = nil; + NSArray *taskArgs = nil; NSString *path = [[NSBundle mainBundle] pathForAuxiliaryExecutable:@"Vim"]; + if (!path) { NSLog(@"ERROR: Vim executable could not be found inside app bundle!"); return; } - NSMutableString *execArg = [NSMutableString - stringWithFormat:@"exec \"%@\" -g", path]; - if (args) { - // Append all arguments while making sure that arguments containing - // spaces are enclosed in quotes. - NSCharacterSet *space = [NSCharacterSet whitespaceCharacterSet]; - unsigned i, count = [args count]; - - for (i = 0; i < count; ++i) { - NSString *arg = [args objectAtIndex:i]; - if (NSNotFound != [arg rangeOfCharacterFromSet:space].location) - [execArg appendFormat:@" \"%@\"", arg]; - else - [execArg appendFormat:@" %@", arg]; + if ([[NSUserDefaults standardUserDefaults] boolForKey:MMLoginShellKey]) { + // Run process with a login shell + // $SHELL -l -c "exec Vim args" + + NSMutableString *execArg = [NSMutableString + stringWithFormat:@"exec \"%@\" -g", path]; + if (args) { + // Append all arguments while making sure that arguments containing + // spaces are enclosed in quotes. + NSCharacterSet *space = [NSCharacterSet whitespaceCharacterSet]; + unsigned i, count = [args count]; + + for (i = 0; i < count; ++i) { + NSString *arg = [args objectAtIndex:i]; + if (NSNotFound != [arg rangeOfCharacterFromSet:space].location) + [execArg appendFormat:@" \"%@\"", arg]; + else + [execArg appendFormat:@" %@", arg]; + } } - } - // Launch the process with a login shell so that users environment settings - // get sourced. This does not always happen when MacVim is started. - NSArray *shellArgs = [NSArray arrayWithObjects:@"-l", @"-c", execArg, nil]; - NSString *shell = [[[NSProcessInfo processInfo] environment] - objectForKey:@"SHELL"]; - if (!shell) - shell = @"/bin/sh"; + // Launch the process with a login shell so that users environment + // settings get sourced. This does not always happen when MacVim is + // started. + taskArgs = [NSArray arrayWithObjects:@"-l", @"-c", execArg, nil]; + taskPath = [[[NSProcessInfo processInfo] environment] + objectForKey:@"SHELL"]; + if (!taskPath) + taskPath = @"/bin/sh"; + } else { + // Run process directly: + // Vim args + taskPath = path; + taskArgs = [NSArray arrayWithObject:@"-g"]; + if (args) + taskArgs = [taskArgs arrayByAddingObjectsFromArray:args]; + } - //NSLog(@"Launching: %@ args: %@", shell, shellArgs); - [NSTask launchedTaskWithLaunchPath:shell arguments:shellArgs]; + //NSLog(@"Launching: %@ args: %@", taskPath, taskArgs); + [NSTask launchedTaskWithLaunchPath:taskPath arguments:taskArgs]; } - (NSArray *)filterFilesAndNotify:(NSArray *)filenames diff --git a/src/MacVim/MacVim.h b/src/MacVim/MacVim.h index 1a77024d..49031ca9 100644 --- a/src/MacVim/MacVim.h +++ b/src/MacVim/MacVim.h @@ -210,6 +210,7 @@ extern NSString *MMTranslateCtrlClickKey; extern NSString *MMTopLeftPointKey; extern NSString *MMOpenFilesInTabsKey; extern NSString *MMNoFontSubstitutionKey; +extern NSString *MMLoginShellKey; diff --git a/src/MacVim/MacVim.m b/src/MacVim/MacVim.m index 45504ab4..e3e6a9f4 100644 --- a/src/MacVim/MacVim.m +++ b/src/MacVim/MacVim.m @@ -91,6 +91,7 @@ NSString *MMTranslateCtrlClickKey = @"MMTranslateCtrlClick"; NSString *MMTopLeftPointKey = @"MMTopLeftPoint"; NSString *MMOpenFilesInTabsKey = @"MMOpenFilesInTabs"; NSString *MMNoFontSubstitutionKey = @"MMNoFontSubstitution"; +NSString *MMLoginShellKey = @"MMLoginShell"; -- 2.11.4.GIT