Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Unified Diff: go/env.py

Issue 2121653002: Fix prompt exporting escaped characters, opt into PS1 mod. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Fix pylint error. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « go/bootstrap.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/env.py
diff --git a/go/env.py b/go/env.py
index 71fe12a6ee399c403aa5934ef245124366a8f57e..b749ec3ff2b79871b06f9285eb4616044c19bc0b 100755
--- a/go/env.py
+++ b/go/env.py
@@ -29,10 +29,33 @@ bootstrap = imp.load_source(
old = os.environ.copy()
new = bootstrap.prepare_go_environ()
+def _escape_special(v):
+ """Returns (str): The supplied value, with special shell characters escaped.
+
+ Replace special characters with their escaped form. This will allow them
+ to be interpreted by the shell using the $'...' notation.
+
+ Args:
+ v (str): The input value to escape.
+ """
+ for f, r in (
+ ('\n', '\\n'),
+ ('\b', '\\b'),
+ ('\r', '\\r'),
+ ('\t', '\\t'),
+ ('\v', '\\v')):
+ v = v.replace(f, r)
+ return v
+
if len(sys.argv) == 1:
for key, value in sorted(new.iteritems()):
if old.get(key) != value:
- print 'export %s=%s' % (key, pipes.quote(value))
+ orig_value, value = value, _escape_special(value)
+
+ # We will only use the $'...' notation if there was an escaped character
+ # in the string.
+ print 'export %s=%s%s' % (key, ('$') if orig_value != value else (''),
+ pipes.quote(value))
else:
exe = sys.argv[1]
if exe == 'python':
« no previous file with comments | « go/bootstrap.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698