ClojureX icon indicating copy to clipboard operation
ClojureX copied to clipboard

clj: correctly find and use rlwrap & support clj as relative symlink

Open bg opened this issue 15 years ago • 4 comments

In reviewing ClojureX today on my commute home from work (in preparation for the rubylearning.org Clojure101 course,) I found and fixed a couple of small bugs in the 'clj' script.

First, clj didn't actually select rlwrap instead of jline like it promised it would. The problem was a typo in the avail function. Second, if clj is a relative symlink (e.g. bin/clj -> ../work/ClojureX/clj) it will not correctly determine the path because readlink fails to canonicalize the link.

diff --git a/clj b/clj
index b3000e7..5c188c5 100755
--- a/clj
+++ b/clj
@@ -14,7 +14,7 @@ USAGE="Usage: $PRG_NAME [java-opt*] [init-opt*] [main-opt] [arg*]"
 
 # determine if $1 is an available program (eschew 'which', as it's unreliable)
 avail() {
-  type -P $1 $>/dev/null
+  type -P $1 &>/dev/null
 }
 
 # send the stock usage text to stderr
@@ -68,7 +68,7 @@ PRG="$0"
 while [ -h "$PRG" ]; do
   # if readlink is availble, use it; it is less fragile than relying on `ls` output
   if avail readlink; then
-    PRG=`readlink "$PRG"`
+    PRG=`readlink -f "$PRG"`
   else
     ls=`ls -ld "$PRG"`
     link=`expr "$ls" : '.*-> \(.*\)$'`

bg avatar Apr 13 '10 00:04 bg

Applied.

citizen428 avatar Apr 14 '10 10:04 citizen428

Unfortunately the -f option breaks readlink on OSX. Since that always has been ClojureX's main platform, I had to remove it for the time being. Will have to implement some platform neutral way to determine the canonical path. The joys of cross-platform shell scripting...

citizen428 avatar Apr 14 '10 10:04 citizen428

Gahhh. And a casual google for an answer reveals ... there is no good answer :(

http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac

How about a compromise? Don't support clj as a relative symlink unless we detect that readlink supports -f?

bg avatar Apr 14 '10 11:04 bg

I know, I found the same link on Google, so probably will have to do something like what you mentioned in the last paragraph.

citizen428 avatar Apr 14 '10 12:04 citizen428