Created
February 24, 2019 19:21
-
-
Save dmwit/1d4af1c62fc2ef33cfd7994bc022c2be to your computer and use it in GitHub Desktop.
A shell script to switch which version of GHC the non-versioned names point to
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
set -e | |
setopt null_glob | |
case $# in | |
1) true;; | |
*) | |
echo Usage: ghc-version VERSION | |
ghc --version || true | |
echo You might try one of these versions: | |
for dir in $path | |
do | |
for i in "$dir"/ghc-* | |
do | |
if echo "$i" | grep 'ghc-[-0-9.]*$' >/dev/null | |
then | |
basename "$i" | cut -b 5- | |
fi | |
done | |
done | sort -uV | |
exit 1 | |
;; | |
esac | |
version="$1" | |
success=true | |
for i in ghc ghci ghc-pkg runghc haddock-ghc | |
do | |
if ! whence $i-"$version" | |
then | |
echo No target for $i-"$version" found. | |
success=false | |
fi | |
done | |
$success || echo Exiting without changing anything. | |
$success | |
for i in ghc ghci ghc-pkg runghc | |
do | |
sudo ln -sf =$i-"$version" =$i | |
done | |
sudo ln -sf =haddock-ghc-"$version" =haddock |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment