Commits

David Keegan committed bd267d0

Changed to oscherler's escapePath code from issue #94. The previous solution for dealing with spaces in paths only worked for bash terminals. Resolves issue #105.

Comments (0)

Files changed (1)

Source/RepoController_Actions.m

     [ws openURL:fileURL];   //use openURL instead of selectFile to support PathFinder. WD-rpw May 1, 2009
 }
 
+// escapePath method derived from quotePath function in project ShellHere created by John Daniel on 3/22/09,
+// Copyright Etresoft 2009 (www.etresoft.org). All rights reserved.
+- (NSString*) escapePath: (NSString*) path
+{
+    NSScanner *scanner = [NSScanner scannerWithString: path];
+    
+    // Don't skip whitespace.
+    [scanner setCharactersToBeSkipped: [NSCharacterSet illegalCharacterSet]];
+    
+    // Character set with path-unfriendly characters (punctuation, symbols, white space).
+    NSMutableCharacterSet *punctuation = [NSMutableCharacterSet punctuationCharacterSet];
+    [punctuation formUnionWithCharacterSet: [NSCharacterSet symbolCharacterSet]];
+    [punctuation formUnionWithCharacterSet: [NSCharacterSet whitespaceCharacterSet]];
+    
+    // Remove characters that should not (/) or need not (-_.,:+) be replaced.
+    [punctuation removeCharactersInString: @"/-_.,:+"];
+    
+    NSMutableString *escapedPath = [NSMutableString string];
+    NSString *good, *bad;
+    
+    while( ! [scanner isAtEnd] ) {
+        // Scan all the good characters.
+        if( [scanner scanUpToCharactersFromSet: punctuation intoString: &good] )
+            [escapedPath appendString: good];
+        
+        // Scan all the bad characters that come next and escape them.
+        if( [scanner scanCharactersFromSet: punctuation intoString: &bad] )
+            for( NSUInteger i = 0; i < [bad length]; ++i )
+                [escapedPath appendFormat: @"\\%C", [bad characterAtIndex: i]];
+    }
+    
+    return escapedPath;
+}
+
 - (IBAction) openInTerminal: (id) sender
 {
     NSURL* fileURL = [NSURL fileURLWithPath: self.repository.absolutePath];
     }
 	
     // Create a "cd" command.
-    // escape code from JayTuley's - cdto
-    NSString *escapedPath = [[[fileURL path] stringByStandardizingPath] 
-                             stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"];
-    NSString * command = [NSString stringWithFormat: @"cd $'%@';clear;", escapedPath];
+    NSString * command = [NSString stringWithFormat: @"cd %@;clear;", [self escapePath:[fileURL path]]];
     [terminal doScript: command in: currentTab];
     
     // Activate the Terminal. Hopefully, the new window is already open and
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.