From fafb9bbf9dec8e17685034210a1d5700dd76c731 Mon Sep 17 00:00:00 2001 From: Sam Halliday Date: Mon, 15 Oct 2018 10:07:00 +0100 Subject: [PATCH 1/2] self-update inplace --- ghcup | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/ghcup b/ghcup index 4cf61a9..7003cd1 100755 --- a/ghcup +++ b/ghcup @@ -105,7 +105,11 @@ KNOWN_GOOD_CABAL="2.2.0.0" # How many jobs to use for compiling GHC. JOBS="1" - +# @VARIABLE: SOURCE +# @DESCRIPTION: +# The $0 argument, which contains +# the script name. +SOURCE="$0" #################### #--[ Print Help ]--# @@ -682,6 +686,24 @@ set_ghc() { #--[ Subcommand self-update ]--# ################################ +# @FUNCTION: script_dir +# @DESCRIPTION: +# Portably gets the full directory of where +# this script resides in and prints it to stdout. +# @STDOUT: script directory +script_dir() { + mysource=${SOURCE} + + while [ -h "${mysource}" ]; do + mydir="$( cd -P "$( dirname "${mysource}" )" > /dev/null && pwd )" + mysource="$(readlink "${mysource}")" + [ "${mysource%${mysource#?}}"x != '/x' ] && mysource="${mydir}/${mysource}" + done + mydir="$( cd -P "$( dirname "${mysource}" )" > /dev/null && pwd )" + echo "${mydir}" + + unset mysource mydir +} # @FUNCTION: self_update # @USAGE: @@ -994,7 +1016,7 @@ while [ $# -gt 0 ] ; do if [ "${TARGET_LOCATION}" ] ; then self_update "${TARGET_LOCATION}" else - self_update "${HOME}/.local/bin" + self_update "$(script_dir)" fi break;; show) From 1f32be49228b1b4c83f6da34186a96c794ab7e3c Mon Sep 17 00:00:00 2001 From: Sam Halliday Date: Mon, 15 Oct 2018 10:11:12 +0100 Subject: [PATCH 2/2] people are lazy, give them copypasta instructions... --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4db9a26..19cd1ba 100644 --- a/README.md +++ b/README.md @@ -37,9 +37,15 @@ Inspired by [rustup](https://github.com/rust-lang-nursery/rustup.rs). ## Installation -Just place the `ghcup` shell script into your PATH anywhere +Just place the `ghcup` shell script into your `PATH` anywhere (preferably `~/.local/bin`). +``` +mkdir -p ~/.local/bin/ghcup +curl https://raw.githubusercontent.com/hasufell/ghcup/master/ghcup > ~/.local/bin/ghcup +chmod +x ~/.local/bin/ghcup +``` + ## Usage See `ghcup --help`.