Skip to content
This repository has been archived by the owner on Oct 3, 2018. It is now read-only.

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

Open
bg opened this issue Apr 13, 2010 · 4 comments
Open

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

bg opened this issue Apr 13, 2010 · 4 comments

Comments

@bg
Copy link

bg commented Apr 13, 2010

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" : '.*-> \(.*\)$'`
@citizen428
Copy link
Owner

Applied.

@citizen428
Copy link
Owner

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...

@bg
Copy link
Author

bg commented Apr 14, 2010

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?

@citizen428
Copy link
Owner

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants