Skip to content

Instantly share code, notes, and snippets.

@cypher
Created October 4, 2009 11:14
Show Gist options
  • Save cypher/201308 to your computer and use it in GitHub Desktop.
Save cypher/201308 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# Released under MIT License
# Copyright (c) 2009 Markus Prinz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
require 'shellwords'
# For rlwrap
BREAK_CHARS=%q/(){}[],^%$#@"";:''|\\/
# Update Java Classpath
CLASSPATH = ENV["CLASSPATH"] ? ENV["CLASSPATH"].split(':') : []
custom_classes_path = File.expand_path("~/classes")
Dir[File.join(custom_classes_path, "*.jar")].each do |jar|
CLASSPATH << jar unless CLASSPATH.include?(jar)
end if File.exists?(custom_classes_path)
# Add processing stuff, if it is installed
PROCESSING_DIR = "/Applications/Processing.app/Contents/Resources/Java"
processing_available = false
if File.exists?(PROCESSING_DIR)
%w(
core.jar
libraries/opengl/library/gluegen-rt.jar
libraries/opengl/library/jogl.jar
libraries/opengl/library/opengl.jar
).each do |jar_name|
jar = File.join(PROCESSING_DIR, jar_name)
CLASSPATH << jar if File.exists?(jar) && !CLASSPATH.include?(jar)
end
processing_available = true
end
CLOJURE_DIR = File.expand_path("~/Code/clojure")
CLOJURE_JAR = File.join(CLOJURE_DIR, "clojure.jar")
CLOJURE_CONTRIB_DIR = File.expand_path("~/Code/clojure-contrib")
CLOJURE_CONTRIB_JAR = File.join(CLOJURE_CONTRIB_DIR, "clojure-contrib.jar")
run_clojure = "java "
run_clojure << "-Djava.library.path=#{PROCESSING_DIR}/libraries/opengl/library " if processing_available
run_clojure << "-cp #{CLOJURE_JAR}:#{CLOJURE_CONTRIB_JAR}:#{CLASSPATH.join(":")} "
if ARGV.empty?
run_repl = if system("which rlwrap")
"rlwrap --remember --complete-filenames --break-chars=#{BREAK_CHARS.shellescape} --file=#{File.expand_path("~/.clj_completions")} "
else
""
end
run_repl << run_clojure
run_clojure << "jline.ConsoleRunner " if CLASSPATH.find{ |jar| jar =~ /jline-\d+\.\d+\.\d+\.jar/ }
run_repl << "clojure.main"
exec run_repl
else
exec "#{run_clojure} clojure.lang.Script #{ARGV[0]} -- #{ARGV[1..-1].shelljoin}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment