-
-
Notifications
You must be signed in to change notification settings - Fork 645
/
clojure.sh
executable file
·54 lines (44 loc) · 1.72 KB
/
clojure.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bash
set -Eeuo pipefail
# This wrapper script adds enrich-classpath's (https://github.com/clojure-emacs/enrich-classpath) functionalities to the `clojure` binary.
# It works by accepting the `clojure` binary as the first argument, and whatever arguments you'd pass to `clojure` as the rest.
# sample usage: clojure.sh clojure -Asome-alias <<< "(System/getProperty \"java.class.path\")"
clojure="$1"
# remove it from "$@"/"$*":
shift
file="deps.edn"
if [ ! -e $file ]; then
echo "$file not found."
$clojure "$@"
elif [[ "$*" == *Spath* ]]; then
echo "-Spath was passed; skipping enrich-classpath."
$clojure "$@"
elif [[ "$*" == *Scp* ]]; then
echo "-Scp was passed; skipping enrich-classpath."
$clojure "$@"
else
here="$PWD"
there=$(mktemp -d -t mytempdir.XXXXXX)
# copy any relevant file to the temporary folder
files_to_copy=( ".tool-versions" # asdf runtime versions configuration
)
for file_to_copy in "${files_to_copy[@]}"; do
if [ -e "$file_to_copy" ]; then
cp "$file_to_copy" "$there"
fi
done
# don't let local deps.edn files interfere:
cd "$there"
# enrich-classpath will emit a command starting by "clojure", or print a stacktrace:
output=$(2>&1 "$clojure" -Sforce -Srepro -J-XX:-OmitStackTraceInFastThrow -J-Dclojure.main.report=stderr -Sdeps '{:deps {mx.cider/tools.deps.enrich-classpath {:mvn/version "1.19.3"}}}' -M -m cider.enrich-classpath.clojure "$clojure" "$here" "true" "$@")
cmd=$(tail -n1 <(echo "$output"))
cd "$here"
if grep --silent "^$clojure" <<< "$cmd"; then
# eval is necessary because $cmd contains arguments that have been processed through pr-str.
eval "$cmd"
else
# Print errors:
echo "$output"
$clojure "$@"
fi
fi