Skip to content

Instantly share code, notes, and snippets.

@dmwit
Created February 24, 2019 19:21
Show Gist options
  • Save dmwit/1d4af1c62fc2ef33cfd7994bc022c2be to your computer and use it in GitHub Desktop.
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
#!/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