瀏覽代碼

fix grass.py to accept custom PS1 and aliases (bashrc)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@61216 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 10 年之前
父節點
當前提交
7309907700
共有 1 個文件被更改,包括 16 次插入2 次删除
  1. 16 2
      lib/init/grass.py

+ 16 - 2
lib/init/grass.py

@@ -744,6 +744,9 @@ def load_env():
         return
 
     for line in readfile(grass_env_file).split(os.linesep):
+        if not line.lower().startswith('export'):
+            continue
+        
         try:
             k, v = map(lambda x: x.strip(), line.strip().split(' ', 1)[1].split('=', 1))
         except:
@@ -1139,16 +1142,27 @@ PROMPT_COMMAND=grass_prompt\n""" % (_("2D and 3D raster MASKs present"),
                                     _("Raster MASK present"),
                                     _("3D raster MASK present")))
 
-    # read environmental variables
-    path = os.path.join(userhome, ".grass.bashrc") # left for backward compatibility
+    # read environmental variables from GRASS 6 (left for backward
+    # compatibility)
+    path = os.path.join(userhome, ".grass.bashrc")
     if os.access(path, os.R_OK):
         f.write(readfile(path) + '\n')
+    
+    # write GRASS environmental variables to $LOCATION/.bashrc
     for env in os.environ.keys():
         if env.startswith('GRASS'):
             val = os.environ[env]
             if ' ' in val:
                 val = '"%s"' % val
             f.write('export %s=%s\n' % (env, val))
+    
+    # write aliases and custom settings from grass_env_file to
+    # $LOCATION/.bashrc
+    if os.access(grass_env_file, os.R_OK):
+        for line in readfile(grass_env_file).split(os.linesep):
+            if line.lower().startswith('export'):
+                continue
+            f.write(line + '\n')
     ### Replaced by code above (do not override already set up environment variables)
     ###    if os.access(grass_env_file, os.R_OK):
     ###        f.write(readfile(grass_env_file) + '\n')