Skip to content

Instantly share code, notes, and snippets.

@teh

teh/stack.py

Last active Aug 24, 2016
Embed
What would you like to do?
#!/usr/bin/env python
"""
Welcome to Tom-does-another-disgusting-hack.
This is an executable shim for the stack binary whose only purpose is
to make the amazing intero mode [1] work in a non-stack environment (Nix
in our case).
Dump it somewhere and make sure it runs *instead* of the actual stack binary.
You will not be able to use stack at the same time.
[1]
https://github.com/commercialhaskell/intero
"""
import sys
import time
import os
import subprocess
def log(l):
subprocess.call(["logger", repr(l)])
def main():
if sys.argv[1:] == ["path", "--project-root", "--verbosity", "silent"]:
print os.getcwd()
return
if sys.argv[1:] == ["exec", '--verbosity', 'silent', '--', 'intero', '--version']:
print "0.1.17"
return
if sys.argv[1:3] == ["exec", "intero"]:
subprocess.call(["intero"])
return
if sys.argv[1:4] == ['ghci', '--with-ghc', 'intero']:
odir = sys.argv[8]
hidir = sys.argv[10]
subprocess.call(['cabal', 'repl', '--ghc-options="{} {}"'.format(odir, hidir)])
return
if sys.argv[1] == 'build':
log(sys.argv)
return
if sys.argv[1:] == ['exec', '--verbosity', 'silent', '--', 'ghc', '--supported-extensions']:
o = subprocess.check_output(["ghc", "--supported-extensions"])
print o
return
log(sys.argv)
raise Exception("unexpected intero command: {}".format(sys.argv))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment