Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Inconsistent Style of Code and Added Template Podfile #23

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true
[**]
end_of_line = LF
indent_style = space
indent_size = 2
insert_final_newline = true
tab_width = 8
13 changes: 13 additions & 0 deletions Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
# Uncomment this line if you're using Swift
# use_frameworks!

target 'cd to' do

end

target 'cd to all' do

end

28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
##cd to...
## `cd to ...`
<img src="https://raw.github.com/jbtule/cdto/master/graphics/lion.png" height="128px" width="128px" />

Finder Toolbar app to open the current directory in the Terminal (or iTerm, X11)

* It's written in objective-c, and uses the scripting bridge so it's *fast*.
* It's written in Objective-c, and uses the scripting bridge so it's *fast*.
* It's also shell agnostic. Works equally well when your shell is `bash` or `fish` or `tcsh`.

By Jay Tuley
https://github.com/jbtule/cdto

###Usage:
### Usage:

Download [Latest cdto.zip](https://github.com/jbtule/cdto/releases/latest)

To install "cd to.app" copy it from the appropriate sub-folder (iterm//x11_xterm/unsigned per your choice) to your Applications folder, and then from the applications folder drag it into the Finder toolbar (10.9 Mavericks requires + )
To install "cd to.app" copy it from the appropriate sub-folder (iterm//x11_xterm/unsigned per your choice) to your Applications folder, and then from the applications folder drag it into the Finder toolbar (10.9 Mavericks requires <kbd>⌘</kbd> + <kbd>⌥</kbd>)

To use, just click on the new button and instanly opens a new terminal window.

For old versions to use with iTerm or X11/xterm, using the finder contextual menu "show package contents" and exchange the plugins in the Plugin/Plugin Disabled folders respectively. Next time you run "cd to ..." it should open with the correct application.
For old versions to use with iTerm or X11/xterm, using the finder contextual menu "Show Package Contents" and exchange the plugins in the Plugin/Plugin Disabled folders respectively. Next time you run `cd to ...` it should open with the correct application.


###Changes:
### Changes:
Version 2.6
* Fixed bug where get info window interferes
* works on selected folder again
* Works on selected folder again
* iTerm 2 plugin update

Version 2.5
* Lion Version
* Use terminal open apple event
* works with tcsh as well as bash
* Works with `tcsh` as well as `bash`
* New Icons

Version 2.3
Expand All @@ -51,13 +51,13 @@ Version 2.1
* Terminal plugin will try to avoid opening two windows on terminal.app's launch

Version 2.0 (2005)
* Ported to objective-c using appscript, boosting launch & execution speed
* properly resolves aliases
* no longer shows icon in dock on launch
* Ported to Objective-C using Appscript, boosting launch & execution speed
* Properly resolves aliases
* No longer shows icon in Dock on launch

Version 1.0 (2003)
* targeted Panther OS X 10.3
* was applescript
* Gargeted Panther OS X 10.3
* Was AppleScript

Pre 1.0 (2001)
Really old applescript
* Really old AppleScript
130 changes: 63 additions & 67 deletions main.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,85 +10,81 @@
#import "CD2PluginProtocolV1.h"
#import "Finder.h"

NSString* getPathToFrontFinderWindow(){

FinderApplication* finder = [SBApplication applicationWithBundleIdentifier:@"com.apple.Finder"];

FinderItem *target = [(NSArray*)[[finder selection]get] firstObject];
if (target == nil){
target = [[[[finder FinderWindows] firstObject] target] get];
}

NSURL* url =[NSURL URLWithString:target.URL];
NSError* error;
NSData* bookmark = [NSURL bookmarkDataWithContentsOfURL:url error:nil];
NSURL* fullUrl = [NSURL URLByResolvingBookmarkData:bookmark
NSString* getPathToFrontFinderWindow() {
FinderApplication* finder = [SBApplication applicationWithBundleIdentifier:@"com.apple.Finder"];

FinderItem *target = [(NSArray*)[[finder selection]get] firstObject];
if (target == nil) {
target = [[[[finder FinderWindows] firstObject] target] get];
}

NSURL* url =[NSURL URLWithString:target.URL];
NSError* error;
NSData* bookmark = [NSURL bookmarkDataWithContentsOfURL:url error:nil];
NSURL* fullUrl = [NSURL URLByResolvingBookmarkData:bookmark
options:NSURLBookmarkResolutionWithoutUI
relativeToURL:nil
bookmarkDataIsStale:nil
error:&error];
if(fullUrl != nil){
url = fullUrl;
}

if (fullUrl != nil) {
url = fullUrl;
}

NSString* path = [[url path] stringByExpandingTildeInPath];

BOOL isDir = NO;
[[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir];
NSString* path = [[url path] stringByExpandingTildeInPath];

BOOL isDir = NO;
[[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir];



if(!isDir){
path = [path stringByDeletingLastPathComponent];
}

return path;
}

NSArray* loadPlugins(){
NSString* pluginPath = [[NSBundle mainBundle] builtInPlugInsPath];
NSArray* bundlePaths = [NSArray array];
if (pluginPath != nil) {
bundlePaths =[NSBundle pathsForResourcesOfType:@"bundle"
inDirectory:pluginPath];
}
NSMutableArray* pluginObjectArrays = [NSMutableArray array];
NSEnumerator *enumerator = [bundlePaths objectEnumerator];
NSString* path;
while ((path = (NSString*)[enumerator nextObject])) {
NSBundle* bundle =[NSBundle bundleWithPath:path];
Class pClass =[bundle principalClass];
if([pClass conformsToProtocol:@protocol(CD2PluginProtocolV1)] && [pClass isKindOfClass:[NSObject class]]){
[pluginObjectArrays addObject:[[[pClass alloc]init]autorelease]];
}
}

return pluginObjectArrays;
if (!isDir){
path = [path stringByDeletingLastPathComponent];
}

return path;
}

int main(int argc, char *argv[])
{
id pool = [[NSAutoreleasePool alloc] init];

NSString* path;
@try{
path = getPathToFrontFinderWindow();
}@catch(id ex){
path =[@"~/Desktop" stringByExpandingTildeInPath];
}

NSArray* plugins =loadPlugins();

NSEnumerator *enumerator = [plugins objectEnumerator];
id <CD2PluginProtocolV1> plugin;
while ((plugin = (id <CD2PluginProtocolV1>)[enumerator nextObject])) {
[plugin openTermWindowForPath:path];
}

[pool release];
return 0;
NSArray* loadPlugins() {
NSString* pluginPath = [[NSBundle mainBundle] builtInPlugInsPath];
NSArray* bundlePaths = [NSArray array];
if (pluginPath != nil) {
bundlePaths =[NSBundle pathsForResourcesOfType:@"bundle"
inDirectory:pluginPath];
}
NSMutableArray* pluginObjectArrays = [NSMutableArray array];
NSEnumerator *enumerator = [bundlePaths objectEnumerator];
NSString* path;
while ((path = (NSString*)[enumerator nextObject])) {
NSBundle* bundle =[NSBundle bundleWithPath:path];
Class pClass =[bundle principalClass];
if ([pClass conformsToProtocol:@protocol(CD2PluginProtocolV1)] && [pClass isKindOfClass:[NSObject class]]) {
[pluginObjectArrays addObject:[[[pClass alloc]init]autorelease]];
}
}

return pluginObjectArrays;
}

int main(int argc, char *argv[]) {
id pool = [[NSAutoreleasePool alloc] init];

NSString* path;
@try {
path = getPathToFrontFinderWindow();
}
@catch (id ex) {
path = [@"~/Desktop" stringByExpandingTildeInPath];
}

NSArray* plugins = loadPlugins();

NSEnumerator *enumerator = [plugins objectEnumerator];
id <CD2PluginProtocolV1> plugin;
while ((plugin = (id <CD2PluginProtocolV1>)[enumerator nextObject])) {
[plugin openTermWindowForPath:path];
}

[pool release];
return 0;
}
4 changes: 2 additions & 2 deletions plugins/CD2PluginProtocolV1.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

@protocol CD2PluginProtocolV1

-(BOOL)openTermWindowForPath:(NSString*)aPath;
- (BOOL)openTermWindowForPath:(NSString *)aPath;

@end
@end
2 changes: 1 addition & 1 deletion plugins/X11_xterm/CD2X11XTermPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

}

-(BOOL)openTermWindowForPath:(NSString*)aPath;
- (BOOL)openTermWindowForPath:(NSString *)aPath;


@end
54 changes: 26 additions & 28 deletions plugins/X11_xterm/CD2X11XTermPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,32 @@

@implementation CD2X11XTermPlugin

-(BOOL)openTermWindowForPath:(NSString*)aPath{
@try{
if(![[NSWorkspace sharedWorkspace] launchApplication:@"X11.app"]){
[[NSWorkspace sharedWorkspace] launchApplication:@"XQuartz.app"];
}
NSTask* task =[[NSTask alloc]init];
[task setCurrentDirectoryPath:aPath];
NSMutableDictionary* enviornment =[[[[NSProcessInfo processInfo] environment] mutableCopy]autorelease];

[task setEnvironment:enviornment];

NSString* path = @"/usr/X11R6/bin/xterm";
if(![[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:NULL]){
path = @"/opt/X11/bin/xterm";
}
[task setLaunchPath:path];

[task setStandardOutput:[NSFileHandle fileHandleWithStandardOutput]];

[task setStandardError:[NSFileHandle fileHandleWithStandardOutput]];
[task launch];

}
@catch(id ex){
return NO;
}

return YES;
- (BOOL)openTermWindowForPath:(NSString *)aPath {
@try {
if (![[NSWorkspace sharedWorkspace] launchApplication:@"X11.app"]) {
[[NSWorkspace sharedWorkspace] launchApplication:@"XQuartz.app"];
}
NSTask* task =[[NSTask alloc]init];
[task setCurrentDirectoryPath:aPath];
NSMutableDictionary* enviornment =[[[[NSProcessInfo processInfo] environment] mutableCopy]autorelease];

[task setEnvironment:enviornment];

NSString* path = @"/usr/X11R6/bin/xterm";
if (![[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:NULL]) {
path = @"/opt/X11/bin/xterm";
}
[task setLaunchPath:path];

[task setStandardOutput:[NSFileHandle fileHandleWithStandardOutput]];

[task setStandardError:[NSFileHandle fileHandleWithStandardOutput]];
[task launch];
}
@catch (id ex) {
return NO;
}
return YES;
}

@end
2 changes: 1 addition & 1 deletion plugins/X11_xterm/X11_xterm_Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
//

#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#import <Cocoa/Cocoa.h>
#endif
2 changes: 1 addition & 1 deletion plugins/iterm/CD2ITerm.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@

}

-(BOOL)openTermWindowForPath:(NSString*)aPath;
- (BOOL)openTermWindowForPath:(NSString *)aPath;

@end
17 changes: 8 additions & 9 deletions plugins/iterm/CD2ITerm.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
#import "CD2ITerm.h"

@implementation CD2ITerm
-(BOOL)openTermWindowForPath:(NSString*)aPath{
@try{

[[NSWorkspace sharedWorkspace] openFile:[aPath stringByExpandingTildeInPath] withApplication:@"iTerm.app"];


}@catch(id test){
return NO;
}
return YES;
- (BOOL)openTermWindowForPath:(NSString *)aPath {
@try {
[[NSWorkspace sharedWorkspace] openFile:[aPath stringByExpandingTildeInPath] withApplication:@"iTerm.app"];
}
@catch (id test) {
return NO;
}
return YES;
}

@end
2 changes: 1 addition & 1 deletion plugins/iterm/iterm_Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
//

#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#import <Cocoa/Cocoa.h>
#endif
2 changes: 1 addition & 1 deletion plugins/terminal/CD2Terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

}

-(BOOL)openTermWindowForPath:(NSString*)aPath;
- (BOOL)openTermWindowForPath:(NSString *)aPath;


@end
Loading