Source

clojurewise / cljeclipse.sh

Full commit
#!/bin/bash
# Open a Clojure REPL with classpath set to given Eclipse project

# Run new terminal first
if [ "$1" != "--no-fork" ]; then
    gnome-terminal -t "Clojure ($(basename $PWD))" -x $0 --no-fork $* &
    exit
fi

shift

# Change to where you store Clojure jars
cljroot=/opt/clojure

if [ $# -eq 0 ]; then
    root=.
else
    root=$1
fi

case $root in
    -h | --help ) echo "usage: $(basename $0) [PROJECT_ROOT]"; exit;;
esac

if [ ! -d $root ]; then
    echo "error: ${root} is not a directory" 1>&2
    exit 1
fi

classpath_file=${root}/.classpath
if [ ! -f $classpath_file ]; then
    echo "error: can't find .classpath (did you run 'mvn eclipse:eclipse'?)" \
         1>&2
    exit 1
fi

# Escape path for sed
m2root=$(echo $HOME | sed 's/\//\\\//g')
m2root="${m2root}\\/.m2\\/repository"

# Convert M2_REPO to ~/.m2/repository and replace newlines with :
eclipse_classpath=$(
    egrep -o 'M2_REPO[^"]*' $classpath_file | \
    sed "s/M2_REPO/${m2root}/" | \
    tr '\n' :
)

# Grab all jars in Clojure directory
clj_classpath=$(ls ${cljroot}/*.jar | tr '\n' :)

breakchars="(){}[],^%$#@\"\";:''|\\"
CLASSPATH="${clj_classpath}:${eclipse_classpath}" \
    rlwrap --remember -c -b "$breakchars" \
    java clojure.main -i $HOME/.clojurerc --repl