diff --git a/ChangeLog.txt b/ChangeLog.txt index 26d0800..b4008da 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,7 @@ +2.0.3: + * Removed highlight from the package (Assumes it is in /usr/local) + * Added Perl and Swift to the colorize.sh script. + 2.0.2: * Modified ReadMe.txt to include the latest info on the Xcode 3.2 conflict * Include a link to Andre Simon's page with previews of color styles diff --git a/Common.m b/Common.m index 719a1a7..a0481ff 100644 --- a/Common.m +++ b/Common.m @@ -83,8 +83,8 @@ [env addEntriesFromDictionary:[defaults persistentDomainForName:myDomain]]; NSString *cmd = [NSString stringWithFormat: - @"'%@/colorize.sh' '%@' '%@' %s", - rsrcEsc, rsrcEsc, targetEsc, thumbnail ? "1" : "0"]; + @"'%@/colorize.sh' '%@' %s", + rsrcEsc, targetEsc, thumbnail ? "1" : "0"]; n8log(@"cmd = %@", cmd); output = runTask(cmd, env, status); diff --git a/GenerateThumbnailForURL.m b/GenerateThumbnailForURL.m index 9399a99..9d2812f 100644 --- a/GenerateThumbnailForURL.m +++ b/GenerateThumbnailForURL.m @@ -89,6 +89,9 @@ done: n8log(@"Finished thumbnail after %.3f sec\n\n", -[startDate timeIntervalSinceNow] ); [pool release]; + if ( webView != NULL ) { + [webView release]; + } return noErr; } diff --git a/Notes.txt b/Notes.txt index c2c30b7..97dfcbb 100644 --- a/Notes.txt +++ b/Notes.txt @@ -1,9 +1,9 @@ Based on highlight: http://www.andre-simon.de/index.html (Was based on pygments: http://pygments.org) -When installing a new version of highlight, make sure to update the -"highlight" symlink in the project dir. Also merge in any updates to -filetypes.conf + +Had a *.* entry in the colorize.sh and it used ##*. to grab the extension and use that as the lang but it didn't work for swift. + The version is handled in the Current Project Version variable in the project. diff --git a/QLColorCode.qlgenerator.zip b/QLColorCode.qlgenerator.zip new file mode 100644 index 0000000..32bdea4 Binary files /dev/null and b/QLColorCode.qlgenerator.zip differ diff --git a/QLColorCode.xcodeproj/project.pbxproj b/QLColorCode.xcodeproj/project.pbxproj index 2909063..1dcfab3 100644 --- a/QLColorCode.xcodeproj/project.pbxproj +++ b/QLColorCode.xcodeproj/project.pbxproj @@ -72,7 +72,6 @@ 0E8776560D08E004005040B4 /* Common.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Common.m; sourceTree = ""; }; 0E8776B60D08ED64005040B4 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = SDKs/MacOSX10.5.sdk/System/Library/Frameworks/WebKit.framework; sourceTree = DEVELOPER_DIR; }; 0E8776BC0D08EDA4005040B4 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = SDKs/MacOSX10.5.sdk/System/Library/Frameworks/AppKit.framework; sourceTree = DEVELOPER_DIR; }; - 0E8FBB56141DA09D00269094 /* override */ = {isa = PBXFileReference; lastKnownFileType = folder; path = override; sourceTree = ""; }; 0EC047960CFBDADF009C986E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; 0EC047F20CFC000A009C986E /* Notes.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Notes.txt; sourceTree = ""; }; 0ECBBB360CFCF98600416538 /* ReadMe.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadMe.txt; sourceTree = ""; }; @@ -141,7 +140,6 @@ 089C167CFE841241C02AAC07 /* Resources */ = { isa = PBXGroup; children = ( - 0E8FBB56141DA09D00269094 /* override */, 8D576317048677EA00EA77CD /* Info.plist */, 8D5B49A704867FD3000E48DA /* InfoPlist.strings */, ); @@ -201,7 +199,6 @@ 8D57630F048677EA00EA77CD /* Resources */, 8D576311048677EA00EA77CD /* Sources */, 8D576313048677EA00EA77CD /* Frameworks */, - 0E9139D70D10A8320067BAD6 /* Install highlight */, 0ECBBA6F0CFCA39E00416538 /* Copy to Library */, 0E1280381061C3EA0078EC05 /* Reset quicklookd */, ); @@ -220,6 +217,8 @@ /* Begin PBXProject section */ 089C1669FE841209C02AAC07 /* Project object */ = { isa = PBXProject; + attributes = { + }; buildConfigurationList = 2CA326220896AD4900168862 /* Build configuration list for PBXProject "QLColorCode" */; compatibilityVersion = "Xcode 3.0"; developmentRegion = English; @@ -281,20 +280,6 @@ shellScript = "qlmanage -r"; showEnvVarsInLog = 0; }; - 0E9139D70D10A8320067BAD6 /* Install highlight */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "Install highlight"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = "/bin/zsh -x"; - shellScript = "set err_exit\ncd $PROJECT_DIR/highlight\nX=\"-arch i386 -arch x86_64 -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET\"\nexport CFLAGS=$X\nexport CXXFLAGS=$X\nexport LDFLAGS=$X\nmake -j 2\n# Make sure it was built universal\n#lipo -info src/highlight | grep -q i386 || exit 1\nlipo -info src/highlight | grep -q x86_64 || exit 1\nmake \\\n\tDESTDIR=$BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH \\\n\tPREFIX=/highlight/ \\\n\tinstall\n\n"; - }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -384,7 +369,7 @@ 2CA326230896AD4900168862 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - CURRENT_PROJECT_VERSION = 2.0.2; + CURRENT_PROJECT_VERSION = 2.0.3; GCC_PREPROCESSOR_DEFINITIONS = DEBUG; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; @@ -397,9 +382,8 @@ 2CA326240896AD4900168862 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_64_BIT_PRE_XCODE_3_1)"; - ARCHS_STANDARD_32_64_BIT_PRE_XCODE_3_1 = "x86_64 i386 ppc"; - CURRENT_PROJECT_VERSION = 2.0.2; + ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; + CURRENT_PROJECT_VERSION = 2.0.3; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; MACOSX_DEPLOYMENT_TARGET = 10.6; diff --git a/ReadMe.txt b/ReadMe.txt index 19d8c65..0548fbe 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -12,8 +12,18 @@ See the end of this file for details. This is a Quick Look plugin that renders source code with syntax highlighting, using the Highlight library: -To install the plugin, just drag it to /Library/QuickLook or ~/Library/QuickLook. -You may need to create that folder if it doesn't already exist. +To install the plugin, just drag it to /Library/QuickLook or +~/Library/QuickLook. You may need to create that folder if it doesn't already +exist. This requires the program highlight to be installed under the /usr/local +directory ('which highlight' should return /usr/local/bin/highlight). The +easiest way to do this is to use the brew package manager (http://brew.sh): +$ brew update +$ brew install highlight +The first command updates the package information. If you installed brew a +while before it may download an old version of highlight. The next version +command installs highlight and any packages it needs. If highlight is already +installed then run the following after updating the package information: +$ brew upgrade highlight If you want to configure QLColorCode, there are several "defaults" commands that could be useful: @@ -30,8 +40,8 @@ the font size: defaults write org.n8gray.QLColorCode fontSizePoints 9 the color style (see http://www.andre-simon.de/dokuwiki/doku.php?id=theme_examples -or try slateGreen to see how I roll. Also included are solarized-light and solarized-dark -as seen at http://ethanschoonover.com/solarized): +or try slateGreen to see how I roll. Also included are solarized-light and +solarized-dark as seen at http://ethanschoonover.com/solarized): defaults write org.n8gray.QLColorCode hlTheme ide-xcode any extra command-line flags for Highlight (see below): @@ -82,10 +92,6 @@ cause problems. Note that if you do edit the Info.plist file you need to nudge the system to tell it something has changed. Moving the plugin to the desktop then back to its installed location should do the trick. -To build from source, you need the Highlight library. Download the source and -uncompress it somewhere, then make a symbolic link to that location from -./highlight - As an aside, by changing colorize.sh you can use this plugin to render any file type that you can convert to HTML. Have fun, and let me know if you do anything cool! diff --git a/colorize.sh b/colorize.sh index f8a52c7..14f5875 100755 --- a/colorize.sh +++ b/colorize.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/zsh # This code is licensed under the GPL v2. See LICENSE.txt for details. @@ -6,64 +6,44 @@ # QLColorCode # # Created by Nathaniel Gray on 11/27/07. -# Copyright 2007 Nathaniel Gray, Jaeho Shin. +# Copyright 2007 Nathaniel Gray. -# Expects $1 = path to resources dir of bundle -# $2 = name of file to colorize -# $3 = 1 if you want enough for a thumbnail, 0 for the full file +# Expects $1 = name of file to colorize +# $2 = 1 if you want enough for a thumbnail, 0 for the full file # # Produces HTML on stdout with exit code 0 on success ############################################################################### # Fail immediately on failure of sub-command -# Also fail whenever undefined variables are used -set -eu - -: \ - ${qlcc_debug:=} \ - ${qlcc_text_fallback:=false} \ - ${maxFileSize:=} \ - ${extraHLFlags:=} \ - # - -RsrcDir=$1 -Target=$2 -case $3 in - 1) Thumb=true ;; - 0|*) Thumb=false ;; -esac +setopt err_exit + +target=$1 +thumb=$2 -debug() { [ -z "$qlcc_debug" ] || ! $Thumb || echo >&2 "QLColorCode: $@"; } +debug () { +if [ "x$qlcc_debug" != "x" ]; then if [ "x$thumb" = "x0" ]; then + echo "QLColorCode: $@" 1>&2 +fi; fi +} debug Starting colorize.sh +#echo target is $target -read-target() { cat "$Target"; } - -# Define how we invoke highlight -# (See: http://www.andre-simon.de/doku/highlight/en/highlight.html) -lang= -highlightOpts=( ---quiet ---validate-input ---encoding "$textEncoding" ---doc-title "${Target##*/}" ---include-style ---style "$hlTheme" ---font "$font" ---font-size "$fontSizePoints" ---data-dir "$RsrcDir"/highlight/share/highlight ---add-config-dir "$RsrcDir"/etc/highlight -) -invoke-highlight() { - set -- "${highlightOpts[@]}" $extraHLFlags "$@" - if [ -n "$lang" ]; then - set -- --syntax "$lang" "$@" - fi - "$RsrcDir"/highlight/bin/highlight "$@" -} +hlDir=/usr/local/share/highlight +cmd=/usr/local/bin/highlight +cmdOpts=(-I -k "$font" -K $fontSizePoints --quiet -I \ + --style=${hlTheme} \ + --encoding $textEncoding ${=extraHLFlags} --validate-input) + +#for o in $cmdOpts; do echo $o\
; done -case ${Target##*/} in +debug Setting reader +reader=(cat $target) + +debug Handling special cases + +case $target in *.graffle ) # some omnigraffle files are XML and get passed to us. Ignore them. exit 1 @@ -71,11 +51,11 @@ case ${Target##*/} in *.plist ) lang=xml - read-target() { /usr/bin/plutil -convert xml1 -o - "$Target"; } + reader=(/usr/bin/plutil -convert xml1 -o - $target) ;; *.h ) - if grep -q "@interface" "$Target" &>/dev/null; then + if grep -q "@interface" $target &> /dev/null; then lang=objc else lang=h @@ -86,7 +66,7 @@ case ${Target##*/} in # look for a matlab-style comment in the first 10 lines, otherwise # assume objective-c. If you never use matlab or never use objc, # you might want to hardwire this one way or the other - if head -n 10 "$Target" | grep -q "^[ ]*%" &>/dev/null; then + if head -n 10 $target | grep -q "^[ ]*%" &> /dev/null; then lang=m else lang=objc @@ -96,51 +76,57 @@ case ${Target##*/} in *.pro ) # Can be either IDL or Prolog. Prolog uses /* */ and % for comments. # IDL uses ; - if head -n 10 "$Target" | grep -q "^[ ]*;" &>/dev/null; then + if head -n 10 $target | grep -q "^[ ]*;" &> /dev/null; then lang=idlang else lang=pro fi ;; - *.* ) - lang=${Target##*.} + *.pl ) + lang=perl ;; - Makefile ) - lang=make + *.swift ) + lang=swift ;; LICENSE |\ COPYING |\ + Podfile |\ README ) lang=txt ;; + + Makefile ) + lang=make + ;; esac -debug Resolved $Target to language $lang -generate-preview () { +debug Resolved $target to language $lang + +go4it () { debug Generating the preview - if $Thumb; then - head -n 100 | head -c 20000 | - invoke-highlight + + # Same as basename $target + local title=${target##*/} + + if [ $thumb = "1" ]; then + $reader | head -n 100 | head -c 20000 | $cmd -S $lang $cmdOpts && exit 0 elif [ -n "$maxFileSize" ]; then - head -c "$maxFileSize" | - invoke-highlight + $reader | head -c $maxFileSize | $cmd -T "${title}" -S $lang $cmdOpts && exit 0 else - invoke-highlight + $reader | $cmd -S $lang -T "${title}" $cmdOpts && exit 0 fi } -if ! read-target | generate-preview; then - # Uh-oh, it didn't work, see if we can fallback to text - if $qlcc_text_fallback || [[ $(file --brief --mime-type "$Target") = text/* ]]; then - # Fallback to rendering as plain text - debug First try failed, fallback to plain text - lang=txt - read-target | generate-preview - else - # Let other QuickLook generator handle - exit 2 - fi -fi +setopt no_err_exit +debug First try... +go4it +# Uh-oh, it didn't work. Fall back to rendering the file as plain +debug First try failed, second try... +lang=txt +go4it +debug Reached the end of the file. That should not happen. +exit 101 +