Skip to content

Commit 10ef744

Browse files
committed
Adds support for auto-detecting the location of highlight
The plugin now searches for highlight using “which highlight” and falls back on /opt/local/bin/highlight
1 parent 627d28c commit 10ef744

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

QLColorCode.xcodeproj/project.pbxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@
206206
089C1669FE841209C02AAC07 /* Project object */ = {
207207
isa = PBXProject;
208208
attributes = {
209-
LastUpgradeCheck = 0700;
209+
LastUpgradeCheck = 0730;
210210
};
211211
buildConfigurationList = 2CA326220896AD4900168862 /* Build configuration list for PBXProject "QLColorCode" */;
212212
compatibilityVersion = "Xcode 3.2";
@@ -338,13 +338,15 @@
338338
2CA3261F0896AD4900168862 /* Debug */ = {
339339
isa = XCBuildConfiguration;
340340
buildSettings = {
341+
COMBINE_HIDPI_IMAGES = YES;
341342
OTHER_CFLAGS = "-DDEBUG";
342343
};
343344
name = Debug;
344345
};
345346
2CA326200896AD4900168862 /* Release */ = {
346347
isa = XCBuildConfiguration;
347348
buildSettings = {
349+
COMBINE_HIDPI_IMAGES = YES;
348350
};
349351
name = Release;
350352
};

src/Common.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,32 @@
6969

7070
// Set up preferences
7171
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
72+
73+
// Try to find highlight location
74+
NSString *highlightPath = [defaults valueForKey:@"pathHL"];
75+
if (highlightPath == nil) {
76+
NSTask *task = [[NSTask alloc] init];
77+
[task setLaunchPath:@"/bin/bash"];
78+
[task setArguments:@[@"-l", @"-c", @"which highlight"]];
79+
NSPipe *pipe;
80+
pipe = [NSPipe pipe];
81+
[task setStandardOutput: pipe];
82+
NSFileHandle *file;
83+
file = [pipe fileHandleForReading];
84+
[task launch];
85+
NSData *data;
86+
data = [file readDataToEndOfFile];
87+
[task waitUntilExit];
88+
highlightPath = [[[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease] stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
89+
[task release];
90+
[file closeFile];
91+
if (![highlightPath hasPrefix: @"/"] || ![highlightPath hasSuffix: @"highlight"]) { // fallback on default
92+
highlightPath = @"/opt/local/bin/highlight";
93+
}
94+
[defaults setObject:highlightPath forKey:@"pathHL"];
95+
[defaults synchronize];
96+
}
97+
7298
NSMutableDictionary *env = [NSMutableDictionary dictionaryWithDictionary:
7399
[[NSProcessInfo processInfo] environment]];
74100
[env addEntriesFromDictionary:[NSDictionary dictionaryWithObjectsAndKeys:

0 commit comments

Comments
 (0)