Improve error/status messages

This commit is contained in:
Julian Ospald 2018-09-30 03:14:56 +08:00
parent 605b7420ce
commit ee1d4e6aac
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
1 changed files with 19 additions and 6 deletions

25
ghcup
View File

@ -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 <ghcver>"
unset myghcver inst_location f
}