Commits

php committed 887a9ed

Add prompt and fork bash

Comments (0)

Files changed (1)

 import re, os, sys
 import subprocess
 
+DEF_PATH = []
+
 def getpath(program):
     proc = subprocess.Popen(["which", program], shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
     output,err = proc.communicate()
     if proc.returncode == 0:
         return os.path.dirname(output.strip())
     return None
+def setpath(paths, prompt=None):
+    if len(paths) == 0:
+        return None
+    path = os.pathsep.join(paths).strip()
+    if path:
+        os.environ['PATH'] = path
+# bash related stuff
+        if prompt:
+            os.environ['PS1'] = "(%s) \h $ " % prompt
+        os.execle("/bin/bash", "", os.environ)
+    return None
+
 def usage():
     print 'envcc <program> +|-<program>'
     print ''
     usage()
     sys.exit(255)
 
+if sys.argv[1] == '-c':
+    setpath(DEF_PATH)
+    sys.exit(0)
+
 preg = re.compile('(\+|\-)?([a-z]+)')
 
 paths = {}
                 paths = {p: getpath(p)}
     except OSError:
         print 'Error occured'
-print os.pathsep.join(paths.values())
+
+setpath(paths.values(), " ".join(sys.argv[1:]))