Compare commits
9 Commits
v0.1.17.6-
...
max_path
| Author | SHA1 | Date | |
|---|---|---|---|
|
92bd333552
|
|||
|
70a451b63e
|
|||
|
cfe6c47cd7
|
|||
|
8eeb32c495
|
|||
|
fdcd6822c4
|
|||
|
71390c84da
|
|||
|
84d01b1091
|
|||
|
8f9faaa39e
|
|||
|
0898244b2a
|
@@ -181,6 +181,48 @@ _done() {
|
||||
exit 0
|
||||
}
|
||||
|
||||
# @FUNCTION: posix_realpath
|
||||
# @USAGE: <file>
|
||||
# @DESCRIPTION:
|
||||
# Portably gets the realpath and prints it to stdout.
|
||||
# This was initially inspired by
|
||||
# https://gist.github.com/tvlooy/cbfbdb111a4ebad8b93e
|
||||
# and
|
||||
# https://stackoverflow.com/a/246128
|
||||
#
|
||||
# If the file does not exist, just prints it appended to the current directory.
|
||||
# @STDOUT: realpath of the given file
|
||||
posix_realpath() {
|
||||
[ -z "$1" ] && die "Internal error: no argument given to posix_realpath"
|
||||
current_loop=0
|
||||
max_loops=50
|
||||
mysource=$1
|
||||
|
||||
while [ -h "${mysource}" ]; do
|
||||
current_loop=$((current_loop+1))
|
||||
mydir="$( cd -P "$( dirname "${mysource}" )" > /dev/null 2>&1 && pwd )"
|
||||
mysource="$(readlink "${mysource}")"
|
||||
[ "${mysource%${mysource#?}}"x != '/x' ] && mysource="${mydir}/${mysource}"
|
||||
|
||||
if [ ${current_loop} -gt ${max_loops} ] ; then
|
||||
(>&2 echo "${1}: Too many levels of symbolic links")
|
||||
echo "$1"
|
||||
return
|
||||
fi
|
||||
done
|
||||
mydir="$( cd -P "$( dirname "${mysource}" )" > /dev/null 2>&1 && pwd )"
|
||||
|
||||
# TODO: better distinguish between "does not exist" and "permission denied"
|
||||
if [ -z "${mydir}" ] ; then
|
||||
(>&2 echo "${1}: Permission denied")
|
||||
echo "$(pwd)/$1"
|
||||
else
|
||||
echo "${mydir%/}/$(basename "${mysource}")"
|
||||
fi
|
||||
|
||||
unset current_loop max_loops mysource mydir
|
||||
}
|
||||
|
||||
download_ghcup() {
|
||||
|
||||
case "${plat}" in
|
||||
@@ -427,23 +469,23 @@ adjust_bashrc() {
|
||||
;;
|
||||
fish)
|
||||
mkdir -p "${GHCUP_PROFILE_FILE%/*}"
|
||||
sed -i -e '/# ghcup-env$/ s/^#*/#/' "${GHCUP_PROFILE_FILE}"
|
||||
sed -i -e '/# ghcup-env$/ s/^#*/#/' "$(posix_realpath "${GHCUP_PROFILE_FILE}")"
|
||||
case $1 in
|
||||
1)
|
||||
echo "set -q GHCUP_INSTALL_BASE_PREFIX[1]; or set GHCUP_INSTALL_BASE_PREFIX \$HOME ; set -gx PATH \$HOME/.cabal/bin $GHCUP_BIN \$PATH # ghcup-env" >> "${GHCUP_PROFILE_FILE}"
|
||||
printf "\n%s" "set -q GHCUP_INSTALL_BASE_PREFIX[1]; or set GHCUP_INSTALL_BASE_PREFIX \$HOME ; set -gx PATH \$HOME/.cabal/bin $GHCUP_BIN \$PATH # ghcup-env" >> "${GHCUP_PROFILE_FILE}"
|
||||
;;
|
||||
2)
|
||||
echo "set -q GHCUP_INSTALL_BASE_PREFIX[1]; or set GHCUP_INSTALL_BASE_PREFIX \$HOME ; set -gx PATH \$HOME/.cabal/bin \$PATH $GHCUP_BIN # ghcup-env" >> "${GHCUP_PROFILE_FILE}"
|
||||
printf "\n%s" "set -q GHCUP_INSTALL_BASE_PREFIX[1]; or set GHCUP_INSTALL_BASE_PREFIX \$HOME ; set -gx PATH \$HOME/.cabal/bin \$PATH $GHCUP_BIN # ghcup-env" >> "${GHCUP_PROFILE_FILE}"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
bash)
|
||||
sed -i -e '/# ghcup-env$/ s/^#*/#/' "${GHCUP_PROFILE_FILE}"
|
||||
echo "[ -f \"${GHCUP_DIR}/env\" ] && source \"${GHCUP_DIR}/env\" # ghcup-env" >> "${GHCUP_PROFILE_FILE}"
|
||||
sed -i -e '/# ghcup-env$/ s/^#*/#/' "$(posix_realpath "${GHCUP_PROFILE_FILE}")"
|
||||
printf "\n%s" "[ -f \"${GHCUP_DIR}/env\" ] && source \"${GHCUP_DIR}/env\" # ghcup-env" >> "${GHCUP_PROFILE_FILE}"
|
||||
case "${plat}" in
|
||||
"Darwin"|"darwin")
|
||||
if ! grep -q "ghcup-env" "${HOME}/.bash_profile" ; then
|
||||
echo "[[ -f ~/.bashrc ]] && source ~/.bashrc # ghcup-env" >> "${HOME}/.bash_profile"
|
||||
printf "\n%s" "[[ -f ~/.bashrc ]] && source ~/.bashrc # ghcup-env" >> "${HOME}/.bash_profile"
|
||||
fi
|
||||
;;
|
||||
MSYS*|MINGW*)
|
||||
@@ -457,8 +499,8 @@ adjust_bashrc() {
|
||||
;;
|
||||
|
||||
zsh)
|
||||
sed -i -e '/# ghcup-env$/ s/^#*/#/' "${GHCUP_PROFILE_FILE}"
|
||||
echo "[ -f \"${GHCUP_DIR}/env\" ] && source \"${GHCUP_DIR}/env\" # ghcup-env" >> "${GHCUP_PROFILE_FILE}"
|
||||
sed -i -e '/# ghcup-env$/ s/^#*/#/' "$(posix_realpath "${GHCUP_PROFILE_FILE}")"
|
||||
printf "\n%s" "[ -f \"${GHCUP_DIR}/env\" ] && source \"${GHCUP_DIR}/env\" # ghcup-env" >> "${GHCUP_PROFILE_FILE}"
|
||||
;;
|
||||
esac
|
||||
echo
|
||||
|
||||
Reference in New Issue
Block a user