ruby-install icon indicating copy to clipboard operation
ruby-install copied to clipboard

ruby-install symlink in ~/bin

Open aidanhs opened this issue 12 years ago • 5 comments

Currently this doesn't work because it looks for ~/share (which I don't want to put there).

Solvable by replacing $0 with $(readlink -f $0) in line 5 of ruby-install.

Can't see how it would break any (sane) existing use cases.

aidanhs avatar Jun 24 '13 13:06 aidanhs

Actually, on OSX their readlink doesn't support -f. How about installing into ~/.local?

postmodern avatar Jun 24 '13 19:06 postmodern

Here is what I have for readlink:

Mac OS X, Version 10.7.5

wilmoore avatar Jun 24 '13 19:06 wilmoore

Interesting take on dealing with BSD readlink not dereferencing symlinks here: https://github.com/nicholasrobinson/JSON.sh/blob/master/bin/json_parse

Adapted from ^ code, we could do something like:

function canonical_readlink()
{
    cd "$(dirname "$1")";
    local filename="$(basename "$1")";
    if [[ -h "$filename" ]]; then
        canonical_readlink "$(readlink "$filename")";
    else
        echo "$(pwd -P)/"$filename"";
    fi
}

havenwood avatar Jun 24 '13 20:06 havenwood

Given that I don't particularly see the need to worry about directory symlinks (if an entire directory has been symlinked it seems fair to assume others will as well), why not turn the $0 into

$( ([[ -h $0 ]] && readlink $0) || echo $0 )

So the line becomes

source "$(dirname $(dirname $( ([[ -h $0 ]] && readlink $0) || echo $0 ) ))/share/ruby-install/ruby-install.sh"

aidanhs avatar Jun 24 '13 20:06 aidanhs

On the subject of installing to .local, that does work and it may come to that, but I prefer to keep executables with the rest of their files where possible and just symlink them.

aidanhs avatar Jun 24 '13 20:06 aidanhs