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

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: Only use $'...' notation if there was actually an escaped character. 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..c541409f9caa2c5d4b8b19908f82ae2e25226784 100755
--- a/go/env.py
+++ b/go/env.py
@@ -32,7 +32,19 @@ new = bootstrap.prepare_go_environ()
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))
+ # Replace special characters with their escaped form. This will allow them
mithro 2016/07/07 02:09:39 Can you move this into a function?
dnj (Google) 2016/07/07 03:43:30 Done.
+ # to be interpreted by the shell using the $'...' notation. We will only
+ # use the $'...' notation if there was an escaped character in the string.
+ orig_value = value
+ for f, r in (
+ ('\n', r'\n'),
mithro 2016/07/07 02:09:38 This is kind of confusing, I think ('\n', '\\n')
dnj (Google) 2016/07/07 03:43:30 Done.
+ ('\b', r'\b'),
+ ('\r', r'\r'),
+ ('\t', r'\t'),
+ ('\v', r'\v')):
+ value = value.replace(f, r)
+ 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