Skip to content

Instantly share code, notes, and snippets.

Forked from simonmichael/gist:1185421
Last active June 6, 2020 12:02
  • Star 30 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
ghc-pkg-clean and ghc-pkg-reset compatible with both zsh and bash
# unregister broken GHC packages. Run this a few times to resolve dependency rot in installed packages.
# ghc-pkg-clean -f cabal/dev/packages*.conf also works.
function ghc-pkg-clean() {
for p in `ghc-pkg check $* 2>&1 | grep problems | awk '{print $6}' | sed -e 's/:$//'`
echo unregistering $p; ghc-pkg $* unregister $p
# remove all installed GHC/cabal packages, leaving ~/.cabal binaries and docs in place.
# When all else fails, use this to get out of dependency hell and start over.
function ghc-pkg-reset() {
if [[ $(readlink -f /proc/$$/exe) =~ zsh ]]; then
read 'ans?Erasing all your user ghc and cabal packages - are you sure (y/N)? '
else # assume bash/bash compatible otherwise
read -p 'Erasing all your user ghc and cabal packages - are you sure (y/N)? ' ans
[[ x$ans =~ "xy" ]] && ( \
echo 'erasing directories under ~/.ghc'; command rm -rf `find ~/.ghc/* -maxdepth 1 -type d`; \
echo 'erasing ~/.cabal/lib'; command rm -rf ~/.cabal/lib; \
alias cabalupgrades="cabal list --installed | egrep -iv '(synopsis|homepage|license)'"
Copy link

Made compatible with zsh

Copy link

how do I run this file? I keep getting syntax errors doing sh

Copy link

@Fresheyeball These are shell functions (and an alias) - not a script.

To use them you should source them in your shell (copy as a file somewhere and then run . and then call one of the functions by just typing ghc-pkg-clean or ghc-pkg-reset at the prompt.

Copy link

I'm getting the following error:

❯ ghc-pkg-reset
readlink: illegal option -- f
usage: readlink [-n] [file ...]
ghc-pkg-reset:read:4: -p: no coprocess

Copy link

p-alik commented Feb 4, 2017

@kevinSuttle, I got the same issue on FreeBSD. See my comment here
Or try this version of ghc-pkg-reset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment