From ee1d4e6aac131d353e186341176afada41cf560f Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sun, 30 Sep 2018 03:14:56 +0800 Subject: [PATCH] Improve error/status messages --- ghcup | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/ghcup b/ghcup index 9b6d62a..cd10749 100755 --- a/ghcup +++ b/ghcup @@ -164,7 +164,7 @@ ARGS: ## utilities ## die() { - (>&2 printf "\\033[0;31m%s\\033[0m\\n" "$1") + (>&2 red_message "$1") exit 2 } @@ -204,6 +204,10 @@ warning_message() { printf "\\033[1;33m%s\\033[0m\\n" "$1" } +red_message() { + printf "\\033[0;31m%s\\033[0m\\n" "$1" +} + get_distro_name() { if [ -f /etc/os-release ]; then # freedesktop.org and systemd @@ -481,14 +485,19 @@ show_ghc() { } show_ghc_installed() { - real_ghc=$(realpath "${BIN_LOCATION}/ghc") + current_ghc="${BIN_LOCATION}/ghc" + real_ghc=$(realpath "${current_ghc}" 2>/dev/null) - if [ -e "${real_ghc}" ] ; then - real_ghc="$(basename "${real_ghc}" | sed 's#ghc-##')" - printf "%s" "${real_ghc}" + if [ -L "${current_ghc}" ] ; then # is symlink + if [ -e "${real_ghc}" ] ; then # exists (realpath was called) + real_ghc="$(basename "${real_ghc}" | sed 's#ghc-##')" + printf "%s" "${real_ghc}" + else # is a broken symlink + red_message "broken symlink" + fi fi - unset real_ghc + unset real_ghc current_ghc } ## rm subcommand ## @@ -510,6 +519,10 @@ rm_ghc() { warning_message "${myghcver} doesn't appear to be installed, skipping" fi + status_message "Successfully removed GHC ${myghcver}, you might have to" + status_message "set the currently active GHC now to fix dangling symlinks:" + status_message " ghcup set " + unset myghcver inst_location f }